# Disco ball

A free-floating chrome mirror ball spins under one cool light while something loads, throwing one cross flare at a time, and coasts to a stop when it is done.

**Gesture:** watch · **Family:** loaders

## Use it

```bash
npx shadcn@latest add @mu-pro/disco-ball
```

**Pro.** Install it with your licence key: add `"@mu-pro": { "url": "https://cottoncandy.dev/r/pro/{name}.json", "headers": { "Authorization": "Bearer ${MU_PRO_TOKEN}" } }` to `registries` in `components.json`, and put `MU_PRO_TOKEN=<your key>` in `.env.local`. Keys come with a purchase at https://cottoncandy.dev/pricing.

If the CLI asks whether to overwrite `components/mu/foundation.css`, `motion.ts` or `sounds.ts`, answer **yes** (or pass `--overwrite`): newer items need the newer foundation, and older items keep working on it.

```tsx
import { DiscoBall } from "@/components/mu/disco-ball/DiscoBall";

<DiscoBall />
```

## Place it

One scale for every loader (FOUNDATION, `### loaders`). The box is exactly `size` and never shifts the layout.

```tsx
// inline, in a sentence (xs: 1em of the text, 16px in body text). The root is a
// <span> and every part is phrasing content, so it is valid inside a <p>, a <label>
// or a <button>; at body leading (text-sm, text-base) the line keeps its height
<p className="text-sm">
  Syncing your library <DiscoBall size="xs" label="Syncing" done={!loading} />
</p>

// or as a status line of its own: the caption is the line's text and carries its baseline
<p className="text-sm text-muted-foreground">
  <DiscoBall size="xs" caption="Loading your set…" done={!loading} />
</p>

// in a button: the loader takes the icon's slot, so the button keeps its width;
// aria-disabled (not disabled) keeps a keyboard user's focus while it saves
<Button aria-disabled={saving} aria-busy={saving} onClick={() => !saving && save()}>
  {saving ? <DiscoBall size="sm" data-icon="inline-start" /> : <Save data-icon="inline-start" />}
  Save
</Button>

// centred in a card or empty state, with a caption (reserve the box: 104px with p-6;
// a 1px border adds 2px, so min-h-[106px] with one)
<div className="grid min-h-[104px] place-items-center p-6">
  <DiscoBall size="md" caption="Fetching 24 tracks" done={!loading} onExited={() => setShown(false)} />
</div>

// over a section: the content stays laid out underneath
<section className="relative" aria-busy={busy}>
  <div inert={busy}>{children}</div>
  {shown && (
    <div className="absolute inset-0 grid place-items-center bg-background/80">
      <DiscoBall size="lg" caption="Rendering" done={!busy} onExited={() => setShown(false)} />
    </div>
  )}
</section>
```

## Props

Every prop is optional; the defaults are what the site shows. Other HTML attributes (such as `data-icon`) go to the root.

| Prop | Default | Range | What it does |
| --- | --- | --- | --- |
| `size` | `"md"` | `xs` · `sm` · `md` · `lg` · `xl` | the loader scale: 1em of the text, snapped to 4px (16 in body text) · 16 · 32 · 64 · 160px. Fewer, larger mirrors when small (6 rows up to 16px, 30 at 160), always one glint |
| `done` | `false` | — | `true` coasts the motor to a stop (1.2s), fades the ball (150ms) and calls `onExited`. `false` again spins it back up |
| `accent` | `false` | — | tints the light (and its flare and glow) with `--mu-signal`; the silver stays neutral |
| `caption` | — | text | visible: beside the ball at xs/sm (the line's own text), below it at md and up (muted). Screen readers hear it |
| `label` | `"Loading"` | — | what a screen reader hears when there is no caption (`role="status"`, polite) |
| `doneLabel` | `"Loaded"` | — | what it hears once `done` |
| `onExited` | — | — | called when the exit has finished, so you can remove it |
| `sound` | off | `true` or 0–1 | the motor's spin-up when a person's press started it, and its spin-down on `done` after that; never a loop |
| `className` | — | — | added to the root |

Other HTML attributes (`id`, `style`, `aria-*`, `data-*`, handlers) and `ref` go to the root `<span>`.

The ball is drawn on a canvas from the item's own `--disco-ball-*` colours (a bright studio by day, graphite under a cool light at night), so it follows light and dark, including a `.dark` section inside a light page. A flare and, by day, a soft contact shadow reach a little past the ball; the box is exactly `size` and the ball's centre is its centre.

## Input and reduced motion

- **Pointer / touch:** none; it is a status, not a control.
- **Keyboard:** not focusable. Screen readers hear `label`, then `doneLabel`.
- **Off-screen or hidden tab:** it stops drawing and keeps its place.
- **Arrive and leave:** from a 4px blur over 200ms as the motor starts; on `done` it coasts, then fades.
- **Reduced motion:** a still, lit ball; one slow glint breathes on its brightest mirror; on `done` it fades at once.
- **Performance:** one canvas, one frame loop that runs only while the motor turns or the glint breathes; it stops when idle.
