Files
heroui-vue/apps/docs/demos/time-field-controlled.vue
T

39 lines
1.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
TimeField,
TimeFieldGroup,
TimeFieldInput,
TimeFieldSegment,
Label,
Description,
Button,
} from "@heroui-vue/components";
import { shallowRef } from "vue";
import { Time, getLocalTimeZone, now } from "@internationalized/date";
import type { TimeValue } from "@heroui-vue/components";
const value = shallowRef<TimeValue | null>(null);
function setCurrent() {
const current = now(getLocalTimeZone());
value.value = new Time(current.hour, current.minute, current.second);
}
</script>
<template>
<div class="flex flex-col gap-4">
<TimeField class="w-[256px]" name="time" v-model="value">
<Label>时间</Label>
<TimeFieldGroup>
<TimeFieldInput v-slot="{ segment }">
<TimeFieldSegment :segment="segment" />
</TimeFieldInput>
</TimeFieldGroup>
<Description>
当前值:{{ value ? value.toString() : "(空)" }}
</Description>
</TimeField>
<div class="flex gap-2">
<Button variant="tertiary" @click="setCurrent">设为当前时间</Button>
<Button variant="tertiary" @click="value = null">清空</Button>
</div>
</div>
</template>