Progress
Display operation progress or proportions with linear, circular, and dashboard styles.
Import
import { HuiProgress } from '@nscode/handy-ui'
Basic usage
percentage is a percentage from 0 to 100. The default is a linear progress bar with its percentage displayed on the right. Values outside this range are clamped; for example, 120 is displayed as 100%.
<template>
<HuiSpace direction="vertical" fill>
<HuiProgress :percentage="0" />
<HuiProgress :percentage="50" />
<HuiProgress :percentage="100" />
<HuiProgress :percentage="120" />
</HuiSpace>
</template>
Types
type has three values:
line(default): a linear bar that fills its parent, with text on the right.circle: a complete ring that grows clockwise from the top, with text in the center.dashboard: a ring with a quarter-circle gap at the bottom that grows clockwise from the left edge of the gap.
<template>
<HuiSpace direction="vertical" fill>
<div class="row">
<span class="row-label">line</span>
<HuiProgress :percentage="75" />
</div>
<HuiSpace wrap size="large">
<div class="cell">
<HuiProgress type="circle" :percentage="75" />
<span class="row-label">circle</span>
</div>
<div class="cell">
<HuiProgress type="dashboard" :percentage="75" />
<span class="row-label">dashboard</span>
</div>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row {
display: flex;
align-items: center;
gap: var(--hui-spacing-3);
}
.cell {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--hui-spacing-2);
}
.row-label {
flex-shrink: 0;
width: 72px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.cell .row-label {
width: auto;
}
</style>
Status
Set status to success, warning, or exception to use the corresponding success, warning, or danger color for both the bar and its outside text (the centered text for circles and dashboards). Without a status, the primary color is used. All three types support status:
<template>
<HuiSpace direction="vertical" fill>
<div class="row">
<span class="row-label">Unset</span>
<HuiProgress :percentage="50" />
</div>
<div class="row">
<span class="row-label">success</span>
<HuiProgress :percentage="70" status="success" />
</div>
<div class="row">
<span class="row-label">warning</span>
<HuiProgress :percentage="50" status="warning" />
</div>
<div class="row">
<span class="row-label">exception</span>
<HuiProgress :percentage="30" status="exception" />
</div>
<HuiSpace wrap size="large">
<div class="cell">
<HuiProgress type="circle" :percentage="50" :width="100" />
<span class="row-label">Unset</span>
</div>
<div class="cell">
<HuiProgress type="circle" :percentage="70" :width="100" status="success" />
<span class="row-label">success</span>
</div>
<div class="cell">
<HuiProgress type="circle" :percentage="50" :width="100" status="warning" />
<span class="row-label">warning</span>
</div>
<div class="cell">
<HuiProgress type="circle" :percentage="30" :width="100" status="exception" />
<span class="row-label">exception</span>
</div>
</HuiSpace>
<HuiSpace wrap size="large">
<div class="cell">
<HuiProgress type="dashboard" :percentage="50" :width="100" />
<span class="row-label">Unset</span>
</div>
<div class="cell">
<HuiProgress type="dashboard" :percentage="70" :width="100" status="success" />
<span class="row-label">success</span>
</div>
<div class="cell">
<HuiProgress type="dashboard" :percentage="50" :width="100" status="warning" />
<span class="row-label">warning</span>
</div>
<div class="cell">
<HuiProgress type="dashboard" :percentage="30" :width="100" status="exception" />
<span class="row-label">exception</span>
</div>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row {
display: flex;
align-items: center;
gap: var(--hui-spacing-3);
}
.cell {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--hui-spacing-2);
}
.row-label {
flex-shrink: 0;
width: 72px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.cell .row-label {
width: auto;
}
</style>
Text placement
Linear progress bars support three text display modes:
- Outside (default): text appears to the right. Space for “100%” is reserved so stacked bars have equal lengths.
- Inside:
text-insideplaces text at the end of the completed segment, in white. Use a largerstroke-width(at least 16 is recommended) to leave enough room. Whenstatusis set, the text remains white and the bar uses the status color. - Hidden: set
show-texttofalse.
Circle and dashboard text stays in the center; text-inside has no effect on them. Set show-text to false to hide it.
<template>
<HuiSpace direction="vertical" fill>
<div class="row">
<span class="row-label">Outside (default)</span>
<HuiProgress :percentage="70" />
</div>
<div class="row">
<span class="row-label">Inside</span>
<HuiProgress :percentage="70" text-inside :stroke-width="20" />
</div>
<div class="row">
<span class="row-label">Inside + status</span>
<HuiProgress :percentage="70" text-inside :stroke-width="20" status="success" />
</div>
<div class="row">
<span class="row-label">Hidden</span>
<HuiProgress :percentage="70" :show-text="false" />
</div>
<HuiSpace wrap size="large">
<div class="cell">
<HuiProgress type="circle" :percentage="70" :width="100" />
<span class="row-label">Circle</span>
</div>
<div class="cell">
<HuiProgress type="circle" :percentage="70" :width="100" :show-text="false" />
<span class="row-label">Circle without text</span>
</div>
<div class="cell">
<HuiProgress type="dashboard" :percentage="70" :width="100" :show-text="false" />
<span class="row-label">Dashboard without text</span>
</div>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row {
display: flex;
align-items: center;
gap: var(--hui-spacing-3);
}
.cell {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--hui-spacing-2);
}
.row-label {
flex-shrink: 0;
width: 88px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.cell .row-label {
width: auto;
}
</style>
Stroke width and size
For linear bars, stroke-width is the bar height. For circles and dashboards, it is the ring's stroke width. The default is 6px. width sets both the canvas width and height for circles and dashboards, defaults to 126px, and has no effect on linear bars.
<template>
<HuiSpace direction="vertical" fill>
<div class="row">
<span class="row-label">4px</span>
<HuiProgress :percentage="60" :stroke-width="4" />
</div>
<div class="row">
<span class="row-label">6px (default)</span>
<HuiProgress :percentage="60" />
</div>
<div class="row">
<span class="row-label">10px</span>
<HuiProgress :percentage="60" :stroke-width="10" />
</div>
<div class="row">
<span class="row-label">16px</span>
<HuiProgress :percentage="60" :stroke-width="16" />
</div>
<HuiSpace wrap size="large" align="end">
<HuiProgress type="circle" :percentage="60" :width="80" :stroke-width="4" />
<HuiProgress type="circle" :percentage="60" />
<HuiProgress type="circle" :percentage="60" :width="180" :stroke-width="12" />
<HuiProgress type="dashboard" :percentage="60" :width="180" :stroke-width="16" />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row {
display: flex;
align-items: center;
gap: var(--hui-spacing-3);
}
.row-label {
flex-shrink: 0;
width: 72px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Custom colors
color accepts three forms:
- A string: a fixed color.
- A function
(percentage) => string: returns a color for the current percentage. - An array of colors: interpolates between adjacent colors by percentage. With two colors, for example, 0% uses the first, 100% uses the second, and 50% uses their midpoint. Only 6-digit and 3-digit hex colors support interpolation. For other formats (
'red', CSS variables), one of the adjacent colors is selected by position. A single color is used directly; an empty array falls back to the primary color.
When status is set, its color takes precedence over color.
<script setup lang="ts">
const color = (percentage: number) => {
if (percentage < 30) return 'var(--hui-color-danger)'
if (percentage < 70) return 'var(--hui-color-warning)'
return 'var(--hui-color-success)'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiProgress :percentage="60" color="#ff6b6b" />
<HuiProgress :percentage="50" :color="color" />
<HuiProgress :percentage="80" :color="['#ff6b6b', '#4ecdc4']" />
</HuiSpace>
</template>
The same applies to circles and dashboards:
<script setup lang="ts">
const color = (percentage: number) => {
if (percentage < 30) return 'var(--hui-color-danger)'
if (percentage < 70) return 'var(--hui-color-warning)'
return 'var(--hui-color-success)'
}
</script>
<template>
<HuiSpace wrap size="large">
<HuiProgress type="circle" :percentage="60" color="#ff6b6b" />
<HuiProgress type="circle" :percentage="20" :color="color" />
<HuiProgress type="dashboard" :percentage="80" :color="['#ff6b6b', '#ffd166', '#4ecdc4']" />
</HuiSpace>
</template>
Custom text
format receives the current percentage, clamped to 0–100, and returns the text to display. Text is hidden when showText is false.
<script setup lang="ts">
const format = (percentage: number) => (percentage === 100 ? 'Complete' : `${percentage} points`)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiProgress :percentage="60" :format="format" />
<HuiProgress :percentage="40" :show-text="false" />
<HuiSpace wrap size="large">
<HuiProgress type="circle" :percentage="100" status="success" :format="format" />
<HuiProgress type="dashboard" :percentage="85" :format="format" />
</HuiSpace>
</HuiSpace>
</template>
Dynamic progress
Use the buttons to increase or decrease progress. Changes to bar width and arc length have a 0.3-second transition. This example sets status to success at 100%, and the dashboard uses a color array to interpolate from red to green.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiButton, HuiButtonGroup, HuiProgress, HuiSpace } from '@nscode/handy-ui'
import type { ProgressStatus } from '@nscode/handy-ui'
const percentage = ref(20)
const status = computed<ProgressStatus | undefined>(() =>
percentage.value === 100 ? 'success' : undefined
)
const decrease = () => {
percentage.value = Math.max(0, percentage.value - 10)
}
const increase = () => {
percentage.value = Math.min(100, percentage.value + 10)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiProgress :percentage="percentage" :status="status" />
<HuiSpace wrap size="large">
<HuiProgress type="circle" :percentage="percentage" :status="status" />
<HuiProgress type="dashboard" :percentage="percentage" :color="['#ff6b6b', '#4ecdc4']" />
</HuiSpace>
<div>
<HuiButtonGroup>
<HuiButton icon="minus" :disabled="percentage <= 0" @click="decrease"
>Decrease by 10%</HuiButton
>
<HuiButton icon="plus" :disabled="percentage >= 100" @click="increase"
>Increase by 10%</HuiButton
>
</HuiButtonGroup>
</div>
</HuiSpace>
</template>
Segmented Progress and Legends
For a linear progress bar, segments supplies percentage values and takes precedence over percentage, color, and status. Segment colors default to the theme's primary, success, warning, danger, and help colors in sequence; a segment's own color overrides that default. A label on any segment enables the default legend.
The total is capped sequentially at 100: values 80, 60, and 5 become 80, 20, and 0, with a development warning. Negative and nonfinite values become zero. Zero segments have no width but remain in the default legend. An empty array stays in segmented mode and displays zero.
format receives the effective total. textInside places text at the end of the used area; showText=false hides the total text without hiding the legend. The legend slot receives normalized segment copies and the total without mutating the input. Providing the slot displays its area even when no segment has a label.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiButton, HuiProgress, HuiSpace } from '@nscode/handy-ui'
import type { ProgressSegment } from '@nscode/handy-ui'
const overflow = ref(false)
const inside = ref(false)
const showText = ref(true)
const segments = computed<ProgressSegment[]>(() => [
{ value: 80, label: 'Complete' },
{ value: overflow.value ? 60 : 15, label: 'Failed', color: 'var(--hui-color-danger)' },
{ value: 5, label: 'Processing' }
])
const capacity = 200
const usage = [
{ label: 'Documents', amount: 60 },
{ label: 'Images', amount: 84 }
]
const storage = usage.map((item) => ({
label: item.label,
value: (item.amount / capacity) * 100
}))
const used = usage.reduce((sum, item) => sum + item.amount, 0)
const storageFormat = (total: number) => `${(total / 100) * capacity}GB / ${capacity}GB`
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace wrap>
<HuiButton @click="overflow = !overflow">Overflow: {{ overflow }}</HuiButton>
<HuiButton @click="inside = !inside">Inside text: {{ inside }}</HuiButton>
<HuiButton @click="showText = !showText">Show total: {{ showText }}</HuiButton>
</HuiSpace>
<HuiProgress
:segments="segments"
:text-inside="inside"
:stroke-width="inside ? 24 : 8"
:show-text="showText"
aria-label="Batch tasks"
/>
<HuiProgress
:segments="[
{ value: -5, label: 'Negative' },
{ value: NaN, label: 'Not finite' },
{ value: 35, label: 'Valid' }
]"
aria-label="Invalid input values"
/>
<HuiProgress :segments="[]" :percentage="60" aria-label="Empty segmented progress" />
<HuiProgress :segments="[{ value: 30 }, { value: 20 }]" aria-label="Budget usage">
<template #legend="{ segments: effective, total }">
<HuiSpace wrap>
<span v-for="(item, index) in effective" :key="index" :style="{ color: item.color }"
>{{ item.value }}%</span
>
<strong>Remaining: {{ 100 - total }}%</strong>
</HuiSpace>
</template>
</HuiProgress>
<HuiProgress
:segments="storage"
:format="storageFormat"
aria-label="Storage usage"
:aria-valuetext="`${used}GB used out of ${capacity}GB`"
/>
</HuiSpace>
</template>
Convert absolute amounts into percentages in application code. Use format for visible absolute totals and aria-valuetext when assistive technology should announce those amounts.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| percentage | number | 0 | Percentage; values outside 0–100 are clamped |
| type | 'line' | 'circle' | 'dashboard' | 'line' | Progress type |
| status | 'success' | 'warning' | 'exception' | - | Status; its semantic color takes precedence over color |
| strokeWidth | number | 6 | Bar height for linear progress; ring stroke width for circles and dashboards (px) |
| textInside | boolean | false | Display text inside the bar; only applies to linear progress |
| color | string | string[] | ((percentage: number) => string) | - | Progress color; an array interpolates between colors by percentage. See “Custom colors” |
| width | number | 126 | Canvas width for circles and dashboards (px) |
| showText | boolean | true | Whether to display text |
| format | (percentage: number) => string | - | Custom text formatter; receives the percentage clamped to 0–100 |
| segments | ProgressSegment[] | - | Linear segmented mode, including an empty array. Ignores percentage/color/status and caps the total sequentially at 100. |
Slots
| Slot | Scope | Description |
|---|---|---|
| legend | { segments: ProgressSegment[], total: number } | Normalized segment copies and the effective total; overrides the default legend. |
Types
import type {
ProgressProps,
ProgressType,
ProgressStatus,
ProgressColor,
ProgressSegment,
ProgressSlots
} from '@nscode/handy-ui'
type ProgressType = 'line' | 'circle' | 'dashboard'
type ProgressStatus = 'success' | 'warning' | 'exception'
type ProgressColorFn = (percentage: number) => string
type ProgressColor = string | string[] | ProgressColorFn
interface ProgressSegment {
value: number
color?: string
label?: string
}
interface ProgressSlots {
legend?: (props: { segments: ProgressSegment[]; total: number }) => unknown
}
interface ProgressProps {
percentage?: number
segments?: ProgressSegment[]
type?: ProgressType
status?: ProgressStatus
strokeWidth?: number
textInside?: boolean
color?: ProgressColor
width?: number
showText?: boolean
format?: (percentage: number) => string
}