# Badge and Spinner

Status feedback. `Badge` labels a state in a word or two; `Spinner` says something is in progress. Both render plain spans on the server.

```tsx
import { Badge, Spinner } from '@blocks/design-system'
```

## A pending task

Pair a named Spinner with words. When the work finishes, replace both with a Badge that states the result, inside a `role="status"` region so screen readers announce the change.

**Example: Sync a station** (`examples/status/sync-station.tsx`)

```tsx
'use client'

import { Badge, Button, Spinner, Stack } from '@blocks/design-system'
import { useState } from 'react'

type State = 'idle' | 'syncing' | 'synced'

export default function SyncStation() {
  const [state, setState] = useState<State>('idle')

  function sync() {
    setState('syncing')
    // Stands in for a request; the docs journey controls the clock.
    setTimeout(() => setState('synced'), 1500)
  }

  return (
    <Stack direction="row" gap="md" align="center" wrap="wrap">
      <Button type="button" onClick={sync} disabled={state === 'syncing'}>
        Sync Mount Hood
      </Button>
      {state === 'syncing' && <Spinner size="sm" label="Syncing Mount Hood" />}
      <span role="status" aria-label="Mount Hood sync">
        {state === 'idle' && <Badge>Not synced</Badge>}
        {state === 'syncing' && <Badge tone="info">Syncing</Badge>}
        {state === 'synced' && <Badge tone="success">Synced just now</Badge>}
      </span>
    </Stack>
  )
}
```

## Badge tones

`tone` picks a semantic color: `neutral` (the default), `accent`, `info`, `success`, `warning` or `danger`. `variant="solid"` fills the badge for more emphasis.

**Example: Tones** (`examples/status/badge-tones.tsx`)

```tsx
import { Badge, Stack } from '@blocks/design-system'

const tones = ['neutral', 'accent', 'info', 'success', 'warning', 'danger'] as const

export default function BadgeTones() {
  return (
    <Stack gap="sm">
      <Stack direction="row" gap="sm" wrap="wrap" aria-label="Subtle badges">
        {tones.map((tone) => (
          <Badge key={tone} tone={tone}>
            {tone}
          </Badge>
        ))}
      </Stack>
      <Stack direction="row" gap="sm" wrap="wrap" aria-label="Solid badges">
        {tones.map((tone) => (
          <Badge key={tone} tone={tone} variant="solid">
            {tone}
          </Badge>
        ))}
      </Stack>
    </Stack>
  )
}
```

## Spinner sizes

`sm` and `md` match the icon sizes; `lg` matches a medium control. `label` names the status (“Loading” by default). Under reduced motion the spinner keeps turning, ten times slower, so it still reads as busy.

**Example: Sizes** (`examples/status/spinner-sizes.tsx`)

```tsx
import { Spinner, Stack } from '@blocks/design-system'

export default function SpinnerSizes() {
  return (
    <Stack direction="row" gap="lg" align="center">
      <Spinner size="sm" label="Loading small" />
      <Spinner label="Loading medium" />
      <Spinner size="lg" label="Loading large" />
    </Stack>
  )
}
```

## Props

**`Badge` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"accent" \| "danger" \| "warning" \| "success" \| "info" \| "neutral"` | `neutral` | The semantic color. Defaults to `"neutral"`. |
| `variant` | `"subtle" \| "solid"` | `subtle` | `"subtle"` (default) tints the background; `"solid"` fills it. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`Spinner` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | `Loading` | Announced to screen readers. Defaults to "Loading". |
| `size` | `"sm" \| "md" \| "lg"` | `md` | `sm` and `md` match the icon sizes; `lg` matches a medium control. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

## Accessibility

- Color is never the only signal: a badge’s words carry the state, so “Synced” reads the same in grayscale.
- Spinner is a `role="status"` region. Give it a specific `label` (“Syncing Mount Hood”) and remove it when the work ends.
- Don’t put a Spinner inside a button’s label; disable the button and show the Spinner beside it.
