# Progress and Meter

> Linear, circular and semicircle progress indicators and meters drawn with CSS and one inline SVG, with indeterminate, buffer, segments and stripes, rendered in Server Components with zero client JavaScript.

Canonical: https://salmonui.dev/docs/notifications/progress

```tsx
import { Meter, Progress } from '@salmonui/notifications/progress';
import '@salmonui/notifications/progress/styles.css';

<Progress aria-label="Upload" value={42} label />;
<Progress aria-label="Sync" shape="circular" value={null} />;
<Meter aria-label="Disk usage" value={85} tone={(v) => (v > 80 ? 'danger' : 'success')} />;
```

`Progress` (`role="progressbar"`) and `Meter` (`role="meter"`) are server
components with no client JavaScript. The value is written as inline custom
properties (`--salmon-progress-value`, `--salmon-progress-buffer`), so server
and client markup match and a value change is one style write: the owner's
render is the only React work.

### Live demo: Linear progress

Live demo: https://salmonui.dev/demos/notifications/progress-linear

Linear Progress bars driven by one slider, with a buffer, a value label and value text, range colors, indeterminate, striped and segmented bars, every tone, a custom range, a German percent label, a pointer event handler and right-to-left.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Progress, type ProgressTone } from '@salmonui/notifications/progress';
import { Slider } from '@salmonui/inputs/slider';

const TONES: ProgressTone[] = ['primary', 'neutral', 'info', 'success', 'warning', 'danger'];

// Range colors: the tone is a function of the value.
const byValue = (value: number | null): ProgressTone => (value == null ? 'primary' : value < 40 ? 'danger' : value < 80 ? 'warning' : 'success');

// Linear progress bars driven by one value: a labelled upload with a buffer,
// indeterminate, striped and segmented bars, every tone, a custom range and
// a German percent label, and a pointer handler on the root.
export default function ProgressLinearDemo() {
  const [value, setValue] = useState(35);
  const [indeterminate, setIndeterminate] = useState(false);
  const [rtl, setRtl] = useState(false);
  const [hovers, setHovers] = useState(0);
  return (
    <div dir={rtl ? 'rtl' : 'ltr'} style={{ display: 'grid', gap: 16, maxInlineSize: 480 }}>
      <div className="demo-toolbar">
        <span style={{ display: 'flex', alignItems: 'flex-end', gap: 12 }}>
          <Slider label="Value" min={0} max={100} value={value} onValueChange={setValue} style={{ inlineSize: 160 }} />
          <output style={{ minInlineSize: '3ch', lineHeight: '24px' }}>{value}</output>
        </span>
        <Checkbox checked={indeterminate} onCheckedChange={(checked) => setIndeterminate(checked)}>
          Indeterminate
        </Checkbox>
        <Checkbox checked={rtl} onCheckedChange={(checked) => setRtl(checked)}>
          Right to left
        </Checkbox>
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="progress-linear-upload">Upload (buffer, value label)</span>
        <Progress
          aria-labelledby="progress-linear-upload"
          value={indeterminate ? null : value}
          buffer={Math.min(100, value + 20)}
          label
          valueLabel={({ percent }) => (percent == null ? 'Waiting for the server' : `${Math.round(percent)} percent uploaded`)}
          tone={byValue}
          onPointerEnter={() => setHovers(hovers + 1)}
        />
        <output>Pointer entered the bar {hovers} times</output>
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="progress-linear-striped">Striped, 12px thick</span>
        <Progress aria-labelledby="progress-linear-striped" value={indeterminate ? null : value} striped thickness={12} />
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="progress-linear-segmented">Ten segments</span>
        <Progress aria-labelledby="progress-linear-segmented" value={indeterminate ? null : value} segments={10} size="lg" />
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="progress-linear-steps">Steps 3 to 12 (min 3, max 12)</span>
        <Progress aria-labelledby="progress-linear-steps" min={3} max={12} value={indeterminate ? null : 3 + (value / 100) * 9} label={({ value: v }) => (v == null ? '' : `Step ${Math.round(v)} of 12`)} />
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="progress-linear-german">German percent label</span>
        <Progress aria-labelledby="progress-linear-german" locale="de-DE" value={indeterminate ? null : value} label size="sm" />
      </div>
      <div style={{ display: 'grid', gap: 6 }}>
        <span>Every tone</span>
        {TONES.map((tone) => (
          <Progress key={tone} aria-label={`${tone} tone`} tone={tone} value={indeterminate ? null : value} size="sm" />
        ))}
      </div>
    </div>
  );
}
```

## Value and range

- `value`, `min` (default 0) and `max` (default 100); the value is clamped to
  the range.
- `value={null}` is indeterminate: `aria-valuenow` is omitted and the bar
  moves on the shared keyframes. Under `prefers-reduced-motion` the
  bar is a static partial fill.
- `buffer`: a lighter second layer on the same scale, for linear and circular
  shapes.

## Shapes

- `shape="linear"` (default): a track and a bar scaled with
  `transform: scaleX()` from the inline start, so right-to-left pages fill
  from the right.
- `shape="circular"` and `shape="semicircle"`: one inline SVG of `<circle>`
  elements drawn with `stroke-dasharray`, no chart engine.
  Other start and end angles, pointers and ranges belong to a
  [Gauge](https://salmonui.dev/docs/data-visualization/gauge): the progress indicator
  stays one fixed SVG so it renders on the server with no chart code.
- `size`: `'sm'`, `'md'` (default), `'lg'`, or a diameter in pixels for the
  round shapes; for `linear` the metric set picks the bar thickness. `thickness` sets the stroke or bar thickness in pixels for track,
  value and buffer together.
- `segments`: equal segments with a fixed gap, a CSS mask on the track or the
  SVG. `striped`: stripes on a linear bar.

### Live demo: Circular and semicircle progress

Live demo: https://salmonui.dev/demos/notifications/progress-circular

Circular Progress in three sizes and a pixel diameter with a custom thickness, a buffer, segments, an indeterminate spinner, centered labels and a custom center node, semicircle gauges and a Meter.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Meter, Progress } from '@salmonui/notifications/progress';
import { Slider } from '@salmonui/inputs/slider';

// Circular and semicircle progress: component sizes, a pixel diameter with a
// custom thickness, centered labels and nodes, a buffer, segments, and a Meter.
export default function ProgressCircularDemo() {
  const [value, setValue] = useState(62);
  const row = { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 24 } as const;
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <div className="demo-toolbar">
        <span style={{ display: 'flex', alignItems: 'flex-end', gap: 12 }}>
          <Slider label="Value" min={0} max={100} value={value} onValueChange={setValue} style={{ inlineSize: 160 }} />
          <output style={{ minInlineSize: '3ch', lineHeight: '24px' }}>{value}</output>
        </span>
      </div>
      <div style={row}>
        <Progress aria-label="Small" shape="circular" size="sm" value={value} />
        <Progress aria-label="Medium" shape="circular" value={value} label />
        <Progress aria-label="Large with buffer" shape="circular" size="lg" value={value} buffer={Math.min(100, value + 15)} label />
        <Progress aria-label="Syncing" shape="circular" value={null} />
        <Progress aria-label="Segmented" shape="circular" size="lg" segments={8} value={value} tone="info" />
      </div>
      <div style={row}>
        <Progress
          aria-label="Storage"
          shape="circular"
          size={120}
          thickness={14}
          value={value}
          tone="success"
          style={{ margin: 8 }}
          label={
            <span style={{ display: 'grid', textAlign: 'center', lineHeight: 1.1 }}>
              <strong>{value} GB</strong>
              <small>of 100</small>
            </span>
          }
        />
        <Progress aria-label="Battery" shape="semicircle" size={140} thickness={12} value={value} tone={value < 25 ? 'danger' : 'primary'} label={({ valueText }) => valueText} />
        <div style={{ display: 'grid', gap: 4, justifyItems: 'center' }}>
          <Meter aria-label="Disk usage" shape="semicircle" size={120} value={value} tone={(v) => ((v ?? 0) > 80 ? 'danger' : 'success')} label />
          <span>Disk usage</span>
        </div>
      </div>
    </div>
  );
}
```

## Color

`tone` is `'primary'` (default), `'neutral'`, `'info'`, `'success'`,
`'warning'` or `'danger'`, or a function of the value, so the color
can change by range: `tone={(value) => (value > 90 ? 'danger' : 'primary')}`.

Colors always come from the theme, which derives them from five semantic
seeds, so every progress bar matches the rest of the interface in
light, dark and forced-colors modes. There are no per-instance bar, track,
buffer or segment color props, gradients or corner radius
settings: pick a `tone`, or override `.salmon-progress-bar` /
`.salmon-progress-track` in your stylesheet. There is no pie fill:
use `shape="circular"` with a large `thickness`, or a
[pie chart](https://salmonui.dev/docs/data-visualization/pie-chart).

## Labels and value text

- `label`: `true` shows the formatted percentage; a node is shown as is; a
  function receives `{ value, percent, valueText }`. Round shapes
  center the label, so any node (an icon, a value and unit) can sit in the
  middle of the ring.
  Label typography and placement are fixed.
- `valueLabel` sets `aria-valuetext`, as a string or a function of the same
  context. The default is the locale percent
  (`locale`, default `'en-US'`).
- Label font, color and position are fixed by the stylesheet: style
  `.salmon-progress-label` instead.
- An accessible name is required by the props type: `aria-label` or
  `aria-labelledby`.

## Meter

`Meter` is for measured values within a known range (disk usage, a score):
`role="meter"`, the same shapes, CSS and props except `buffer`, `striped` and
indeterminate values.

## Events, class and style

`className`, `style` and every DOM prop, including `onClick` and the pointer
events (`onPointerDown`, …), reach the root element. `ref`
is the root `<div>`.

Not included, on purpose:

- Value-changed and completed events: the application sets
  `value`, so it already knows when the value changes or reaches `max`; run
  that code where you set the value.
- Animation settings (duration, delay, an animation-complete event): value changes use one CSS transition, off under
  `prefers-reduced-motion`. Per-instance timing would need JavaScript
  animation on the server-rendered component.
- An active moving sheen: use `value={null}` or `striped`.
- A built-in tooltip: wrap the progress in a
  [Tooltip](https://salmonui.dev/docs/layout/tooltip) or show `label`; a built-in tooltip would
  add client code to a component that has none.
- Persistence: there is no state to persist; the value is a prop.
- Load events and a teardown method: React's lifecycle replaces
  them; the component renders synchronously and has no load phase.

## SSR

`Progress` and `Meter` are server components: the subpath has no
`"use client"` directive, they use no hooks, and the server HTML is final
(no measurement, no hydration work).

API reference: [`@salmonui/notifications/progress`](https://salmonui.dev/docs/reference/notifications/progress).
