feat: migrate public TimeField with shared date input parts
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
TimeField,
|
||||
TimeFieldGroup,
|
||||
TimeFieldInput,
|
||||
TimeFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
import { computed, shallowRef } from "vue";
|
||||
import { parseTime, Time } from "@internationalized/date";
|
||||
import type { TimeValue } from "@heroui-vue/components";
|
||||
const value = shallowRef<TimeValue | null>(null);
|
||||
const minTime = parseTime("09:00");
|
||||
const maxTime = parseTime("17:00");
|
||||
const isInvalid = computed(() => {
|
||||
if (!value.value) return false;
|
||||
const time = new Time(
|
||||
value.value.hour,
|
||||
value.value.minute,
|
||||
value.value.second,
|
||||
value.value.millisecond,
|
||||
);
|
||||
return time.compare(minTime) < 0 || time.compare(maxTime) > 0;
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TimeField
|
||||
is-required
|
||||
class="w-[256px]"
|
||||
name="time"
|
||||
v-model="value"
|
||||
:is-invalid="isInvalid"
|
||||
:min-value="minTime"
|
||||
:max-value="maxTime"
|
||||
>
|
||||
<Label>时间</Label>
|
||||
<TimeFieldGroup>
|
||||
<TimeFieldInput v-slot="{ segment }">
|
||||
<TimeFieldSegment :segment="segment" />
|
||||
</TimeFieldInput>
|
||||
</TimeFieldGroup>
|
||||
<FieldError v-if="isInvalid">
|
||||
时间须在上午 9:00 至下午 5:00 之间
|
||||
</FieldError>
|
||||
<Description v-else>输入上午 9:00 至下午 5:00 之间的时间</Description>
|
||||
</TimeField>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user