Files
heroui-vue/apps/docs/demos/range-calendar-anchor-unavailable-dates.vue
T

51 lines
1.5 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">
// Adapted from HeroUI ce90ea3 range-calendar/anchor-unavailable-dates.tsx, Apache-2.0.
import {
RangeCalendar,
RangeCalendarHeader,
RangeCalendarHeading,
RangeCalendarNavButton,
RangeCalendarGrid,
RangeCalendarGridHeader,
RangeCalendarGridBody,
RangeCalendarHeaderCell,
RangeCalendarCell,
Description,
} from "@heroui-vue/components";
import {
today,
getLocalTimeZone,
type CalendarDate,
type DateValue,
} from "@internationalized/date";
const now = today(getLocalTimeZone());
const isDateUnavailable = (date: DateValue, anchorDate: CalendarDate | null) =>
anchorDate != null && Math.abs(date.compare(anchorDate)) > 7;
</script>
<template>
<div class="flex flex-col items-center gap-4">
<RangeCalendar
aria-label="行程日期"
:is-date-unavailable="isDateUnavailable"
:min-value="now"
>
<RangeCalendarHeader>
<RangeCalendarHeading />
<RangeCalendarNavButton slot="previous" />
<RangeCalendarNavButton slot="next" />
</RangeCalendarHeader>
<RangeCalendarGrid>
<RangeCalendarGridHeader v-slot="{ day }">
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
</RangeCalendarGridHeader>
<RangeCalendarGridBody v-slot="{ date }">
<RangeCalendarCell :date="date" />
</RangeCalendarGridBody>
</RangeCalendarGrid>
</RangeCalendar>
<Description class="text-center">
选择开始日期后,仅前后 7 天内的日期可选
</Description>
</div>
</template>