Divider
A line that separates content, horizontally or vertically, optionally with a label in the middle.
- A plain horizontal divider renders an <hr>; a vertical or labelled divider renders a <div role="separator"> (as replaces the element in every case). children that render nothing ('', or an array, Set or generator of only empty items, such as an empty .map() result) are no label; 0 is one.
- A labelled divider is **one** separator named by its label (aria-labelledby); the two line segments around the label are presentational (aria-hidden). A consumer aria-label names it instead, and a consumer aria-labelledby is joined with the label.
- Vertical dividers set aria-orientation="vertical" and use logical borders (RTL-safe).
Examples
Default
export const Default: Story = {
decorators: [
(Story) => (
<div style={{ width: 400 }}>
<Story />
</div>
),
],
};Vertical
export const Vertical: Story = {
args: {
orientation: 'vertical',
},
decorators: [
(Story) => (
<div style={{ height: 48, display: 'flex', alignItems: 'center' }}>
<Story />
</div>
),
],
};With Text
export const WithText: Story = {
args: {
children: 'OR',
},
decorators: [
(Story) => (
<div style={{ width: 400 }}>
<Story />
</div>
),
],
};Vertical With Text
export const VerticalWithText: Story = {
args: {
orientation: 'vertical',
children: 'OR',
},
decorators: [
(Story) => (
<div style={{ height: 120, display: 'flex', alignItems: 'stretch' }}>
<Story />
</div>
),
],
};Appearances
export const Appearances: Story = {
argTypes: { appearance: { control: false } },
render: (args) => (
<div className="flex w-96 flex-col gap-4">
{(['default', 'subtle', 'strong', 'brand'] as const).map((appearance) => (
<Divider key={appearance} {...args} appearance={appearance}>
{appearance}
</Divider>
))}
</div>
),
};Inset
export const Inset: Story = {
render: (args) => (
<div className="w-96">
<Divider {...args} />
<Divider {...args} inset />
<Divider {...args} inset>
Inset with a label
</Divider>
</div>
),
};Align Content
export const AlignContent: Story = {
argTypes: { alignContent: { control: false } },
render: (args) => (
<div className="flex w-96 flex-col gap-4">
{(['start', 'center', 'end'] as const).map((alignContent) => (
<Divider key={alignContent} {...args} alignContent={alignContent}>
{alignContent}
</Divider>
))}
</div>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
orientation | 'horizontal' | 'vertical' | No | 'horizontal' | Orientation of the divider line. |
appearance | 'default' | 'subtle' | 'brand' | 'strong' | No | 'default' | How the line looks: |
inset | boolean | No | false | Insets the divider from the edges of its container by 12px along its length, so the line stops short of both ends. Rendered as a boolean |
alignContent | 'start' | 'center' | 'end' | No | 'center' | Where the label sits along a divider that has one: |
ref | React.Ref<HTMLElement> | No | Ref to the rendered element. Typed | |
slotProps | { line?: SlotPart<'div'>; label?: SlotPart<'span'> } | No | Props for the elements a labelled divider draws, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref attached. Every attribute the divider sets on a part is locked. A part takes no | |
as | React.ElementType | No | 'hr' | Render as a different element or component (its props are type-checked). |
Any other prop is passed to the element it renders (HTMLHRElement).
Parts
linelabel
Stable class names
| Part | Class |
|---|---|
root | wave-divider |
line | wave-divider__line |
label | wave-divider__label |