# ProgressBar

Crate: `libero`
Import: `use libero::components::ProgressBar;`
Feature: `progress-bar` (off by default, turns on `slider`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/feedback/progress_bar.rs>
Index: [index.md](index.md) lists every other page
Description: A determinate or indeterminate progress bar over any `min..=max` range.

A bar that fills from `min` to `max`. It shows output and takes no focus. With
`value: None` it sweeps instead, for the time before the total is known.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::ProgressBar;

#[component]
fn Demo() -> Element {
    let uploaded = use_signal(|| 40.0);

    rsx! {
        ProgressBar {
            aria_label: "Upload",
            value: uploaded(),
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `Option<f64>` | `None` | Current progress, clamped into `min..=max`. Omitted or `None` makes it indeterminate. |
| `min` | `f64` | `0.0` | Range start. |
| `max` | `f64` | `100.0` | Range end. At or below `min` the bar draws empty. |
| `color` | `ThemeAwareValue` | `primary` | The fill. A theme color name paints its text shade, darker on a light page so the bar stands out from its track. Any other CSS color paints as given. |
| `size` | `Responsive<Size>` | `md` | Track height, 3px at `xs` to 20px at `xxl`. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `radius` | `Responsive<ThemeAwareValue>` | `xl` | Corner of the track and the fill, or any CSS, e.g. `radius: "0"`. On a thin track most steps draw the same pill. Or one per breakpoint, `radius: responsive(Size::Xs).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `aria_valuetext` | `String` | - | Read instead of the rounded percentage, such as "4.2 MB of 12 MB". |
| `segments` | `Vec<ProgressBarSegment>` | `[]` | Splits the track into stretches with 2px gaps, each from its `start` to the next one's, as a `Slider`'s `segments`, and fills them up to the value. The label of the stretch the value is in follows the percentage, as "60%, Upload"; `aria_valuetext` replaces both. Sorted for you; a start outside the range or a repeat is dropped, and an unlabeled stretch fills from `min` to the first start. An indeterminate bar sweeps as without them. |
| `parts` | `Parts<ProgressBarPart>` | - | Styles for the inner parts in the Style API tab, under `sx`: `Parts::new().part(ProgressBarPart::Fill, sx().background("success.6"))`. |

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

### `ProgressBarSegment`

| Prop | Type | Default | Description |
|---|---|---|---|
| `start` | `f64` | - | Where the stretch starts; it ends at the next one's start, or `max`. |
| `label` | `Option<String>` | - | Names the stretch, read after the percentage while the value is in it. `ProgressBarSegment::labeled(start, label)`. |

## 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 |
|---|---|---|
| `ProgressBarPart::Fill` | `fill` | The drawn share, or the indeterminate sweep. The root is the track. |
| `ProgressBarPart::Segments` | `segments` | The row of segments a `segments` bar draws instead of the fill. |
| `ProgressBarPart::Segment` | `segment` | One stretch of a segmented bar. |
| `ProgressBarPart::SegmentFill` | `segment-fill` | The filled part of a segment. |

## Accessibility

### Libero handles

- A screen reader reads the rounded percentage, then the label of the segment
  the value is in, as "60%, Upload"; `aria_valuetext` replaces both.
- The bar takes no focus.
- A theme color fills in its text shade, at 3:1 or more against the track and the page. Yellow stays short of that on a light page, so `warning` draws a 1px ink edge inside its fill.
- With reduced motion an indeterminate bar stops sweeping and shows as a full
  bar striped in its colour, so it does not read as part done and keeps its 3:1.

### You must

- Name it with `aria_label`, or `aria_labelledby` pointing at a visible
  caption.
- The bar is not a live region. To announce progress, update a separate status
  line at milestones, not on every tick.

### Example

An upload bar, `ProgressBar { value: Some(42.0), aria_label: "Upload" }`: a
screen reader reads the name "Upload" and 42% when it reaches the bar. A
status line beside it says "Half done" once, at the milestone.

## Theme defaults

`ProgressBarDefaults` on the theme, as `theme.progress_bar`.

| Field | Type | Description |
|---|---|---|
| `color` | `Color` | Default `color` when the prop is omitted (`primary`). |
| `size` | `Size` | Default `size` when the prop is omitted (`md`). |
| `radius` | `Size` | Default `radius` when the prop is omitted (`xl`). |
| `track_shade` | `ColorShade` | Grey step of the unfilled track (`S2`). |
| `transition` | `&'static str` | How long the fill eases to a new value (`100ms`). |
| `sizes` | `Sizes<&'static str>` | Track height per size step: `3px 5px 8px 12px 16px 20px`. |

Where the radius stops mattering, radius scale `2/4/8/16/32/64px`:

| Track | Height | Pill from | Radius steps that look different |
|---|---|---|---|
| `xs` | 3px | `xs` | none |
| `sm` | 5px | `sm` | `xs` |
| `md` | 8px | `sm` | `xs` |
| `lg` | 12px | `md` | `xs`, `sm` |
| `xl` | 16px | `md` | `xs`, `sm` |
| `xxl` | 20px | `lg` | `xs`, `sm`, `md` |

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-progress-bar-thickness-<size>` | Track height for that size step. |
| `--lsx-progress-bar-size` | The picked height, resolved on the root. |
| `--lsx-progress-bar-radius` | The picked radius, resolved on the root; the fill inherits the corner. |
| `--lsx-progress-bar-track` | The unfilled track, `muted.2`. Themed once. |
| `--lsx-progress-bar-transition` | Duration of the fill's `width` transition. Themed once. |
| `--lsx-progress-bar-color` | The resolved `color` in its text shade, per instance. |
| `--lsx-progress-bar-fill` | The drawn percentage, e.g. `42%`, per instance. Not written while indeterminate, and nothing reads it then. |

The sweep is `@keyframes lsx-progress-bar-indeterminate`, emitted once in the
theme stylesheet.

## Data attributes

`data-state` on the root and on the fill carries `size-*`, `radius-*`, and
either `determinate` or `indeterminate`; the root also carries `segmented` while
it draws segments. `data-slot="fill"` marks the fill, see [Style API](#style-api).
