feat: migrate DateField and shared date input group
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
TooltipContent,
|
||||
} from "@heroui-vue/components";
|
||||
import { computed, ref } from "vue";
|
||||
import { IconHelpCircle } from "@tabler/icons-vue";
|
||||
import { parseDate, parseZonedDateTime } from "@internationalized/date";
|
||||
type Granularity = "day" | "hour" | "minute" | "second";
|
||||
const options = [
|
||||
{ id: "day", label: "日" },
|
||||
{ id: "hour", label: "时" },
|
||||
{ id: "minute", label: "分" },
|
||||
{ id: "second", label: "秒" },
|
||||
] as const;
|
||||
const granularity = ref<Granularity>("day");
|
||||
function setGranularity(value: unknown) {
|
||||
if (options.some((option) => option.id === value))
|
||||
granularity.value = value as Granularity;
|
||||
}
|
||||
const defaultValue = computed(() =>
|
||||
granularity.value === "day"
|
||||
? parseDate("2025-02-03")
|
||||
: parseZonedDateTime("2025-02-03T08:45:00[America/Los_Angeles]"),
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<DateField
|
||||
:key="granularity"
|
||||
class="w-[256px]"
|
||||
:default-value="defaultValue"
|
||||
:granularity="granularity"
|
||||
name="granularity-date"
|
||||
>
|
||||
<Label>预约日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<Label>粒度</Label>
|
||||
<Tooltip :delay="0">
|
||||
<TooltipTrigger aria-label="粒度说明">
|
||||
<IconHelpCircle class="size-4 text-muted" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent placement="bottom start">
|
||||
<p>
|
||||
决定日期选择器显示的最小单位。默认情况下,日期为「日」,时间为「分」。
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Select
|
||||
class="w-[110px]"
|
||||
:model-value="granularity"
|
||||
placeholder="选择粒度"
|
||||
variant="secondary"
|
||||
@update:model-value="setGranularity"
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in options"
|
||||
:id="option.id"
|
||||
:key="option.id"
|
||||
:text-value="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user