8f51b0e097
- 包根补齐固定上游 82 对 Xxx/XxxRoot 同对象别名(55 个缺失 Root 别名 + Dropdown 反向别名)与 59 个 RootProps/Menu/Dropdown 类型别名;不杜撰上游没有的名称(如 CheckboxGroupRoot、ToastRootProps) - tests/package 新增 api-root-aliases 契约:完整别名清单、82 对身份等价断言与 strict NodeNext/bundler 类型正反例 - progress-bar custom-value 演示回填公共 NumberField/Select,保持固定源文案/布局/范围/四格式与边界处理 - 修复 NumberFieldInput keydown 无条件 restore 还原同任务键入字符的缺陷,并入 number-field 回归 - 文档导航 dropdown 归位固定 meta.json 顺序并补顺序断言;修正“原生临时控件”陈述
166 lines
4.5 KiB
Vue
166 lines
4.5 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref } from "vue";
|
|
import {
|
|
Label,
|
|
ListBox,
|
|
ListBoxItem,
|
|
ListBoxItemIndicator,
|
|
NumberField,
|
|
NumberFieldDecrementButton,
|
|
NumberFieldGroup,
|
|
NumberFieldIncrementButton,
|
|
NumberFieldInput,
|
|
ProgressBar,
|
|
ProgressBarFill,
|
|
ProgressBarOutput,
|
|
ProgressBarTrack,
|
|
Select,
|
|
SelectIndicator,
|
|
SelectPopover,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
Separator,
|
|
} from "@heroui-vue/components";
|
|
|
|
const value = ref(750);
|
|
const minValue = ref(0);
|
|
const maxValue = ref(1000);
|
|
const format = ref("percent");
|
|
|
|
const formatStyleOptions = [
|
|
{ label: "货币", value: "currency" },
|
|
{ label: "百分比", value: "percent" },
|
|
{ label: "小数", value: "decimal" },
|
|
{ label: "单位", value: "unit" },
|
|
] as const;
|
|
|
|
const formatOptionsMap: Record<string, Intl.NumberFormatOptions> = {
|
|
currency: { currency: "USD", style: "currency" },
|
|
decimal: { style: "decimal" },
|
|
percent: { style: "percent" },
|
|
unit: { style: "unit", unit: "mile" },
|
|
};
|
|
|
|
const formatOptions = computed(() => formatOptionsMap[format.value]);
|
|
|
|
function onValueChange(next: number | null) {
|
|
// 清空或无效草稿不接受,受控字段恢复上一个接受值。
|
|
if (next == null || !Number.isFinite(next)) return;
|
|
value.value = Math.min(Math.max(next, minValue.value), maxValue.value);
|
|
}
|
|
|
|
function onMinChange(next: number | null) {
|
|
if (next == null || !Number.isFinite(next)) return;
|
|
minValue.value = Math.min(next, maxValue.value - 1);
|
|
if (value.value < minValue.value) value.value = minValue.value;
|
|
}
|
|
|
|
function onMaxChange(next: number | null) {
|
|
if (next == null || !Number.isFinite(next)) return;
|
|
maxValue.value = Math.max(next, minValue.value + 1);
|
|
if (value.value > maxValue.value) value.value = maxValue.value;
|
|
}
|
|
|
|
function onFormatChange(next: string | number | (string | number)[] | null) {
|
|
if (typeof next === "string" && next in formatOptionsMap) format.value = next;
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex w-full flex-col gap-6 md:flex-row md:items-center md:gap-10">
|
|
<div class="flex w-full max-w-md flex-1 justify-center">
|
|
<ProgressBar
|
|
aria-label="收入"
|
|
class="w-full max-w-52"
|
|
:format-options="formatOptions"
|
|
:max-value="maxValue"
|
|
:min-value="minValue"
|
|
:value="value"
|
|
>
|
|
<Label>进度</Label>
|
|
<ProgressBarOutput />
|
|
<ProgressBarTrack>
|
|
<ProgressBarFill />
|
|
</ProgressBarTrack>
|
|
</ProgressBar>
|
|
</div>
|
|
|
|
<Separator class="md:hidden" />
|
|
<Separator class="hidden md:block" orientation="vertical" />
|
|
|
|
<div class="flex max-w-52 flex-col gap-3">
|
|
<Label class="text-xs font-medium text-muted">选项</Label>
|
|
|
|
<NumberField
|
|
:max-value="maxValue"
|
|
:min-value="minValue"
|
|
:model-value="value"
|
|
variant="secondary"
|
|
@update:model-value="onValueChange"
|
|
>
|
|
<Label>值</Label>
|
|
<NumberFieldGroup>
|
|
<NumberFieldDecrementButton />
|
|
<NumberFieldInput />
|
|
<NumberFieldIncrementButton />
|
|
</NumberFieldGroup>
|
|
</NumberField>
|
|
|
|
<NumberField
|
|
:max-value="maxValue - 1"
|
|
:min-value="0"
|
|
:model-value="minValue"
|
|
variant="secondary"
|
|
@update:model-value="onMinChange"
|
|
>
|
|
<Label>最小值</Label>
|
|
<NumberFieldGroup>
|
|
<NumberFieldDecrementButton />
|
|
<NumberFieldInput />
|
|
<NumberFieldIncrementButton />
|
|
</NumberFieldGroup>
|
|
</NumberField>
|
|
|
|
<NumberField
|
|
:max-value="2000"
|
|
:min-value="minValue + 1"
|
|
:model-value="maxValue"
|
|
variant="secondary"
|
|
@update:model-value="onMaxChange"
|
|
>
|
|
<Label>最大值</Label>
|
|
<NumberFieldGroup>
|
|
<NumberFieldDecrementButton />
|
|
<NumberFieldInput />
|
|
<NumberFieldIncrementButton />
|
|
</NumberFieldGroup>
|
|
</NumberField>
|
|
|
|
<Select
|
|
:model-value="format"
|
|
variant="secondary"
|
|
@update:model-value="onFormatChange"
|
|
>
|
|
<Label>格式</Label>
|
|
<SelectTrigger>
|
|
<SelectValue />
|
|
<SelectIndicator />
|
|
</SelectTrigger>
|
|
<SelectPopover>
|
|
<ListBox>
|
|
<ListBoxItem
|
|
v-for="option in formatStyleOptions"
|
|
:id="option.value"
|
|
:key="option.value"
|
|
:text-value="option.label"
|
|
>
|
|
{{ option.label }}
|
|
<ListBoxItemIndicator />
|
|
</ListBoxItem>
|
|
</ListBox>
|
|
</SelectPopover>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
</template>
|