# Stepper

Crate: `libero`
Import: `use libero::components::{Options, StepState, Stepper};`
Feature: `stepper` (off by default, turns on `collapse`, `use-icon`, `use-id`, `visually-hidden`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/navigation/stepper>
Index: [index.md](index.md) lists every other page
Description: The stages of a process over an enum, horizontal or vertical, with the current step's content.

The stages of a process, one per variant of an enum, with the current step's
content. `#[derive(Options)]` lists and names the steps. `panel` matches on the
same enum, so a step without a body does not compile. You own `value` and move
it on, usually from a button inside the step.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::{Button, Flex, Options, Stepper, Text};

#[derive(Clone, PartialEq, Options)]
enum Stage {
    Account,
    #[option(label = "Shipping address")]
    Shipping,
    Review,
}

#[component]
fn Demo() -> Element {
    let mut stage = use_signal(|| Some(Stage::Account));

    rsx! {
        Stepper {
            value: stage(),
            aria_label: "Order steps",
            panel: move |s: Stage| match s {
                Stage::Account => rsx! {
                    Flex { gap: "sm", align: "flex-start",
                        Text { "Who is ordering?" }
                        Button { onclick: move |_| stage.set(Some(Stage::Shipping)), "Continue" }
                    }
                },
                Stage::Shipping => rsx! {
                    Flex { gap: "sm", align: "flex-start",
                        Text { "Where should the parcel go?" }
                        Button { onclick: move |_| stage.set(Some(Stage::Review)), "Continue" }
                    }
                },
                Stage::Review => rsx! {
                    Flex { gap: "sm", align: "flex-start",
                        Text { "Check the order, then place it." }
                        Button { onclick: move |_| stage.set(None), "Place order" }
                    }
                },
            },
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `Option<T>` | required | The current step. Steps before it are completed, the rest pending. `None` means every step is finished. |
| `panel` | `Callback<T, Element>` | - | A step's body. Horizontal shows it below the strip, vertical under its own step. A closed step's content is not mounted. |
| `options` | `Vec<T>` | `T::options()` | The steps to show, in order. |
| `option_label` | `Callback<T, OptionLabel>` | `T::label()` | Overrides a step's label. `OptionLabel::rich` draws it as rsx and keeps a text name. |
| `option_description` | `Callback<T, String>` | - | A second line under a step's label. An empty string prints none. |
| `state` | `Callback<T, Option<StepState>>` | derived | Overrides a step's state. `None` keeps the derived one. The only way to mark a step `Error`, which changes the marker, not which step is current. |
| `onstepclick` | `EventHandler<T>` | - | Called with the picked step. Without it the steps are plain text with no tab stops of their own; a scrolling strip with no clickable step is one tab stop itself. |
| `allow_next_steps` | `bool` | `false` | With `onstepclick`, lets steps not reached yet be picked too. |
| `orientation` | `Responsive<Orientation>` | `horizontal` | `vertical` puts each step's content under the step itself. Or one per breakpoint, `orientation: responsive(Orientation::Vertical).md(Orientation::Horizontal)`. It is laid out in Rust, so it switches after mount when server-rendered. |
| `label_position` | `Responsive<StepLabelPosition>` | `side` | `side` or `below` the marker. Ignored when vertical. Under 7.5rem a step (22.5rem for three, 360px at a 16px root), `side` draws as `below`. Or one per breakpoint, `label_position: responsive(StepLabelPosition::Below).md(StepLabelPosition::Side)`. It is laid out in Rust, so it switches after mount when server-rendered. |
| `size` | `Responsive<Size>` | `md` | Marker, type and spacing. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `color` | `ThemeAwareValue` | `primary` | The current and completed markers, and the connectors behind them. |
| `connectors` | `Responsive<bool>` | `true` | The lines between steps. `false` drops them: horizontal steps share the row in even columns, so they never shrink to dashes on a phone, and a vertical stepper keeps its spacing without the rail. Or one per breakpoint, `connectors: responsive(false).md(true)`, all in CSS. Breakpoints follow the window, not the parent. |
| `parts` | `Parts<StepperPart>` | - | Styles for the inner parts in the Style API tab, under `sx`. |

It also takes `sx`, `class`, `states`, and any extra HTML attributes. An `id`
seeds the ids of the steps.

## Style API

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

| Part | `data-slot` | Description |
|---|---|---|
| `StepperPart::List` | `list` | The `<ol>` of steps. |
| `StepperPart::Step` | `step` | One step's `<li>`. Its `data-state` names the step's state. |
| `StepperPart::Header` | `header` | The step's button, or a plain box when steps cannot be picked. |
| `StepperPart::Marker` | `marker` | The number, check or cross. |
| `StepperPart::Body` | `body` | Label and description. |
| `StepperPart::Label` | `label` | The step's label. |
| `StepperPart::Description` | `description` | The second line under the label. |
| `StepperPart::Panel` | `panel` | The `panel` content: below the strip, or under each step when vertical. |

## Accessibility

### Libero handles

- With `onstepclick`, each clickable step is a button and a tab stop. Enter
  and Space activate. There are no arrow keys.
- `aria_label` and `aria_labelledby` land on the step list, not the root.
- A horizontal strip never widens the page (WCAG 1.4.10): the connectors
  shrink first, down to a quarter of the size's spacing (2 to 7px, a short dash
  on a phone with descriptions), then steps that still don't fit scroll inside
  the strip. Labels keep their words whole; only a word wider than the strip breaks.
  While it scrolls and no step is clickable, the strip itself is a tab stop,
  so the arrow keys can scroll it in any browser. Without an `aria_label` or
  `aria_labelledby` it is named "Steps" (`StepperLabels::steps`).

### You must

- Name the steps with `aria_label` or `aria_labelledby`.
- Give a rich label a name that contains its visible text. A screen reader hears
  the name, not the drawing, so put no link or button in it.

### Example

A checkout, `Stepper { aria_label: "Checkout steps", .. }` with Cart, Address
and Payment: a screen reader reads the list as "Checkout steps", and with
`onstepclick` each clickable step is a button and a tab stop.

## Theme defaults

`StepperDefaults` on the theme: `size`, `sizes` (marker, font sizes, gaps),
`label_position`, `color`, `pending_color`, `error_color`, `connector_color`,
`description_color`, `line_width`, `content_padding` and `connectors`. The vertical collapse
takes `theme.collapse.duration`. The status words are `StepperLabels`
(`completed`, `error`, `steps`) in the [localization](localization.md).
