# Progress bar

A linear indicator of how far a task or quantity has progressed: an upload, a multi-step setup, a quota. Without a value it shows indeterminate activity.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-progress-bar`
- Source: [libs/ui/src/lib/atoms/progress-bar/progress-bar.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/progress-bar/progress-bar.ts)

```typescript title="Import"
import { ProgressBar } from '@vigdx/ui/progress-bar';
```

## Basic

`value` is a percentage from 0 to 100 (clamped and rounded). `showValue` prints it next to the bar; `ariaLabel` names the bar for screen readers.

```typescript title="progress-bar-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-2">
      <span class="text-sm font-medium text-foreground">Storage used</span>
      <vig-progress-bar [value]="68" [showValue]="true" ariaLabel="Storage used" />
      <span class="text-xs text-muted-foreground">6.8 GB of 10 GB</span>
    </div>
  `,
})
export class ProgressBarBasicDemo {}
```

## Variants

`variant` colors the fill with the shared hues, e.g. `success` once a task is done or `warning` and `error` for a nearly full quota.

```typescript title="progress-bar-variants.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-variants',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-4">
      <vig-progress-bar [value]="40" ariaLabel="Primary" />
      <vig-progress-bar [value]="55" variant="info" ariaLabel="Info" />
      <vig-progress-bar [value]="100" variant="success" ariaLabel="Success" />
      <vig-progress-bar [value]="85" variant="warning" ariaLabel="Warning" />
      <vig-progress-bar [value]="97" variant="error" ariaLabel="Error" />
      <vig-progress-bar [value]="30" variant="secondary" ariaLabel="Secondary" />
    </div>
  `,
})
export class ProgressBarVariantsDemo {}
```

## Sizes

`size` sets the track height to `sm`, `md` (default) or `lg`, relative to the font size. The bar fills the width of its container.

```typescript title="progress-bar-sizes.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-sizes',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-4">
      <vig-progress-bar [value]="60" size="sm" ariaLabel="Small" />
      <vig-progress-bar [value]="60" size="md" ariaLabel="Medium" />
      <vig-progress-bar [value]="60" size="lg" ariaLabel="Large" />
    </div>
  `,
})
export class ProgressBarSizesDemo {}
```

## Indeterminate

Leave `value` at `null` when the remaining work is unknown: a segment sweeps along the track, or the bar stays static with reduced motion.

```typescript title="progress-bar-indeterminate.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-indeterminate',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-2">
      <span class="text-sm text-foreground">Preparing your export…</span>
      <vig-progress-bar ariaLabel="Preparing export" size="sm" />
    </div>
  `,
})
export class ProgressBarIndeterminateDemo {}
```

## Live progress

Bind `value` to a signal and the fill animates between updates. Switching the variant on completion confirms the result.

```typescript title="progress-bar-upload.ts"
import { ChangeDetectionStrategy, Component, DestroyRef, inject, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-upload',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-3">
      <div class="flex items-center justify-between text-sm text-foreground">
        <span>annual-report-2026.pdf</span>
        <vig-button
          [label]="progress() === null ? 'Upload' : 'Upload again'"
          size="sm"
          variant="secondary"
          [disabled]="running()"
          (click)="start()"
        />
      </div>
      <vig-progress-bar
        [value]="progress() ?? 0"
        [variant]="progress() === 100 ? 'success' : 'primary'"
        [showValue]="true"
        ariaLabel="Uploading annual-report-2026.pdf"
      />
    </div>
  `,
})
export class ProgressBarUploadDemo {
  protected readonly progress = signal<number | null>(null);
  protected readonly running = signal(false);
  private timer?: ReturnType<typeof setInterval>;

  constructor() {
    inject(DestroyRef).onDestroy(() => clearInterval(this.timer));
  }

  protected start(): void {
    this.progress.set(0);
    this.running.set(true);
    this.timer = setInterval(() => {
      const next = Math.min(100, (this.progress() ?? 0) + 7);
      this.progress.set(next);
      if (next === 100) {
        clearInterval(this.timer);
        this.running.set(false);
      }
    }, 200);
  }
}
```

## Labels

`ariaLabel` and `valueTemplate` (`{0}` is the rounded value) are inputs for translations; the template also feeds `aria-valuetext`. App-wide defaults come from the `progressAriaLabel` and `progressValueTemplate` labels.

```typescript title="progress-bar-labels.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ProgressBar } from '@vigdx/ui/progress-bar';

@Component({
  selector: 'app-progress-bar-labels',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ProgressBar],
  template: `
    <div class="flex max-w-md flex-col gap-4">
      <vig-progress-bar
        [value]="45"
        [showValue]="true"
        ariaLabel="Profil vervollständigt"
        valueTemplate="{0} %"
      />
      <vig-progress-bar
        [value]="80"
        [showValue]="true"
        variant="info"
        ariaLabel="Course progress"
        valueTemplate="{0}% complete"
      />
    </div>
  `,
})
export class ProgressBarLabelsDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="progress-bar"][data-part="track"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="progress-bar"]`

| Part | Element | data-state |
| --- | --- | --- |
| `track` | The native `<progress>`; the fill is its pseudo-element. |   |
| `value` | The percentage text (`showValue`). |   |

## Accessibility

- Renders a native `<progress max="100">`, which the platform exposes as a progress bar with its value, plus a formatted `aria-valuetext`; indeterminate bars omit the value.
- Always give each bar a specific `ariaLabel`, or point at a visible heading with `ariaLabelledby` (`ariaDescribedby` adds a description); the generic default (“Progress”) does not tell users what is progressing.
- Screen readers do not announce every value change. For long tasks, also announce milestones or completion in a live region such as a toast.
- The fill animation and the indeterminate sweep respect `prefers-reduced-motion`: the sweep slows down rather than stopping, so the bar still reads as busy.

## API

### ProgressBar

Selector: `vig-progress-bar` · Kind: component

Linear progress indicator: a native `<progress>`, so the progressbar role and value come from the platform. A `value` of 0–100 renders a determinate bar; `null` renders an indeterminate sweep (slowed down, never stopped, with reduced motion, so it still reads as busy).

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaDescribedby` | `string \| undefined` | `undefined` | Ids of elements describing the bar. A static `aria-describedby` on the host works too. |
| `ariaLabel` | `string \| undefined` | `undefined` | Accessible name; defaults to the `progressAriaLabel` label. |
| `ariaLabelledby` | `string \| undefined` | `undefined` | Ids of elements naming the bar, e.g. a visible heading; wins over `ariaLabel`. A static `aria-labelledby` on the host works too. |
| `showValue` | `boolean` | `false` | Renders the formatted percentage next to the bar (determinate only). |
| `size` | `ProgressBarSize` | `'md'` | — |
| `value` | `number \| null` | `null` | Percentage complete (0–100, clamped); `null` shows an indeterminate bar. |
| `valueTemplate` | `string \| ((value: number) => string) \| undefined` | `undefined` | Percentage text: a function of the rounded value, e.g. `(n) => n + ' percent'`, or a string where `{0}` is replaced with it. Defaults to `progressValueTemplate`. |
| `variant` | `ProgressBarVariant` | `'primary'` | — |
