Files
heroui-vue/apps/docs/demos/date-picker-controlled.vue
T

86 lines
2.6 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 {
Button,
Calendar,
CalendarCell,
CalendarGrid,
CalendarGridBody,
CalendarGridHeader,
CalendarHeader,
CalendarHeaderCell,
CalendarNavButton,
CalendarYearPickerCell,
CalendarYearPickerGrid,
CalendarYearPickerGridBody,
CalendarYearPickerTrigger,
CalendarYearPickerTriggerHeading,
CalendarYearPickerTriggerIndicator,
DateFieldGroup,
DateFieldInput,
DateFieldSegment,
DateFieldSuffix,
DatePicker,
DatePickerPopover,
DatePickerTrigger,
DatePickerTriggerIndicator,
Description,
Label,
} from "@heroui-vue/components";
import {
getLocalTimeZone,
today,
type DateValue,
} from "@internationalized/date";
import { shallowRef } from "vue";
const value = shallowRef<DateValue | null>(today(getLocalTimeZone()));
</script>
<template>
<div class="flex w-72 flex-col gap-4">
<DatePicker v-model="value" name="date">
<Label>日期</Label>
<DateFieldGroup full-width>
<DateFieldInput v-slot="{ segment }">
<DateFieldSegment :segment="segment" />
</DateFieldInput>
<DateFieldSuffix>
<DatePickerTrigger>
<DatePickerTriggerIndicator />
</DatePickerTrigger>
</DateFieldSuffix>
</DateFieldGroup>
<DatePickerPopover>
<Calendar aria-label="活动日期">
<CalendarHeader>
<CalendarYearPickerTrigger>
<CalendarYearPickerTriggerHeading />
<CalendarYearPickerTriggerIndicator />
</CalendarYearPickerTrigger>
<CalendarNavButton slot="previous" />
<CalendarNavButton slot="next" />
</CalendarHeader>
<CalendarGrid>
<CalendarGridHeader v-slot="{ day }">
<CalendarHeaderCell>{{ day }}</CalendarHeaderCell>
</CalendarGridHeader>
<CalendarGridBody v-slot="{ date }">
<CalendarCell :date="date" />
</CalendarGridBody>
</CalendarGrid>
<CalendarYearPickerGrid>
<CalendarYearPickerGridBody v-slot="{ year, date }">
<CalendarYearPickerCell :year="year" :date="date" />
</CalendarYearPickerGridBody>
</CalendarYearPickerGrid>
</Calendar>
</DatePickerPopover>
</DatePicker>
<Description>当前值:{{ value ? value.toString() : "(空)" }}</Description>
<div class="flex gap-2">
<Button variant="tertiary" @click="value = today(getLocalTimeZone())">
设为今天
</Button>
<Button variant="tertiary" @click="value = null">清空</Button>
</div>
</div>
</template>