# Progress Bar

## Usage

`ProgressBar` shows the completion ratio of an operation.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
</script>

<template>
  <ProgressBar :value="60" label="Upload" show-value />
</template>
```

### Anatomy

- **Progress bar**: Container arranging the label row and progress track.
- **Label**: Text naming the operation, optionally hidden visually while remaining accessible.
- **Value text**: Formatted determinate value shown beside the label when requested.
- **Track**: Remaining-progress rail that carries the progressbar semantics.
- **Fill**: Painted segment showing completed progress or indeterminate movement.
- **Mark**: Labeled target tick positioned on a determinate track.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Choose a color variant that matches the context: accent for general progress, success for completion, warning or error for alerts. |
| Don't | Place icons or labels inside the bar; compose them alongside it using layout components. |
| Don't | Use multiple progress bars stacked together for the same operation; use one bar with a value label instead. |

## Examples

### Custom format

formatValueLabel turns the current value and max into a label such as disk usage in GB.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <div style="width: 300px">
    <VStack :gap="1">
      <ProgressBar
        :value="3.2"
        :max="5"
        label="Disk usage"
        has-value-label
        :format-value-label="(value, max) => `${value} GB / ${max} GB`"
      />
      <Text type="supporting" color="secondary">
        1.8 GB remaining
      </Text>
    </VStack>
  </div>
</template>
```

### Indeterminate

isIndeterminate is for work whose duration is unknown.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
</script>

<template>
  <ProgressBar is-indeterminate label="Loading..." style="width: 300px" />
</template>
```

### Semantic variants

Accent, success, warning, error, and neutral, stacked so the status colors can be compared.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
import { VStack } from '@astryx-vue/core/Stack'
</script>

<template>
  <VStack :gap="4" width="100%" style="max-width: 300px">
    <ProgressBar :value="60" label="Accent" variant="accent" has-value-label />
    <ProgressBar :value="80" label="Positive" variant="success" has-value-label />
    <ProgressBar :value="50" label="Warning" variant="warning" has-value-label />
    <ProgressBar :value="92" label="Negative" variant="error" has-value-label />
    <ProgressBar :value="35" label="Neutral" variant="neutral" has-value-label />
  </VStack>
</template>
```

### Value label

hasValueLabel shows the current percentage beside the label.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
</script>

<template>
  <ProgressBar :value="75" label="Storage used" has-value-label style="width: 300px" />
</template>
```

### Marks

Marks use the same scale as the bar. A mark on the fill uses the fill foreground; a mark still on the track uses the text color. Hover or focus reads its name.

```vue
<script setup lang="ts">
import { ProgressBar } from '@astryx-vue/core/ProgressBar'
</script>

<template>
  <ProgressBar
    :value="62"
    label="Upload"
    style="width: 320px"
    :marks="[
      { value: 25, label: 'Started' },
      { value: 90, label: 'Almost done' },
    ]"
  />
</template>
```

## Accessibility

A progress bar has no focusable element, so screen reader users rely on the ARIA attributes the component exposes to learn the current progress. The component therefore puts `role="progressbar"` on the track and fills in the progress values and name, so assistive technologies can announce it accurately:

- The progress range is described by `aria-valuemin` and `aria-valuemax`, which the component sets automatically from `min` and `max`.
- The current progress is described by `aria-valuenow`, which is also set automatically.
- When `label` is provided, the label is linked to the track through `aria-labelledby`.
- When `description` is provided, the description is linked to the track through `aria-describedby`.

When `isIndeterminate` is true the progress is unknown, so the component removes `aria-valuenow` and screen readers announce the bar without a specific value.

## ProgressBar Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` | — | Required. Current value. |
| `min` | `number` | `0` | Minimum value. |
| `max` | `number` | `100` | Maximum value. |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Track height. |
| `variant` | `'accent' \| 'neutral' \| 'success' \| 'warning' \| 'error' \| 'info'` | `'accent'` | Fill color. |
| `label` | `string` | — | Progress bar label. Used as the accessible name. |
| `description` | `string` | — | Supplementary description. |
| `isIndeterminate` | `boolean` | `false` | Indeterminate state. Shows a looping animation and omits aria-valuenow, aria-valuemin, aria-valuemax, and aria-valuetext. |
| `isDisabled` | `boolean` | `false` | Disabled look: the fill, label, value and marks all drop to the muted colors. Use it for canceled or inactive work. |
| `showValue` | `boolean` | `false` | Show the percentage next to the label. |
| `valueText` | `string` | — | Custom aria-valuetext and display text. Overrides the default percentage. |
| `marks` | `{ value: number, label: string }[]` | — | Target ticks on the track. Hidden while indeterminate. `label` is the accessible name and the hover or focus tooltip. |
| `width` | `number \| string` | — | Component width. Numbers are treated as px. |

## Theme

```css
.my-progress-bar {
  --astryx-progress-bar-track-background: #e5e5e5;
  --astryx-progress-bar-fill-background: #171717;
}
```

- `--astryx-progress-bar-track-background`: track background.
- `--astryx-progress-bar-fill-background`: default fill color.
- `--astryx-progress-bar-track-height`: default track height.
- `--astryx-progress-bar-track-height-sm`: sm track height.
- `--astryx-progress-bar-track-height-lg`: lg track height.
