feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
parseDate,
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const focusedDate = shallowRef<DateValue>(parseDate("2025-12-25"));
|
||||
function jump(date: DateValue) {
|
||||
value.value = date;
|
||||
focusedDate.value = date;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<ButtonGroup full-width size="sm" variant="tertiary">
|
||||
<Button @click="jump(today(getLocalTimeZone()))">今天</Button>
|
||||
<Button @click="jump(startOfWeek(today(getLocalTimeZone()), 'en-US'))">
|
||||
本周
|
||||
</Button>
|
||||
<Button @click="jump(startOfMonth(today(getLocalTimeZone())))">
|
||||
本月
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
<Calendar
|
||||
aria-label="活动日期"
|
||||
v-model="value"
|
||||
v-model:focused-value="focusedDate"
|
||||
>
|
||||
<CalendarHeader>
|
||||
<CalendarHeading />
|
||||
<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>
|
||||
</Calendar>
|
||||
<Description class="text-center">
|
||||
{{ value ? `已选择:${value.toString()}` : "未选择日期" }}
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user