# Segmented progress

Shows how far along something is as a row of small cells that ramp from a light to a deep accent blue. It reads at a glance when the amount counts whole things.

Status: Stable. Group: Feedback.

## When to use

- Progress through a set of whole items: 19 of 24 screens audited.
- A compact meter inside a card or a list row, with a short line after it such as 5 left.

## When not to use

- The amount is a stream, such as bytes uploaded. Use Progress instead.
- It shows where someone is in a short flow. Use Steps, in Progress and steps instead.
- There are only three or four things. Use Steps, in Progress and steps instead.

## Scenarios

### Audit coverage

The Checkout flow audit has 24 screens. 19 cells are filled and the line after the track says 5 left; each screen audited fills the next cell.

### Brand tokens

A Brand panel row shows 21 of 24 cells for tokens in use and 3 unused at the end, so the gap is the story.

## Do and avoid

- Do: Set cells to the number of things being counted, up to about 24.
- Avoid: Use 100 cells to fake a percentage; use Progress.
- Do: Say what is counted in label, and put the remainder in trailing.
- Avoid: Leave the meaning to the colour alone.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` |  | Required. Names the bar for assistive tech (aria-label): Checkout flow audit. |
| `value` | `number` |  | Cells filled, rounded and clamped between 0 and cells. |
| `cells` | `number` | `24` | How many cells the track has. aria-valuemax follows it. |
| `trailing` | `ReactNode` |  | A short line after the track, such as 5 left. Not part of the accessible name. |
| `className` | `string` |  | Extra classes on the root. |

## Anatomy

1. Track (`data-part="track"`): 26 px sunken bar, radius 10 px, 3 px padding and a 2 px gap between cells.
2. Cell (`data-part="cell"`): One equal slot, radius 4 px, a little darker than the track while empty.
3. Fill (`data-part="fill"`): The colour of a filled cell: a fixed ramp of color-mix steps from a light to a deep accent, the same in both themes.
4. Trailing line (`data-part="trailing"`): Body 14/20 at weight 500 in fg, 14 px after the track.

## Motion

| Interaction | Property | Duration | Easing | From the keyboard |
| --- | --- | --- | --- | --- |
| Value change | opacity and scale .5 to 1 of the cells that change, left to right, 14 ms apart (emptying runs right to left) | quick | out | Same: the bar only reports a value, a key press never starts it. Instant with reduced motion or Motion off. |

## Accessibility

| Keys | Action |
| --- | --- |
| Tab | Not focusable. It reports a value; it takes no input. |

- role progressbar with aria-label, aria-valuenow, aria-valuemin 0 and aria-valuemax set to the cell count.
- The cells are decorative: assistive tech hears one value, not 24 elements.
- The filled share is also readable from the trailing line, so colour is never the only signal.

## Code

### SegmentedProgress.tsx

```tsx
'use client'
import { useState, type CSSProperties, type ReactNode } from 'react'

// Nacre SegmentedProgress: how far along something is, as a row of small cells. It reads faster than a bar when
// the amount counts whole things (screens audited, lessons done). Progress (Progress.tsx) is the plain bar for a
// stream such as an upload. React plus Tailwind classes only; needs nacre-theme.css. The filled cells ramp from a
// light to a deep accent: a fixed ramp of color-mix steps on the accent role, so it follows both themes.
// Motion: when the value changes, the new cells fade and scale in left to right, 14 ms apart (quick 160, out),
// by opacity and scale only. It is display only, so a key press never starts it. Reduced motion and
// [data-nacre-motion="off"] change at once.

export type SegmentedProgressProps = {
  label: string
  /** Cells filled, from 0 to cells. */
  value: number
  /** How many cells the track has. */
  cells?: number
  /** A short line after the track, such as 5 left. */
  trailing?: ReactNode
  className?: string
}

/** The accent mixed toward white on the first half of the track and toward black on the second half. */
function ramp(i: number, n: number): string {
  const t = n > 1 ? i / (n - 1) : 1
  const white = Math.round(55 * Math.max(0, 1 - t * 2))
  const black = Math.round(32 * Math.max(0, t * 2 - 1))
  return `color-mix(in oklab, black ${black}%, color-mix(in oklab, white ${white}%, var(--nx-accent)))`
}

export function SegmentedProgress({ label, value, cells = 24, trailing, className = '' }: SegmentedProgressProps) {
  const total = Math.max(1, Math.round(Number.isFinite(cells) ? cells : 24))
  const filled = Math.min(Math.max(Math.round(Number.isFinite(value) ? value : 0), 0), total)
  // The value before the last change decides which cells animate and in what order (stored in state, so render stays pure).
  const [seen, setSeen] = useState(filled)
  const [from, setFrom] = useState(filled)
  if (seen !== filled) {
    setFrom(seen)
    setSeen(filled)
  }
  return (
    <div data-part="root" className={`flex items-center gap-3.5 ${className}`}>
      <div
        role="progressbar"
        aria-label={label}
        aria-valuemin={0}
        aria-valuemax={total}
        aria-valuenow={filled}
        data-part="track"
        className="flex h-[26px] min-w-0 flex-1 gap-0.5 rounded-[10px] bg-sunken p-[3px]"
      >
        {Array.from({ length: total }, (_, i) => {
          const on = i < filled
          // Filling runs left to right from the first new cell; emptying runs right to left from the last one.
          const step = filled >= from ? i - from : from - 1 - i
          return (
            <i
              key={i}
              data-part="cell"
              className="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]"
            >
              <span
                data-part="fill"
                data-on={on ? '' : undefined}
                style={{ backgroundColor: ramp(i, total), '--step': Math.min(Math.max(step, 0), 20) } as CSSProperties}
                className={`absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&]:[transition-delay:0s] ${on ? 'scale-100 opacity-100' : 'scale-50 opacity-0'}`}
              />
            </i>
          )
        })}
      </div>
      {trailing != null && <span data-part="trailing" className="shrink-0 text-body font-[500] whitespace-nowrap text-fg">{trailing}</span>}
    </div>
  )
}
```

## HTML

The default example as plain HTML, for any stack. Needs nacre-theme.css.

```html
<div data-part="root" class="flex items-center gap-3.5 ">
  <div role="progressbar" aria-label="Checkout flow audit" aria-valuemin="0" aria-valuemax="24" aria-valuenow="19" data-part="track" class="flex h-[26px] min-w-0 flex-1 gap-0.5 rounded-[10px] bg-sunken p-[3px]">
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 55%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 50%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 45%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 41%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 36%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 31%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 26%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 22%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 17%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 12%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 7%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 0%, color-mix(in oklab, white 2%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 1%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 4%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 7%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 10%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 13%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 15%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" data-on="" style="background-color:color-mix(in oklab, black 18%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-100 opacity-100"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" style="background-color:color-mix(in oklab, black 21%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:0" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-50 opacity-0"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" style="background-color:color-mix(in oklab, black 24%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:1" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-50 opacity-0"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" style="background-color:color-mix(in oklab, black 26%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:2" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-50 opacity-0"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" style="background-color:color-mix(in oklab, black 29%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:3" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-50 opacity-0"></span>
    </i>
    <i data-part="cell" class="relative flex-1 rounded-[4px] bg-[color-mix(in_oklab,var(--nx-fg)_8%,var(--nx-sunken))]">
      <span data-part="fill" style="background-color:color-mix(in oklab, black 32%, color-mix(in oklab, white 0%, var(--nx-accent)));--step:4" class="absolute inset-0 rounded-[inherit] motion-safe:transition-[opacity,scale] motion-safe:duration-(--nx-dur-quick) motion-safe:ease-out motion-safe:[transition-delay:calc(var(--step)*14ms)] [[data-nacre-motion=off]_&amp;]:[transition-delay:0s] scale-50 opacity-0"></span>
    </i>
  </div>
  <span data-part="trailing" class="shrink-0 text-body font-[500] whitespace-nowrap text-fg">5 left</span>
</div>
```

## Related

- [Progress and steps](https://enxm.me/services/design-systems/nacre/components/progress)
- [Panel](https://enxm.me/services/design-systems/nacre/components/panel)
