# Progress Ring

A small ring that shows a task's progress, with a count or a mark in its centre.

A small ring that shows a task's progress, with a count or a mark in its centre. Small progress ring with content in the center: the task badge. A custom property drives the arc; the root is a progressbar.

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

## Add

```bash
npx fndn add progress-ring
```

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

## Usage

```tsx
import { ProgressRing } from "@/components/ui/progress-ring";
```

```vue
import { ProgressRing } from "@/components/ui/progress-ring";
```

```svelte
import { ProgressRing } from "$lib/components/ui/progress-ring";
```

## Parts

In the DOM the root carries `data-slot="progress-ring"` and each part `data-slot="progress-ring-<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` | `progress-ring` |  | role=progressbar with aria-valuenow; carries --fndn-progress |
| `svg` | `svg` | `progress-ring-svg` |  | rotated -90deg so the arc starts at 12 o'clock |
| `track` | `circle` | `progress-ring-track` |  |  |
| `bar` | `circle` | `progress-ring-bar` |  | pathLength=100; dashoffset = 100 * (1 - progress) |
| `label` | `span` | `progress-ring-label` | optional |  |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `progress` | `number` | `0` | 0..1. Out-of-range and non-finite values are clamped. |
| `tone` | `"orange" \| "green" \| "red" \| "accent"` | `"orange"` |  |
| `size` | `"sm" \| "md"` | `"md"` | sm 24px · md 28px |
| `label` | `string` | `"Progress"` | Accessible name of the progress bar. |

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

## Slots

| Slot | Content |
| --- | --- |
| `default` | Center content (a step number) |

## Keyboard and accessibility

Role: progressbar.

Notes:

- aria-valuenow is the progress as a whole percentage; give the ring a label that says what is progressing.
- The center content is visual shorthand (a step number); the label and value carry the meaning.

## Motion

- arc: stroke-dashoffset over duration.move, easing.out-strong when progress changes; jumps under prefers-reduced-motion
- tone: the stroke colour changes over duration.base ease, with the travel (a completion turns green as the arc lands)
- nothing animates on mount

## Tokens

`color.line`, `color.orange`, `color.green`, `color.red`, `color.accent`, `color.ink`, `text.2xs`, `text.xs`, `duration.move`, `easing.out-strong`

## Examples

### Setup checklist

React · `setup-checklist.tsx`

```tsx
import { Check, Circle } from "@phosphor-icons/react";
import { ProgressRing } from "@/components/ui/progress-ring";

const steps = [
  { name: "Deploy to Production", done: true },
  { name: "Add a custom domain", done: false },
  { name: "Turn on usage alerts", done: false },
];

export default function SetupChecklist() {
  return (
    <div className="flex w-72 flex-col gap-3 text-sm">
      <div className="flex items-center gap-3">
        <ProgressRing progress={3 / 5} label="Setup: 3 of 5 steps done">3</ProgressRing>
        <div>
          <p className="font-medium text-ink">Set up web-app</p>
          <p className="text-ink-2">3 of 5 steps done</p>
        </div>
      </div>
      <ul className="flex flex-col gap-1.5">
        {steps.map((step) => (
          <li key={step.name} className={`flex items-center gap-2 ${step.done ? "text-ink-2 line-through" : "text-ink"}`}>
            {step.done ? <Check data-slot="icon" weight="bold" className="text-green" /> : <Circle data-slot="icon" className="text-ink-3" />}
            {step.name}
          </li>
        ))}
      </ul>
    </div>
  );
}
```

Vue · `setup-checklist.vue`

```vue
<script setup lang="ts">
import { PhCheck, PhCircle } from "@phosphor-icons/vue";
import { ProgressRing } from "@/components/ui/progress-ring";

const steps = [
  { name: "Deploy to Production", done: true },
  { name: "Add a custom domain", done: false },
  { name: "Turn on usage alerts", done: false },
];
</script>

<template>
  <div class="flex w-72 flex-col gap-3 text-sm">
    <div class="flex items-center gap-3">
      <ProgressRing :progress="3 / 5" label="Setup: 3 of 5 steps done">3</ProgressRing>
      <div>
        <p class="font-medium text-ink">Set up web-app</p>
        <p class="text-ink-2">3 of 5 steps done</p>
      </div>
    </div>
    <ul class="flex flex-col gap-1.5">
      <li v-for="step in steps" :key="step.name" :class="`flex items-center gap-2 ${step.done ? 'text-ink-2 line-through' : 'text-ink'}`">
        <PhCheck v-if="step.done" data-slot="icon" weight="bold" class="text-green" />
        <PhCircle v-else data-slot="icon" class="text-ink-3" />
        {{ step.name }}
      </li>
    </ul>
  </div>
</template>
```

Svelte · `setup-checklist.svelte`

```svelte
<script lang="ts">
  import Check from "phosphor-svelte/lib/CheckIcon";
  import Circle from "phosphor-svelte/lib/CircleIcon";
  import { ProgressRing } from "$lib/components/ui/progress-ring";

  const steps = [
    { name: "Deploy to Production", done: true },
    { name: "Add a custom domain", done: false },
    { name: "Turn on usage alerts", done: false },
  ];
</script>

<div class="flex w-72 flex-col gap-3 text-sm">
  <div class="flex items-center gap-3">
    <ProgressRing progress={3 / 5} label="Setup: 3 of 5 steps done">3</ProgressRing>
    <div>
      <p class="font-medium text-ink">Set up web-app</p>
      <p class="text-ink-2">3 of 5 steps done</p>
    </div>
  </div>
  <ul class="flex flex-col gap-1.5">
    {#each steps as step (step.name)}
      <li class={`flex items-center gap-2 ${step.done ? "text-ink-2 line-through" : "text-ink"}`}>
        {#if step.done}
          <Check data-slot="icon" weight="bold" class="text-green" />
        {:else}
          <Circle data-slot="icon" class="text-ink-3" />
        {/if}
        {step.name}
      </li>
    {/each}
  </ul>
</div>
```

### Pipeline steps

React · `pipeline-steps.tsx`

```tsx
import { ProgressRing } from "@/components/ui/progress-ring";

const steps = [
  { name: "Build", note: "48s", progress: 1, tone: "green" },
  { name: "Test", note: "38 of 64 suites", progress: 38 / 64, tone: "orange" },
  { name: "Deploy to Production", note: "Waiting", progress: 0, tone: "orange" },
] as const;

/* sm rings keep a list of steps compact */
export default function PipelineSteps() {
  return (
    <ol className="flex w-72 flex-col gap-2 text-sm">
      {steps.map((step, i) => (
        <li key={step.name} className="flex items-center gap-3">
          <ProgressRing progress={step.progress} tone={step.tone} size="sm" label={`${step.name}: ${step.note}`}>{i + 1}</ProgressRing>
          <span className="flex-1 text-ink">{step.name}</span>
          <span className="text-ink-2 tabular-nums">{step.note}</span>
        </li>
      ))}
    </ol>
  );
}
```

Vue · `pipeline-steps.vue`

```vue
<script setup lang="ts">
import { ProgressRing } from "@/components/ui/progress-ring";

const steps = [
  { name: "Build", note: "48s", progress: 1, tone: "green" },
  { name: "Test", note: "38 of 64 suites", progress: 38 / 64, tone: "orange" },
  { name: "Deploy to Production", note: "Waiting", progress: 0, tone: "orange" },
] as const;
</script>

<!-- sm rings keep a list of steps compact -->
<template>
  <ol class="flex w-72 flex-col gap-2 text-sm">
    <li v-for="(step, i) in steps" :key="step.name" class="flex items-center gap-3">
      <ProgressRing :progress="step.progress" :tone="step.tone" size="sm" :label="`${step.name}: ${step.note}`">{{ i + 1 }}</ProgressRing>
      <span class="flex-1 text-ink">{{ step.name }}</span>
      <span class="text-ink-2 tabular-nums">{{ step.note }}</span>
    </li>
  </ol>
</template>
```

Svelte · `pipeline-steps.svelte`

```svelte
<script lang="ts">
  import { ProgressRing } from "$lib/components/ui/progress-ring";

  const steps = [
    { name: "Build", note: "48s", progress: 1, tone: "green" },
    { name: "Test", note: "38 of 64 suites", progress: 38 / 64, tone: "orange" },
    { name: "Deploy to Production", note: "Waiting", progress: 0, tone: "orange" },
  ] as const;
</script>

<!-- sm rings keep a list of steps compact -->
<ol class="flex w-72 flex-col gap-2 text-sm">
  {#each steps as step, i (step.name)}
    <li class="flex items-center gap-3">
      <ProgressRing progress={step.progress} tone={step.tone} size="sm" label={`${step.name}: ${step.note}`}>{i + 1}</ProgressRing>
      <span class="flex-1 text-ink">{step.name}</span>
      <span class="text-ink-2 tabular-nums">{step.note}</span>
    </li>
  {/each}
</ol>
```

### Import stopped

React · `import-failed.tsx`

```tsx
import { Button } from "@/components/ui/button";
import { ProgressRing } from "@/components/ui/progress-ring";

export default function ImportFailed() {
  return (
    <div className="flex w-80 items-center gap-3 text-sm">
      <ProgressRing progress={0.42} tone="red" label="Import stopped at 42%">!</ProgressRing>
      <div className="min-w-0 flex-1">
        <p className="font-medium text-ink">Import stopped at 42%</p>
        <p className="text-ink-2">data-pipeline lost its connection after 18,240 of 43,500 events.</p>
      </div>
      <Button size="sm">Retry</Button>
    </div>
  );
}
```

Vue · `import-failed.vue`

```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button";
import { ProgressRing } from "@/components/ui/progress-ring";
</script>

<template>
  <div class="flex w-80 items-center gap-3 text-sm">
    <ProgressRing :progress="0.42" tone="red" label="Import stopped at 42%">!</ProgressRing>
    <div class="min-w-0 flex-1">
      <p class="font-medium text-ink">Import stopped at 42%</p>
      <p class="text-ink-2">data-pipeline lost its connection after 18,240 of 43,500 events.</p>
    </div>
    <Button size="sm">Retry</Button>
  </div>
</template>
```

Svelte · `import-failed.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { ProgressRing } from "$lib/components/ui/progress-ring";
</script>

<div class="flex w-80 items-center gap-3 text-sm">
  <ProgressRing progress={0.42} tone="red" label="Import stopped at 42%">!</ProgressRing>
  <div class="min-w-0 flex-1">
    <p class="font-medium text-ink">Import stopped at 42%</p>
    <p class="text-ink-2">data-pipeline lost its connection after 18,240 of 43,500 events.</p>
  </div>
  <Button size="sm">Retry</Button>
</div>
```

## Recipe

`progress-ring.recipe.ts`:

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

/* progress-ring — small ring with content in the center, the task badge.
 * --fndn-progress (0..1, set by the adapter) drives the arc; pathLength="100" on the circles keeps
 * the math size-independent.
 *
 * Motion included: the arc travels when progress changes (reduced motion makes it jump). The
 * first slot is `base`. */

export const progressRing = tv({
  slots: {
    base: "[--fndn-progress:0] relative inline-flex shrink-0 items-center justify-center size-7 align-middle",
    /* the arc starts at the top */
    svg: "absolute inset-0 size-full -rotate-90",
    track: "fill-none stroke-line stroke-2",
    bar: [
      "fill-none stroke-orange stroke-2 [stroke-linecap:round]",
      "[stroke-dasharray:100] [stroke-dashoffset:calc(100*(1-var(--fndn-progress)))]",
      "motion-also-[stroke-dashoffset_var(--fndn-duration-move)_var(--fndn-easing-out-strong)]",
      /* a tone change (orange → green on completion) fades with the travel, as the progress bar does */
      "motion-colors-base",
    ],
    label: "relative text-xs font-semibold tabular-nums leading-none text-ink",
  },
  variants: {
    size: {
      sm: { base: "size-6", label: "text-2xs" },
      md: { base: "size-7" },
    },
    tone: {
      orange: {},
      green: { bar: "stroke-green" },
      red: { bar: "stroke-red" },
      accent: { bar: "stroke-accent" },
    },
  },
  defaultVariants: { size: "md", tone: "orange" },
});

export type ProgressRingRecipeProps = VariantProps<typeof progressRing>;
```
