Skip to content
Nacre
Color palette
中文

Progress

experimentalProgress · RatioBarOpen in playground
Progress
Runs the real component in your browser.

Progress shows task completion. Use RatioBar for read-only shares such as remaining credit or the distribution of ratings.

Status: experimental · Components: Progress, RatioBar

import { Progress, RatioBar } from 'nacre'

value / max give the progress (max is 100 by default), and label says what is happening; it fills its parent’s width. Put the specifics (“Item 3 of 8”) in a line of text above it.

import { Text, View, signal } from 'nsh'
import { Button, Progress, TEXT_SIZE } from 'nacre'
export function ProgressUsage() {
const done = signal(3)
const total = 8
return (
<View class="w-[280px] max-w-full gap-2">
<Text testID="progress-usage-text" class={`${TEXT_SIZE.small} text-foreground tabular-nums`}>
{'Checking item {n} of {total}'
.replace('{n}', String(Math.min(done() + 1, total)))
.replace('{total}', String(total))}
</Text>
<Progress testID="progress-usage" value={done()} max={total} label="Environment self-check" />
<View class="flex-row gap-2">
<Button testID="progress-usage-next" size="xs" onPress={() => done.update((n) => Math.min(n + 1, total))}>
Next item
</Button>
<Button size="xs" variant="ghost" onPress={() => done.set(0)}>
Restart
</Button>
</View>
</View>
)
}

Like HTML meter (https://developer.mozilla.org/docs/Web/HTML/Element/meter), this shows a bounded quantity, not task completion. NSH exposes the name and percentage as static text; there are no adjustment keys. Callers choose thresholds, tones and visible labels.

import { Text, View } from 'nsh'
import { RatioBar, TEXT_SIZE } from 'nacre'
export function RatioReading() {
const label = 'Remaining credit'
return (
<View class="w-[200px] gap-2">
<Text class={`${TEXT_SIZE.small} text-foreground`}>{`${label} 25%`}</Text>
<RatioBar testID="ratio-reading" label={label} size="sm" tone="warning" ratio={0.25} />
</View>
)
}

sm, 2pt (the default), goes under a line of text in dialogs and cards; md, 4pt, is for a standalone upload or export.

Phone: On phones sm is 4 pt (default) and md 6 pt, like the iOS progress view, with a darker track that stays visible outdoors.

import { View } from 'nsh'
import { Progress } from 'nacre'
export function ProgressSizes() {
return (
<View class="w-[280px] max-w-full gap-4">
<Progress value={40} label="Import" />
<Progress testID="progress-md" size="md" value={72} label="Uploading attachment" />
</View>
)
}

indeterminate: when the total is unknown (waiting on the server, in a queue), the whole bar breathes slowly without showing a specific amount; it stays still with reduced motion. Don’t use it when the total is known.

import { Text, View } from 'nsh'
import { Progress, TEXT_SIZE } from 'nacre'
export function ProgressIndeterminate() {
return (
<View class="w-[280px] max-w-full gap-2">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>Queued, waiting for the server…</Text>
<Progress testID="progress-indeterminate" indeterminate value={0} label="Exporting chat records" />
</View>
)
}
  • role=“progressbar”, reading label and the percentage; when indeterminate it reads “busy” and no value.
  • Progress changes transition over 150ms; with reduced motion it jumps into place, and the indeterminate bar does not breathe.

Do

  • Tasks that take more than a few seconds and have countable steps (self-check, bulk export)
  • Say which item it is on in text next to it
  • Make label say what is happening (“Environment self-check”)

Don’t

  • Requests that finish in a second or two (use a button’s loading)
  • First-load placeholders (use Skeleton)
  • Use indeterminate when the total is known
  • Hand-write an h-0.5 bg-secondary progress bar

Property descriptions follow the Chinese source comments.

Prop Type Default Description
value * number — 已完成的量,0..max;超出两端按两端算
max number — 总量,默认 100
label * string — 读屏名:在做什么(「环境自检」),读屏同时念进度值
indeterminate boolean — 不知道总量(等服务端、排队中):整条缓慢呼吸,不画具体进度;减少动态效果时静止
size ProgressSize — sm 2pt(默认,放在对话框、卡片里一行文字下面);md 4pt(单独一块的上传、导出)
class string — 布局类(宽度、外边距);默认横向撑满父容器
testID string —

* required

Prop Type Default Description
ratio * number — 部分占整体的比例,0–1;超界时裁到轨道内
tone RatioTone 'neutral'
label * string — 比例的名称;数值单独提供给读屏
size 'sm' | 'md' — sm 6pt,md 8pt
class string —
testID string —

* required