# Progress

Shows how far a task that takes a while has got, such as an upload. It renders a div with role="progressbar" and the value in aria-valuenow, aria-valuetext and the CSS custom property --progress, and draws nothing: size the indicator with --progress. A value of null is indeterminate, for a task whose progress is unknown. The role requires a name: give it aria-label, or aria-labelledby naming an element. When it shows a region loading, set aria-busy="true" on that region until it has loaded, and point the region's aria-describedby at the progress bar.

- Entry point: `menhir/progress`
- Size: 1.2 kB, minified and gzipped, Solid left out

> To add Progress to a project, install the packages below with the project's package manager, then copy the example that matches how the project is styled, Tailwind CSS or plain CSS, and adapt its markup and class names to the project.

## Install

```sh
pnpm add menhir solid-js @solidjs/web
```

## Anatomy

```tsx
<Progress.Root>
  <Progress.Value />
  <Progress.Indicator />
</Progress.Root>
```

## Example

### Tailwind CSS

`ProgressExample.tsx`:

```tsx
import { Progress } from "menhir/progress";

export default function ProgressExample() {
  return (
    <Progress.Root
      value={60}
      aria-labelledby="progress-label"
      class="grid w-64 grid-cols-[1fr_auto] gap-2 text-sm"
    >
      <span id="progress-label">Uploading</span>
      <Progress.Value />
      <div class="col-span-2 h-2 overflow-hidden rounded-full bg-stone-200 dark:bg-stone-800">
        <Progress.Indicator class="h-full w-(--progress) bg-stone-800 dark:bg-stone-300" />
      </div>
    </Progress.Root>
  );
}
```

### CSS

`ProgressExample.tsx`:

```tsx
import { Progress } from "menhir/progress";

import "./progress.css";

export default function ProgressExample() {
  return (
    <Progress.Root value={60} aria-labelledby="progress-label" class="progress">
      <span id="progress-label">Uploading</span>
      <Progress.Value />
      <div class="progress-track">
        <Progress.Indicator class="progress-indicator" />
      </div>
    </Progress.Root>
  );
}
```

`progress.css`:

```css
/* The least CSS that makes the Progress visible: a track, and an indicator
   as wide as --progress, which the Root sets. Everything else is the
   browser's. Colours are Tailwind's stone palette; light-dark() picks the
   second one in dark mode (color-scheme: dark). */
.progress {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  width: 16rem;
  font:
    0.875rem system-ui,
    sans-serif;
}

.progress-track {
  grid-column: 1 / -1;
  height: 0.5rem;
  border-radius: 9999px;
  overflow: hidden;
  background: light-dark(
    oklch(92.3% 0.003 48.717) /* stone-200 */,
    oklch(26.8% 0.007 34.298) /* stone-800 */
  );
}

.progress-indicator {
  width: var(--progress);
  height: 100%;
  background: light-dark(
    oklch(26.8% 0.007 34.298) /* stone-800 */,
    oklch(86.9% 0.005 56.366) /* stone-300 */
  );
}
```

## API reference

### Root

<div role="progressbar">, with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext, and data-indeterminate, data-progressing or data-complete. Its style sets --progress, the percentage of the range, such as 25%, which every element inside it inherits.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number \| null` | — | How far the task has got, from min to max, or null while unknown. A value outside the range is clamped to it. |
| `min` | `number` | `0` | The value at the start of the task. |
| `max` | `number` | `100` | The value when the task is complete. |
| `format` | `Intl.NumberFormatOptions` | `{ style: "percent" }` | How aria-valuetext and Progress.Value format the value. The percent style formats the percentage of the range; any other style formats the value itself, such as { style: "unit", unit: "megabyte" } for "42 MB". For other text, such as "3 of 10 files", pass your own aria-valuetext. |
| `locale` | `Intl.LocalesArgument` | — | The language to format in, else the runtime's default. Pass it when rendering on the server, so that the server and the browser format alike. |
| `render` | `(props) => JSX.Element` | — | Renders the progress bar with your own component. Read once. |

### Indicator

<div> for the filled part of the bar, with the Root's data-* attributes. Give it a size from --progress, such as width: var(--progress), and its own while indeterminate, when --progress is unset.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `render` | `(props) => JSX.Element` | — | Renders the indicator with your own component. Read once. |

### Value

<span> with the value as text, the same as the Root's aria-valuetext, yours if you pass one, and the Root's data-* attributes. Empty while indeterminate, unless you pass aria-valuetext.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `render` | `(props) => JSX.Element` | — | Renders the value with your own component. Read once. |

## Keyboard

| Keys | Action |
| --- | --- |
| `Tab` | Moves past the progress bar, which is not focusable: the user cannot change its value. |
