# Spinner

A turning arc that shows work is running when the amount is unknown: loading a list, checking a value. Its name is read by screen readers and never shown.

**Dependencies:** npm: 2 direct, 3 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Show that work runs when its length is unknown: loading comments, checking a value.
- A small region or a control that waits, right where the result will appear.

### When not to use

- Work whose amount is known, such as an upload. Use Progress.
- A page or list whose layout you know while it loads. Use Skeleton.

### Native

**Default**

```text
WerewolfSpinner()
```

```text
WerewolfSpinner()
```

**Named**

```text
WerewolfSpinner(label: "Loading comments", tone: .accent)
```

```text
WerewolfSpinner(label = "Loading comments", tone = WerewolfSpinnerTone.Accent)
```

## Variants

### size

sm (16px) inside sm and md controls; md (20px) inside lg controls; lg (24px) on its own in a region that loads.

Values: `sm`, `md`, `lg`. Default: `md`.

### tone

secondary on surfaces; accent when the spinner is the main thing on screen; current takes the text color around it, such as a label inside a Button.

Values: `secondary`, `accent`, `current`. Default: `secondary`.

## Examples

### Loading a list

```tsx
<div className="flex items-center gap-sm text-sm text-text-secondary">
  <Spinner size="sm" label="Loading comments" />
  <span aria-hidden="true">Loading comments</span>
</div>
```

### On its own

lg and accent when it is the only thing in the region.

```tsx
<Spinner size="lg" tone="accent" label="Loading dashboard" />
```

## Do and don't

### Do

- Name what loads in the label: Loading comments.
- Put it where the content will appear, so the eye is already there when it does.
- Use tone current inside a control, so it takes the control's text color.

### Don't

- Don't use it when the amount of work is known, such as an upload. Use Progress.
- Don't use it for a whole page or list whose layout you know. Use Skeleton.
- Don't show several spinners for one task.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `size` | `enum` | `sm`, `md`, `lg` | `md` | sm (16px) inside sm and md controls; md (20px) inside lg controls; lg (24px) on its own in a region that loads. |
| `tone` | `enum` | `secondary`, `accent`, `current` | `secondary` | secondary on surfaces; accent when the spinner is the main thing on screen; current takes the text color around it, such as a label inside a Button. |
| `label` | `string` |  | `Loading` | What is loading, for screen readers: Loading comments. Never shown. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | An inline box the size of the icon, in an icon color. |
| `icon` | Tabler Loader2: 16px (sm), 20px (md) or 24px (lg). It turns under motion-safe. |
| `label` | Visually hidden text that names what is loading. |

## Accessibility

Role: `status`

- The root is a status region, and label (Loading by default) is its visually hidden text. Name what loads: Loading comments.
- The arc is decorative (aria-hidden); the label carries the meaning.
- It turns only when the user allows motion. Under prefers-reduced-motion it holds still, and the label still says what is happening.
- Remove it when the work is done, and move focus to the result only if the user asked for it.

## Install

```bash
npx werewolf-ui add spinner
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add spinner --platform ios
npx werewolf-ui add spinner --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
