# Spinner

A small spinning ring for work of unknown length.

A small spinning ring for work of unknown length. Ring with a single ink arc, spinning at 700ms. Fast on purpose: a quick spinner makes the wait feel shorter.

Kind: component · Category: Feedback · Status: stable · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add spinner
```

It writes the folder `spinner/` into the project's ui folder (`index.ts`, `spinner.tsx`, `Spinner.vue`, `Spinner.svelte`, `spinner.recipe.ts`). First time: [Installation](/installation.md).

## Usage

```tsx
import { Spinner } from "@/components/ui/spinner";
```

```vue
import { Spinner } from "@/components/ui/spinner";
```

```svelte
import { Spinner } from "$lib/components/ui/spinner";
```

## Parts

In the DOM the root carries `data-slot="spinner"` and each part `data-slot="spinner-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `span` | `spinner` |  | role=status |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"sm" \| "md" \| "lg"` | `"sm"` |  |
| `label` | `string` | `"Loading"` |  |
| `decorative` | `boolean` | `false` | Purely visual, inside something that is already a status region (selection-actions' status): aria-hidden, no role=status and no label. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Keyboard and accessibility

Role: status.

Notes:

- The label is the accessible name; make it say what is loading.
- Do not show a spinner for work that finishes in under 300ms; the flash reads as a glitch.

## Motion

- rotate 360° every 700ms, linear, forever
- keeps spinning under prefers-reduced-motion: it is the loading signal, not decoration

## Tokens

`color.line-strong`, `color.ink-2`

## Examples

### A build running in a list

React · `deploy-list.tsx`

```tsx
import { CheckCircle } from "@phosphor-icons/react";
import { Spinner } from "@/components/ui/spinner";

const deploys = [
  { id: "dpl_7f3a9c", branch: "feat/usage-alerts", building: true, status: "Building · 1m 12s" },
  { id: "dpl_51e0b2", branch: "main", building: false, status: "Ready · 2 min ago" },
  { id: "dpl_0c94d7", branch: "fix/tax-rounding", building: false, status: "Ready · 1 h ago" },
];

export default function DeployList() {
  return (
    <ul className="flex w-80 max-w-full flex-col gap-2 text-sm">
      {deploys.map((deploy) => (
        <li key={deploy.id} className="flex items-center gap-2">
          {deploy.building ? (
            <Spinner label="Building" />
          ) : (
            <CheckCircle data-slot="icon" weight="fill" className="shrink-0 text-green" aria-hidden />
          )}
          <span className="min-w-0 flex-1 truncate text-ink" title={deploy.branch}>{deploy.branch}</span>
          <span className="shrink-0 text-ink-2 tabular-nums">{deploy.status}</span>
        </li>
      ))}
    </ul>
  );
}
```

Vue · `deploy-list.vue`

```vue
<script setup lang="ts">
import { PhCheckCircle } from "@phosphor-icons/vue";
import { Spinner } from "@/components/ui/spinner";

const deploys = [
  { id: "dpl_7f3a9c", branch: "feat/usage-alerts", building: true, status: "Building · 1m 12s" },
  { id: "dpl_51e0b2", branch: "main", building: false, status: "Ready · 2 min ago" },
  { id: "dpl_0c94d7", branch: "fix/tax-rounding", building: false, status: "Ready · 1 h ago" },
];
</script>

<template>
  <ul class="flex w-80 max-w-full flex-col gap-2 text-sm">
    <li v-for="deploy in deploys" :key="deploy.id" class="flex items-center gap-2">
      <Spinner v-if="deploy.building" label="Building" />
      <PhCheckCircle v-else data-slot="icon" weight="fill" class="shrink-0 text-green" aria-hidden="true" />
      <span class="min-w-0 flex-1 truncate text-ink" :title="deploy.branch">{{ deploy.branch }}</span>
      <span class="shrink-0 text-ink-2 tabular-nums">{{ deploy.status }}</span>
    </li>
  </ul>
</template>
```

Svelte · `deploy-list.svelte`

```svelte
<script lang="ts">
  import CheckCircle from "phosphor-svelte/lib/CheckCircleIcon";
  import { Spinner } from "$lib/components/ui/spinner";

  const deploys = [
    { id: "dpl_7f3a9c", branch: "feat/usage-alerts", building: true, status: "Building · 1m 12s" },
    { id: "dpl_51e0b2", branch: "main", building: false, status: "Ready · 2 min ago" },
    { id: "dpl_0c94d7", branch: "fix/tax-rounding", building: false, status: "Ready · 1 h ago" },
  ];
</script>

<ul class="flex w-80 max-w-full flex-col gap-2 text-sm">
  {#each deploys as deploy (deploy.id)}
    <li class="flex items-center gap-2">
      {#if deploy.building}
        <Spinner label="Building" />
      {:else}
        <CheckCircle data-slot="icon" weight="fill" class="shrink-0 text-green" aria-hidden="true" />
      {/if}
      <span class="min-w-0 flex-1 truncate text-ink" title={deploy.branch}>{deploy.branch}</span>
      <span class="shrink-0 text-ink-2 tabular-nums">{deploy.status}</span>
    </li>
  {/each}
</ul>
```

### Deploy in progress

React · `busy-button.tsx`

```tsx
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";

export default function BusyButton() {
  return (
    <Button aria-disabled aria-busy icon={<Spinner decorative />}>
      Deploying to Production…
    </Button>
  );
}
```

Vue · `busy-button.vue`

```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
</script>

<template>
  <Button aria-disabled="true" aria-busy="true">
    <template #icon><Spinner decorative /></template>
    Deploying to Production…
  </Button>
</template>
```

Svelte · `busy-button.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Spinner } from "$lib/components/ui/spinner";
</script>

<Button aria-disabled="true" aria-busy="true">
  {#snippet icon()}<Spinner decorative />{/snippet}
  Deploying to Production…
</Button>
```

### Loading a panel

React · `loading-panel.tsx`

```tsx
import { Spinner } from "@/components/ui/spinner";

export default function LoadingPanel() {
  return (
    <div role="status" className="flex h-32 w-80 max-w-full flex-col items-center justify-center gap-3 text-sm text-ink-2">
      <Spinner size="lg" decorative />
      Loading build logs for dpl_7f3a9c…
    </div>
  );
}
```

Vue · `loading-panel.vue`

```vue
<script setup lang="ts">
import { Spinner } from "@/components/ui/spinner";
</script>

<template>
  <div role="status" class="flex h-32 w-80 max-w-full flex-col items-center justify-center gap-3 text-sm text-ink-2">
    <Spinner size="lg" decorative />
    Loading build logs for dpl_7f3a9c…
  </div>
</template>
```

Svelte · `loading-panel.svelte`

```svelte
<script lang="ts">
  import { Spinner } from "$lib/components/ui/spinner";
</script>

<div role="status" class="flex h-32 w-80 max-w-full flex-col items-center justify-center gap-3 text-sm text-ink-2">
  <Spinner size="lg" decorative />
  Loading build logs for dpl_7f3a9c…
</div>
```

## Recipe

`spinner.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* spinner — ring with a single ink-2 arc; sits on the middle of the text when used inline.
 * The spin is fast on purpose: a quick spinner makes the wait feel shorter. It keeps spinning under
 * reduced motion; it is the loading signal. @keyframes fndn-spin is in base.css;
 * one element, so the recipe is `base` only. */

export const spinner = tv({
  base: "inline-block shrink-0 size-3 rounded-[50%] border-[1.5px] border-solid border-line-strong border-t-ink-2 align-[-0.125em] animate-[fndn-spin_700ms_linear_infinite]",
  variants: {
    size: {
      sm: "size-3",
      md: "size-4 border-2",
      lg: "size-6 border-2",
    },
  },
  defaultVariants: { size: "sm" },
});

export type SpinnerRecipeProps = VariantProps<typeof spinner>;
```
