# Timeline

Crate: `libero`
Import: `use libero::components::{Timeline, TimelineEvent, TimelineLine};`
Feature: `timeline` (off by default, turns on `visually-hidden`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/data_display/timeline>
Index: [index.md](index.md) lists every other page
Description: An ordered list of events drawn against a rail, with an `active` index colouring the bullets and connectors up to the current one.

An ordered list of events drawn against a rail, rendered as an
`<ol role="list">`. `active` marks the current event. Bullets up to it fill
with the accent and the connectors between them draw in it, so the rail reads
as progress. Done and pending bullets differ by shape too, not by color alone.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::{Text, Timeline, TimelineEvent};

#[component]
fn Demo() -> Element {
    rsx! {
        Timeline {
            active: 2,
            items: vec![
                TimelineEvent::new("Pushed to main")
                    .content(rsx! { Text { "3 commits" } }),
                TimelineEvent::new("Review requested")
                    .content(rsx! { Text { "@tom" } }),
                TimelineEvent::new("Deployed")
                    .content(rsx! { Text { "v2.4.0 to production" } }),
                TimelineEvent::new("Rolled back")
                    .content(rsx! { Text { "reverted in 4 minutes" } }),
            ],
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `items` | `Vec<TimelineEvent>` | `vec![]` | The events, in render order. |
| `active` | `Option<usize>` | `None` | The current event. Bullets up to and including it, and the connectors between them, draw in the accent. An index past the end clamps to the last event, so "step 7 of 4" means finished. |
| `align` | `Responsive<TimelineAlign>` | `start` | `start`, `end`, or `alternate` for content on both sides of a centred rail. Mirrored in a right-to-left layout. `alternate` fills its parent, so a narrower parent makes it narrower. With an event's `.opposite(..)`, every `align` draws as `start` below `sm`. Or one per breakpoint, `align: responsive(TimelineAlign::Start).md(TimelineAlign::Alternate)`. Breakpoints follow the window, not the parent. With `opposite` content, the reading order and each body's side follow it too; a server-rendered page shows the base until it loads. |
| `color` | `ThemeAwareValue` | `primary` | The active accent. An event's own `.color(..)` overrides it. |
| `bullet_size` | `Responsive<Size>` | `md` | Bullet diameter. Or one per breakpoint, `bullet_size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `radius` | `Responsive<ThemeAwareValue>` | `xl` | Bullet corner radius, or any CSS, e.g. `radius: "0"`. `xl` is a dot. Or one per breakpoint, `radius: responsive(Size::Xs).md(Size::Xl)`. Breakpoints follow the window, not the parent. |
| `gap` | `Responsive<ThemeAwareValue>` | `xl` | Space between events, which is also each connector's length, or any CSS, e.g. `gap: "0"`. Or one per breakpoint, `gap: responsive(Size::Sm).md(Size::Xl)`. Breakpoints follow the window, not the parent. |
| `parts` | `Parts<TimelinePart>` | - | Styles for the inner parts in the Style API tab, under `sx`. |

`TimelineEvent`

| Method | Type | Default | Description |
|---|---|---|---|
| `new(title)` | `impl Into<OptionLabel>` | required | The event's name, optionally with its own rendering, which a screen reader skips for the name. |
| `.content(..)` | `Element` | none | The body below the title. |
| `.opposite(..)` | `Element` | none | Content across the rail from the body, such as a time. One event setting it centres the rail for the whole timeline from the `sm` breakpoint up, with the body on the `align` side (`alternate` swaps sides per event). Below `sm` the rail runs down the start edge and the content takes only the width it needs, beside the body. It is read in order, after the body. |
| `.bullet(..)` | `Element` | the dot | An icon or avatar inside the bullet in place of the dot. It inverts when active, so use an outlined glyph: a solid one covers the fill and the done bullet reads as a pending ring. |
| `.color(..)` | `impl Into<ThemeAwareValue>` | inherits | This event's own accent, such as an error step in an ordinary run. |
| `.line(..)` | `TimelineLine` | `Solid` | The connector below this event, `Solid`, `Dashed` or `Dotted`. |

Like every component, `Timeline` 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. [Style API in Styling](styling.md#style-api)
explains how parts work.

| Part | `data-slot` | Description |
|---|---|---|
| `TimelinePart::Item` | `item` | One event's `<li>`. |
| `TimelinePart::Bullet` | `bullet` | The dot, or the ring around an event's `bullet`. |
| `TimelinePart::Body` | `body` | Title and content, beside the rail. |
| `TimelinePart::Title` | `title` | The event's title. |
| `TimelinePart::Opposite` | `opposite` | An event's `.opposite(..)` content, across the rail from the body. |

## Accessibility

### Libero handles

- The list gives a screen reader the position and count the rail shows.
- Bullets are `aria-hidden`, and the title is the text. A custom `.bullet(..)`
  is hidden too.

### You must

- Never put anything focusable in a `.bullet(..)`. It would stay a tab stop with
  no name. Interactive content belongs in `.content(..)`.
- Keep a rich title (`OptionLabel::rich`) decorative: it is hidden from a screen
  reader, which hears the name instead, so no link or button in it. Interactive
  content belongs in `.content(..)`.
- Say an error or other status in the title or content. The `.color(..)` accent
  alone does not carry it.

### Example

An order's history in a `Timeline` with `active` on the "Shipped" event: a
screen reader reads each event's place in the list and marks "Shipped" as the
current step. A failed delivery says "Failed" in its title, not only in red.

### Limits

- A pending bullet is filled with the `Paper` colour. On a page of another colour,
  such as a dark page behind a lighter `Paper`, the ring shows a disc of that
  colour; set `bullet_background` on the theme to the surface the timeline sits on.
- A screen reader hears only which event is current, as `aria-current="step"`.
  Done and pending are visual; put them in the title or content where they
  matter. With `active` past the end, the last event still reads as current.

## Theme defaults

`TimelineDefaults` on the theme, as `theme.timeline`.

| Field | Type | Default | Description |
|---|---|---|---|
| `align` | `TimelineAlign` | `Start` | Which side content sits on. |
| `color` | `&'static str` | `"primary.6"` | The active accent. |
| `line_color` | `&'static str` | `"muted.6"` | Inactive bullets and connectors, 3:1 on the page (WCAG 1.4.11). |
| `bullet_background` | `&'static str` | `PAPER_BACKGROUND` | The bullet's fill, and the glyph colour once it inverts. Follows the surface color, so dark mode comes from `PaperDefaults`. |
| `radius` | `Size` | `Xl` | Bullet corner radius. |
| `bullet_size` | `Size` | `Md` | Which step of `bullet_sizes` is the default. |
| `bullet_sizes` | `Sizes<u16>` | 12/16/20/24/28/32 px | The bullet scale. |
| `line_width` | `u8` | `2` | Connector thickness, and the bullet's ring. |
| `gap` | `Size` | `Xl` | Which step of `gaps` is the default. |
| `gaps` | `Sizes<u16>` | 12/16/24/32/40/48 px | The event-spacing scale. |

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-timeline-color` | The active accent. Set per event by `.color(..)`. |
| `--lsx-timeline-line-color` | Inactive bullets and connectors. |
| `--lsx-timeline-line-width` | Connector thickness and bullet ring width. |
| `--lsx-timeline-bullet-background` | The bullet's fill, `var(--lsx-paper-background)` by default. |
| `--lsx-timeline-bullet-size-*` | The bullet scale, one per `Size`. |
| `--lsx-timeline-gap-*` | The event-spacing scale, one per `Size`. |

Some are set per element. `--lsx-timeline-bullet`, `--lsx-timeline-space` and
`--lsx-timeline-radius` hold the picked step of each size on the root.
`--lsx-timeline-line-style`, `--lsx-timeline-connector` and
`--lsx-timeline-marker` hold each event's line style and its two active
colours.

## Data attributes

On the root.

| Token | When |
|---|---|
| `align-start` / `align-end` / `align-alternate` | The resolved `align`. |
| `xs`..`xxl` | The resolved `bullet_size`. |
| `radius-xs`..`radius-xxl` | The resolved `radius`. |
| `gap-xs`..`gap-xxl` | The resolved `gap`. |
| `opposite` | Any event sets `.opposite(..)`. The rail is centred and each event drops its `align-*` token. |

On each event, and on its bullet.

| Token | When |
|---|---|
| `active` | This event is at or before `active`. |
| `opposite` | The timeline has an opposite. The bullet also has `align-alternate`, for the centred rail from `sm` up. |
| `content-end` | The body sits on the rail's end side (event only, with an opposite). |
| `line-active` | The connector below this event is before `active`. |
| `with-child` | The bullet holds a caller's element (bullet only). |
