Progress Bar
进度条。表示一项任务走到哪了。基于 Reka UI Progress。可以带标题、当前值和一句说明。
Installation
pnpm dlx @weme-ui/weme-ui add progress-barUsage
Uploading64%
Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
</script>
<template>
<div class="w-full">
<ProgressBar label="Uploading" :model-value="64" />
</div>
</template>Examples
Sizes
Small40%
Medium40%
Large40%
Vueexamples/sizes.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
</script>
<template>
<div class="flex flex-col gap-3 w-full">
<ProgressBar label="Small" size="sm" :model-value="40" />
<ProgressBar label="Medium" size="md" :model-value="40" />
<ProgressBar label="Large" size="lg" :model-value="40" />
</div>
</template>Color
default64%
accent64%
info64%
success64%
warning64%
error64%
Vueexamples/color.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
const colors = ['default', 'accent', 'info', 'success', 'warning', 'error'] as const
</script>
<template>
<div class="flex flex-col gap-3 w-full">
<ProgressBar
v-for="color in colors"
:key="color"
:color="color"
:label="color"
:model-value="64"
/>
</div>
</template>With Description
Storage64%
64 GB of 100 GB used
Vueexamples/with-description.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
</script>
<template>
<div class="w-full">
<ProgressBar description="64 GB of 100 GB used" label="Storage" :model-value="64" />
</div>
</template>Without Label
Vueexamples/without-label.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
</script>
<template>
<div class="w-full">
<ProgressBar :model-value="64" />
</div>
</template>Format Options
Percent64%
Decimal64
USD$64.00
Vueexamples/format-options.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
const formats = [
{
label: 'Percent',
formatOptions: { style: 'percent' },
},
{
label: 'Decimal',
formatOptions: { style: 'decimal' },
},
{
label: 'USD',
formatOptions: { style: 'currency', currency: 'USD' },
},
] as const
</script>
<template>
<div class="flex flex-col gap-3 w-full">
<ProgressBar
v-for="format in formats"
:key="format.label"
:format-options="format.formatOptions"
:label="format.label"
:model-value="64"
/>
</div>
</template>Indeterminate
Vueexamples/indeterminate.vueExpand codeHide code
<script lang="ts" setup>
import ProgressBar from '../progress-bar.vue'
</script>
<template>
<div class="w-full">
<ProgressBar aria-label="Loading" :model-value="null" />
</div>
</template>Props
PropTypeDefault
asAsTag | Component'div'
根节点渲染为的元素或组件(Reka UI
Primitive)AsTag | Component'div'
asChildbooleanfalse
合并到子元素上渲染(Reka UI composition)
booleanfalsemodelValuenumber | null-
当前进度,可用
v-model。空值时 data-state 为 indeterminate。指示条按 translateX(-(100 - (modelValue ?? 0))%) 位移,不除以 maxnumber | null-
maxnumber100
最大值。用于
aria-valuemax,并作为百分比文案的分母number100getValueLabel(value: number | null | undefined, max: number) => string | undefined(value, max) => typeof value === 'number' ? Math.round((value / max) * 100) + '%' : undefined
无障碍名称(
aria-label)。值为数字时默认读成相对 max 的整数百分比,否则不设(value: number | null | undefined, max: number) => string | undefined(value, max) => typeof value === 'number' ? Math.round((value / max) * 100) + '%' : undefined
getValueText(value: number | null | undefined, max: number) => string | undefined-
无障碍数值文本(
aria-valuetext)。未传时不设(value: number | null | undefined, max: number) => string | undefined-
color'default' | 'accent' | 'info' | 'success' | 'warning' | 'error''default'
指示条颜色
'default' | 'accent' | 'info' | 'success' | 'warning' | 'error''default'
size'sm' | 'md' | 'lg''md'
尺寸
'sm' | 'md' | 'lg''md'
labelstring-
标题。无
label 插槽时作为默认内容。无插槽且无 prop 时不渲染标题行,数值也不显示string-descriptionstring-
说明。无
description 插槽时作为默认内容string-hideValueboolean-
为
true 时不渲染数值boolean-formatOptionsIntl.NumberFormatOptions{ style: 'percent' }
数值文案的
Intl.NumberFormat 选项。style 为 'percent' 时格式化 (modelValue ?? 0) / (max ?? 100),否则格式化 modelValue ?? 0。只在有标题时出现Intl.NumberFormatOptions{ style: 'percent' }classany-
轨道额外 class(加在 track 上)
any-uiPartial<ProgressBarStyleSlots>-
覆盖 slots 样式(
root / track / indicator / caption / label / description / value)Partial<ProgressBarStyleSlots>-
Events
EventType
update:modelValuevalue: string[] | undefined
值变更时触发(含
v-model);由 Reka ProgressRoot 转发value: string[] | undefined
update:maxvalue: number
max 变更时触发(含 v-model:max);由 Reka ProgressRoot 转发value: number
Slots
SlotDescription
label标题内容。未传时回退到 label。无插槽且无 prop 时不渲染标题行
标题内容。未传时回退到
label。无插槽且无 prop 时不渲染标题行value数值文案。作用域参数 { modelValue, value }。modelValue 是当前进度,value 是格式化后的字符串。仅在有标题且 hideValue 不为真时渲染
数值文案。作用域参数
{ modelValue, value }。modelValue 是当前进度,value 是格式化后的字符串。仅在有标题且 hideValue 不为真时渲染description说明内容。未传时回退到 description。无插槽且无 prop 时不渲染
说明内容。未传时回退到
description。无插槽且无 prop 时不渲染Accessibility
基于 Reka UI ProgressRoot(内含 ProgressIndicator)。根节点 role="progressbar",aria-valuemin 为 0,aria-valuemax 为 max。值为数字时设置 aria-valuenow,aria-label 来自 getValueLabel,aria-valuetext 来自 getValueText。data-state 为空值时是 indeterminate,等于 max 时是 complete,否则是 loading。根节点还有 data-value、data-max,以及 data-slot="progress-bar"。
Files
src/components/progress-bar/progress-bar.vuesrc/components/progress-bar/progress-bar.props.tssrc/components/progress-bar/progress-bar.style.tssrc/components/progress-bar/progress-bar.uno.ts