组件
计时器 Timer
Timer:计时器。等宽数字避免跳动,操作触发器沿用控件样式。部件:Root、Area、Control、Item、Separator、ActionTrigger、Context。单位标签是普通内容,不是状态机部件。
#基础用法
18
min42
sec<script setup lang="ts">
import { pause, play, rotate_ccw } from "@bysages/icons";
import { Icon, Timer } from "@bysages/vue";
const units = [
{ type: "minutes", label: "min" },
{ type: "seconds", label: "sec" },
];
</script>
<template>
<Timer.Root :start-ms="18 * 60 * 1000 + 42 * 1000">
<Timer.Area>
<template v-for="(unit, index) in units" :key="unit.type">
<Timer.Separator v-if="index > 0">:</Timer.Separator>
<div class="grid justify-items-center gap-[0.125rem]">
<Timer.Item :type="unit.type" />
<span class="text-xs text-tertiary">{{ unit.label }}</span>
</div>
</template>
</Timer.Area>
<Timer.Control>
<Timer.ActionTrigger action="start">
<Icon :glyph="play" />
Start
</Timer.ActionTrigger>
<Timer.ActionTrigger action="pause">
<Icon :glyph="pause" />
Pause
</Timer.ActionTrigger>
<Timer.ActionTrigger action="resume">Resume</Timer.ActionTrigger>
<Timer.ActionTrigger action="reset">
<Icon :glyph="rotate_ccw" />
Reset
</Timer.ActionTrigger>
</Timer.Control>
</Timer.Root>
</template>
#属性
#ActionTrigger
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
action | TimerAction | — |
#Area
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Control
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Item
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
type | TimePart | — |
#Root
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
autoStart | boolean | 计时器是否自动启动 | |
countdown | boolean | 计时器是否倒计时,每次 tick 递减计时值 | |
id | string | 组件内部状态机的唯一标识 | |
ids | Partial<{ root: string; area: string; }> | 计时器部件的 id | |
interval | number | 250 | 更新计时器计数的间隔,单位毫秒 |
startMs | number | 计时器总时长,单位毫秒 | |
targetMs | number | 计时器最小计数,单位毫秒 | |
translations | timer.IntlTranslations | 无障碍元素及其状态的本地化文案 |
#Separator
纯造型的部件——自身没有属性,沿用部件结构的共享样式。