# Loader

Crate: `libero`
Import: `use libero::components::Loader;`
Feature: `loader` (on by default, turns on `box`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/feedback/loader.rs>
Index: [index.md](index.md) lists every other page
Description: An indeterminate busy indicator: a ring, bars or dots. It stays silent, so a status region says the wait. `Button`, `Combobox` and `FileField` show it.

An indeterminate busy indicator. It says something is happening, not how much
is left. The root is a `<span>`, so it fits inside a paragraph or a button.
With reduced motion it stops moving but stays visible.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::{Flex, Loader, Text};

#[component]
fn Demo() -> Element {
    rsx! {
        // Beside its own text, the text says the wait.
        Flex { direction: "row", align: "center", gap: "sm",
            Loader {}
            Text { "Uploading…" }
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `variant` | `LoaderVariant` | `oval` | The shape: `oval`, `bars` or `dots`. |
| `size` | `Responsive<Size>` | `md` | The edge of the square, 18px at `xs` to 72px at `xxl`. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `color` | `ThemeAwareValue` | `primary` | A theme color name paints its text shade, so the ink stands out from the page. Any other CSS color paints as given. |

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

## Accessibility

### Libero handles

- The loader is hidden from screen readers.
- With reduced motion it stops moving but stays visible.
- A theme color draws in its text shade, at 3:1 or more against the page. Yellow
  stays short of that on a light page, so `warning` adds a 1px ink edge.

### You must

- Say the wait with something else. Beside its own text, the text says it.
  Inside a control, such as a `Button` with `loading`, the control does.
- As the only content of a region, mark the region `aria-busy` and put the
  text in a `role="status"` region outside it.
- Mount that status region up front and fill it only while loading, or a
  screen reader may skip it.

### Example

A `Loader` beside the text "Loading results": a screen reader reads the text
and skips the loader. With reduced motion the loader stops moving.

## Theme defaults

`LoaderDefaults` on the theme.

| Field | Type | Description |
|---|---|---|
| `variant` | `LoaderVariant` | `Oval`. |
| `size` | `Size` | `Md`. |
| `color` | `Color` | `Primary`. |
| `sizes` | `Sizes<&'static str>` | The edge per step: `18px`, `22px`, `36px`, `44px`, `58px`, `72px`. |

Durations are fixed. Override `animation-duration` through `sx` to change one.

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-loader-size-<size>` | The edge for that step, from `LoaderDefaults`. |
| `--lsx-loader-size` | The active step's edge, republished unsuffixed on the root; the bars and dots inherit it. Override it for an off-scale size. |
| `--lsx-loader-color` | Resolved `color` in its text shade, per instance. |

## Data attributes

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

| Token | Condition |
|---|---|
| `oval` / `bars` / `dots` | The `variant` in effect. |
| `size-<size>` | The `size` in effect. |
