# Divider

Crate: `libero`
Import: `use libero::components::Divider;`
Feature: `divider` (on by default, turns on `box`, `use-id`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/layout/divider.rs>
Index: [index.md](index.md) lists every other page
Description: A horizontal or vertical rule, with an optional label sitting in the line.

A horizontal or vertical rule, with an optional label sitting in the line.

## Usage

The rule has no size of its own, so both examples give it neighbours.

```rust
use dioxus::prelude::*;
use libero::components::{Box, Divider, Text};
use libero::sx::sx;

#[component]
fn Demo() -> Element {
    rsx! {
        Box {
            sx: sx().width("240px").text_align("center"),
            Text { "Above" }
            Divider { spacing: "md", "OR" }
            Text { "Below" }
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `orientation` | `Responsive<Orientation>` | `horizontal` | The direction of the rule. A vertical rule stretches to its row's height, so it needs a flex row parent; in a block parent it is 0px high and does not show. Or one per breakpoint, `orientation: responsive(Orientation::Horizontal).md(Orientation::Vertical)`: the rule switches with the window from the first paint, while `aria-orientation` follows after mount when the page was rendered on a server. |
| `size` | `Responsive<Size>` | `xs` | Line thickness. Or one per breakpoint, `size: responsive(Size::Xs).md(Size::Sm)`. |
| `label_position` | `LabelPosition` | `center` | Where the label sits along the rule: `center`, `start` or `end`. |
| `spacing` | `Responsive<ThemeAwareValue>` | `none` | Margin on both sides of the rule, a spacing step or a CSS length. Or one per breakpoint, `spacing: responsive(Size::Xs).md(Size::Lg)`. |
| `color` | `ThemeAwareValue` | `muted.4` | Line color. A bare theme color like `primary` resolves to its shade 3. |
| `children` | `Element` | - | An optional label in the line. |
| `parts` | `Parts<DividerPart>` | - | Styles for the inner parts in the Style API tab, under `sx`. |

Like every component, `Divider` also takes the shared props `sx`, `class`,
`style`, `states`, `hidden_from`, `visible_from`, and any extra HTML attributes.

## Style API

Style a part with the `parts` prop, or address it as `[data-slot='…']` in your
own CSS. The names are stable. [Styling](styling.md#style-api) explains how
parts work.

| Part | `data-slot` | Description |
|---|---|---|
| `DividerPart::Label` | `label` | The label between the two line halves, with `children` only. |

## Accessibility

### Libero handles

- The rule is a `separator`, named by its label. Your own `aria-label` or
  `aria-labelledby` wins. A `role` other than `separator` turns the label
  naming and `aria-orientation` off.
- A long label on a horizontal rule wraps inside the line instead of running
  out of a narrow container. A vertical rule's label stays on one line.

### You must

- Pass `role: "none"` for a purely visual rule.

### Example

A rule between two settings groups, `Divider { "Advanced" }`: a screen reader
reads a separator named "Advanced". A rule that only spaces two cards takes
`role: "none"` and is skipped.

## Theme defaults

`DividerDefaults` on the theme.

| Field | Type | Description |
|---|---|---|
| `size` | `Size` | Default `size`, `xs`. |
| `label_position` | `LabelPosition` | Default `label_position`, `center`. |
| `spacing` | `Option<Size>` | Default margin on both sides of the rule. `None` means `0`. |
| `thicknesses` | `Sizes<u16>` | Line thickness in pixels per size step. |

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-divider-thickness-<size>` | Line thickness for that size step. |
| `--lsx-divider-line` | The thickness in effect, resolved from the `size` state. |
| `--lsx-divider-spacing` | Margin on both sides of the rule. |
| `--lsx-divider-color` | Line color. Unset leaves `muted.4`. |

## Data attributes

State tokens on the root's `data-state`, space separated.

| Token | Condition |
|---|---|
| `size-<size>` | The `size` in effect. |
| `horizontal` / `vertical` | The `orientation` in effect. |
| `label` | `children` is present. |
| `label-start` | `label_position` is `start`. |
| `label-end` | `label_position` is `end`. |
