Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào app đã cài registry, hoặc mở trong StackBlitz.
Kèm nhãn và số đếm
Nhãn đặt tên cho thanh (aria-labelledby); số đếm bên cạnh nói lại bằng chữ.
Đang nhập sản phẩm640 / 1.000
ProgressLabeled.vue
<script setup lang="ts">
import { Progress } from '@/components/ui/progress'
const done = 640
const total = 1000
</script>
<template>
<div class="flex w-full max-w-120 flex-col gap-(--bh-space-100)">
<div class="flex items-baseline justify-between gap-(--bh-space-200)">
<span id="import-label" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Đang nhập sản phẩm</span>
<span class="text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)] tabular-nums">{{ done.toLocaleString('vi') }} / {{ total.toLocaleString('vi') }}</span>
</div>
<Progress :model-value="done / total * 100" aria-labelledby="import-label" />
</div>
</template>Một việc đang chạy
Phần đã làm di chuyển theo motion.indicator. Một dòng trạng thái báo khi việc bắt đầu và kết thúc, không báo từng bước.
ProgressRunning.vue
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { Button } from '@/components/ui/button'
import { Progress } from '@/components/ui/progress'
const value = ref(0)
const running = ref(false)
let timer: ReturnType<typeof setInterval> | undefined
function start() {
value.value = 0
running.value = true
clearInterval(timer)
timer = setInterval(() => {
value.value = Math.min(100, value.value + 10)
if (value.value === 100) {
clearInterval(timer)
running.value = false
}
}, 400)
}
onBeforeUnmount(() => clearInterval(timer))
</script>
<template>
<div class="flex w-full max-w-120 flex-col gap-(--bh-space-150)">
<Progress :model-value="value" aria-label="Tiến độ đồng bộ tồn kho" />
<div class="flex items-center gap-(--bh-space-150)">
<Button variant="outline" size="sm" :aria-disabled="running || undefined" @click="start">Đồng bộ tồn kho</Button>
<!-- Nói trạng thái bằng chữ, cho trình đọc màn hình và cho người không thấy thanh chạy. -->
<span role="status" class="text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">
{{ running ? 'Đang đồng bộ…' : value === 100 ? 'Đã đồng bộ tồn kho' : '' }}
</span>
</div>
</div>
</template>