feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarCellIndicator,
|
||||
Button,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef, ref } from "vue";
|
||||
import {
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
isWeekend,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const selectedDate = shallowRef<DateValue | null>(null);
|
||||
const booking = ref("");
|
||||
const now = today(getLocalTimeZone());
|
||||
const bookedDates = [5, 6, 12, 13, 14, 20];
|
||||
const isDateUnavailable = (date: DateValue) =>
|
||||
isWeekend(date, "en-US") || bookedDates.includes(date.day);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar
|
||||
aria-label="预订日期"
|
||||
v-model="selectedDate"
|
||||
:min-value="now"
|
||||
:is-date-unavailable="isDateUnavailable"
|
||||
>
|
||||
<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" v-slot="{ formattedDate }">
|
||||
{{ formattedDate }}
|
||||
<CalendarCellIndicator v-if="bookedDates.includes(date.day)" />
|
||||
</CalendarCell>
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
<div class="flex flex-col gap-2 text-center">
|
||||
<div class="flex items-center justify-center gap-4 text-xs text-muted">
|
||||
<span class="flex items-center gap-1">
|
||||
<span class="size-2 rounded-full bg-muted" />
|
||||
已有预订
|
||||
</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<span class="size-2 rounded-full bg-default" />
|
||||
周末/不可用
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
v-if="selectedDate"
|
||||
size="sm"
|
||||
variant="primary"
|
||||
@click="booking = selectedDate.toString()"
|
||||
>
|
||||
预订 {{ selectedDate.toString() }}
|
||||
</Button>
|
||||
<Description v-if="booking" role="status">
|
||||
已预订 {{ booking }}
|
||||
</Description>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user