# Loading State

A compact loader with an elapsed timer for long-running agent work.

A compact loader for long-running agent work: a pixel grid, a shimmering label and an elapsed timer. The 3×3 grid draws a chevron wavefront (drive / dots) or a comet lapping the perimeter (orbit); the timer is in mono tabular figures.

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

## Add

```bash
npx fndn add loading-state
```

It writes the folder `loading-state/` into the project's ui folder (`index.ts`, `loading-state.tsx`, `LoadingState.vue`, `LoadingState.svelte`, `loading-state.recipe.ts`), and what it is built from: [Shimmer](/components/shimmer.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { LoadingState } from "@/components/ui/loading-state";
```

```vue
import { LoadingState } from "@/components/ui/loading-state";
```

```svelte
import { LoadingState } from "$lib/components/ui/loading-state";
```

## Parts

In the DOM the root carries `data-slot="loading-state"` and each part `data-slot="loading-state-<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` | `div` | `loading-state` |  | role=status, aria-label = the label |
| `grid` | `span` | `loading-state-grid` |  | aria-hidden 3×3 grid |
| `cell` | `span` | `loading-state-cell` | repeats | nine 4px cells; delay by nth-child |
| `label` | `span` | `loading-state-label` |  | The real Shimmer (fast), marked data-loading-state="label"; truncates, full text in title |
| `elapsed` | `span` | `loading-state-elapsed` | optional | aria-hidden: the ticking time is never announced |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"drive" \| "dots" \| "orbit"` | `"drive"` |  |
| `label` | `string` | `"Loading"` | Status text; also the region's accessible name. |
| `elapsed` | `string` |  | Formatted elapsed time from the host. When omitted, the adapters tick it from mount (7.9s · 1m 2.0s · 1h 12m). |
| `showElapsed` | `boolean` | `true` |  |

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

## States

`loading`

## Keyboard and accessibility

Role: status.

Notes:

- The root is a role=status region named by the label; changing the label is announced once.
- The elapsed time is aria-hidden so its 100ms ticks are never announced; the pixel grid is aria-hidden.
- Nothing is focusable or interactive.

## Motion

- cells: fndn-pixel-on loop (opacity only), 650ms (orbit 950ms) with easing ease, staggered 90ms (orbit 110ms) through literal loop delays; keeps pulsing under reduced motion (it is the loading signal)
- label: our shimmer at its fast speed (1.4s loop); the shimmer stops under reduced motion and shows static ink-2 text
- no entrance and no other motion; the timer ticks in tabular figures so nothing shifts

## Tokens

`color.ink`, `color.ink-2`, `font.mono`, `text.xs`, `text.sm`

## Dependencies

- [Shimmer](/components/shimmer.md)

## Examples

### Reading the codebase

React · `drive.tsx`

```tsx
import { LoadingState } from "@/components/ui/loading-state";

export default function Drive() {
  return (
    <LoadingState
      label="Reading 214 files in harbor/api"
      elapsed="12.4s"
    />
  );
}
```

Vue · `drive.vue`

```vue
<script setup lang="ts">
import { LoadingState } from "@/components/ui/loading-state";
</script>

<template>
  <LoadingState label="Reading 214 files in harbor/api" elapsed="12.4s" />
</template>
```

Svelte · `drive.svelte`

```svelte
<script lang="ts">
  import { LoadingState } from "$lib/components/ui/loading-state";
</script>

<LoadingState label="Reading 214 files in harbor/api" elapsed="12.4s" />
```

### Running the test suite

React · `dots.tsx`

```tsx
import { LoadingState } from "@/components/ui/loading-state";

export default function Dots() {
  return (
    <LoadingState
      variant="dots"
      label="Running the test suite"
      elapsed="1m 8.2s"
    />
  );
}
```

Vue · `dots.vue`

```vue
<script setup lang="ts">
import { LoadingState } from "@/components/ui/loading-state";
</script>

<template>
  <LoadingState
    variant="dots"
    label="Running the test suite"
    elapsed="1m 8.2s"
  />
</template>
```

Svelte · `dots.svelte`

```svelte
<script lang="ts">
  import { LoadingState } from "$lib/components/ui/loading-state";
</script>

<LoadingState
  variant="dots"
  label="Running the test suite"
  elapsed="1m 8.2s"
/>
```

### Deploying to production

React · `orbit.tsx`

```tsx
import { LoadingState } from "@/components/ui/loading-state";

export default function Orbit() {
  return (
    <LoadingState
      variant="orbit"
      label="Deploying harbor/web to production"
      elapsed="3m 41.0s"
    />
  );
}
```

Vue · `orbit.vue`

```vue
<script setup lang="ts">
import { LoadingState } from "@/components/ui/loading-state";
</script>

<template>
  <LoadingState
    variant="orbit"
    label="Deploying harbor/web to production"
    elapsed="3m 41.0s"
  />
</template>
```

Svelte · `orbit.svelte`

```svelte
<script lang="ts">
  import { LoadingState } from "$lib/components/ui/loading-state";
</script>

<LoadingState
  variant="orbit"
  label="Deploying harbor/web to production"
  elapsed="3m 41.0s"
/>
```

### Timer counted by the block

React · `live-timer.tsx`

```tsx
import { LoadingState } from "@/components/ui/loading-state";

export default function LiveTimer() {
  return <LoadingState label="Drafting the migration plan" />;
}
```

Vue · `live-timer.vue`

```vue
<script setup lang="ts">
import { LoadingState } from "@/components/ui/loading-state";
</script>

<template>
  <LoadingState label="Drafting the migration plan" />
</template>
```

Svelte · `live-timer.svelte`

```svelte
<script lang="ts">
  import { LoadingState } from "$lib/components/ui/loading-state";
</script>

<LoadingState label="Drafting the migration plan" />
```

## Recipe

`loading-state.recipe.ts`:

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

/* loading-state — pixel-grid loader for long-running work.
 *   drive  square cells, chevron wavefront driving right (650ms cycle)
 *   dots   same wavefront, circular cells
 *   orbit  a comet lapping the grid perimeter (950ms)
 * Paired with a shimmering label (the real Shimmer, fast; this recipe's `label` is passed to it as
 * className) and an elapsed timer in mono tabular figures.
 *
 * Motion: three loops and nothing else. The grid is opacity-only and keeps pulsing under reduced
 * motion (it is the loading signal); the label shimmer stops there and shows static ink-2 text.
 * The loop timings are literal (like the spinner's): --_dur on the root, --_delay per cell.
 * fndn-pixel-on is in base.css. The label is the real Shimmer, marked
 * data-loading-state="label". */

export const loadingState = tv({
  slots: {
    base: "[--_dur:650ms] inline-flex w-fit max-w-full min-w-0 items-center gap-2.5",
    grid: "grid shrink-0 grid-cols-[repeat(3,4px)] gap-[1.5px]",
    cell: [
      "size-1 rounded-[1px] bg-ink opacity-15",
      "animate-[fndn-pixel-on_var(--_dur)_ease_var(--_delay,0ms)_infinite]",
      /* chevron wavefront: delay = (col + |row - 1|) * 90ms */
      "nth-1:[--_delay:90ms] nth-2:[--_delay:180ms] nth-3:[--_delay:270ms]",
      "nth-4:[--_delay:0ms] nth-5:[--_delay:90ms] nth-6:[--_delay:180ms]",
      "nth-7:[--_delay:90ms] nth-8:[--_delay:180ms] nth-9:[--_delay:270ms]",
    ],
    /* on the Shimmer: truncates here, the full text in its title */
    label: "min-w-0 overflow-hidden text-ellipsis text-sm font-medium whitespace-nowrap [unicode-bidi:plaintext]",
    elapsed: "font-mono text-xs tabular-nums whitespace-nowrap shrink-0 text-ink-2 [unicode-bidi:plaintext]",
  },
  variants: {
    variant: {
      drive: {},
      dots: { cell: "rounded-[50%]" },
      /* perimeter order 1 2 3 6 9 8 7 4, 110ms apart; the center stays dim */
      orbit: {
        base: "[--_dur:950ms]",
        cell: [
          "nth-1:[--_delay:0ms] nth-2:[--_delay:110ms] nth-3:[--_delay:220ms] nth-6:[--_delay:330ms]",
          "nth-9:[--_delay:440ms] nth-8:[--_delay:550ms] nth-7:[--_delay:660ms] nth-4:[--_delay:770ms]",
          "nth-5:opacity-[0.07] nth-5:animate-none",
        ],
      },
    },
  },
  defaultVariants: { variant: "drive" },
});

export type LoadingStateRecipeProps = VariantProps<typeof loadingState>;
```
