# Progress Button

> The progress button as Button props - a loading spinner that keeps focus and a progress fill driven by the application's real progress.

Canonical: https://salmonui.dev/docs/buttons/progress-button

A progress button is a `Button` with `loading` and `progress`; every other
Button member applies unchanged.

## Loading

`loading` shows a spinner, sets `aria-busy="true"` and `aria-disabled="true"`
and ignores activation, but keeps the button focusable so keyboard users do not
lose their place. `loadingLabel` (default `"Loading"`) is appended
to the accessible name as visually hidden text. The spinner takes the
`iconStart` slot (centered on an icon-only button) and scales with `size`;
`spinner` replaces the graphic.

## Progress

`progress={n}` (0 to 100) draws a fill from inline-start, sets `data-progress`
and one inline custom property, and appends `progressLabel(n)` (default
`"n%"`) to the name as hidden text. A button's children are
presentational, so there is no `progressbar` role inside it. `progress`
without `loading` shows only the fill, with no spinner.
Changing `children` or any style prop during progress is an ordinary
re-render.

### Live demo: Loading and progress

Live demo: https://salmonui.dev/demos/buttons/progress-button

A button that shows the progress the application reports, a loading button that keeps focus, a custom progress label and a custom spinner.

`Demo.tsx`:

```tsx
'use client';

import { useEffect, useRef, useState } from 'react';
import { Button } from '@salmonui/buttons/button';

// A custom spinner: a quarter arc that turns (the system spinner is a full ring).
const RingSpinner = () => (
  <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
    <path d="M8 2a6 6 0 0 1 6 6">
      <animateTransform attributeName="transform" type="rotate" from="0 8 8" to="360 8 8" dur="0.9s" repeatCount="indefinite" />
    </path>
  </svg>
);

// The application owns the work: here a stand-in upload reports its progress
// in steps; `progress` and `loading` render whatever it reports.
export default function ProgressButtonDemo() {
  const [percent, setPercent] = useState<number | null>(null);
  const [saving, setSaving] = useState(false);
  const timer = useRef<ReturnType<typeof setInterval> | undefined>(undefined);
  useEffect(() => () => clearInterval(timer.current), []);
  const upload = () => {
    setPercent(0);
    timer.current = setInterval(() => {
      setPercent((p) => {
        const next = (p ?? 0) + 10;
        if (next >= 100) clearInterval(timer.current);
        return next >= 100 ? null : next;
      });
    }, 200);
  };
  const save = () => {
    setSaving(true);
    setTimeout(() => setSaving(false), 1500);
  };
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 8 }}>
      <Button tone="primary" variant="outline" progress={percent ?? undefined} loading={percent !== null} loadingLabel="Uploading" onClick={upload}>
        {percent === null ? 'Upload' : 'Uploading'}
      </Button>
      <Button tone="success" loading={saving} loadingLabel="Saving" onClick={save}>
        Save
      </Button>
      <Button variant="outline" progress={65} progressLabel={(value) => `${value} percent of the quota used`}>
        Quota
      </Button>
      <Button loading spinner={<RingSpinner />}>
        Custom spinner
      </Button>
    </div>
  );
}
```

## Design notes

- No timed, simulated progress: there is no duration, no start / stop
  methods and no progress lifecycle events. The application's own async code
  sets `loading` and `progress` from its real work. Enter and Space are plain activation; there is no
  built-in progress for Escape to stop.
- The spinner's position and width are fixed by the button metrics;
content animations are not offered.
- The fill always runs along the inline axis; vertical and top-edge fills
  are not offered.
