Files
heroui-vue/apps/docs/demos/calendar-booking-calendar.vue
T
maoyingjie 2e3fdd4800 fix(demos): inherit ConfigProvider locale and restore the format-options popover width
HD-03 scope, all against heroui ce90ea3 cn sources:

- calendar-disabled/read-only: restore the today() default value and the
  baseline description lines (日历已禁用 / 日历为只读) inside the
  flex flex-col items-center wrapper
- calendar-controlled: restore the second button row (设为今天/设为圣诞节/
  清空) and the baseline feedback wording (已选日期:…(未选))
- locale inheritance: add a public useLocale() accessor (the components'
  ConfigProvider → en-US/ltr chain) and use it for startOfWeek in
  calendar-controlled, isWeekend in booking-calendar/unavailable-dates and
  the DateFormatter in date-range-picker-format-options instead of the
  hardcoded 'en-US' / 'zh-CN' literals
- date-range-picker-format-options: restore the pinned w-full popover class;
  the pinned source positions the popover against the initial containing
  block (full viewport width — verified on the reference docs at desktop and
  narrow), while Reka's shrink-to-fit positioning wrapper collapses the same
  class. A scoped adapter rule (.hv-date-range-picker__popover.w-full →
  100vw, layering-safe like the dropdown static-wrapper adapter) restores
  the baseline effect: viewport-wide popover, 252px calendar, stretched
  time rows, identical boundary clamping

- tests: locale dynamic-switching regressions covering zh-CN/en-US for week
  start, weekend rules (with ar-EG flipping the weekend for a observable
  rule change) and range formatting; full suite 110 files / 1627 tests,
  typecheck, build:docs and the date-range-picker / api-root-aliases /
  calendar tarball contracts pass
2026-10-28 16:35:26 +08:00

82 lines
2.3 KiB
Vue

<script setup lang="ts">
import {
Calendar,
CalendarHeader,
CalendarHeading,
CalendarNavButton,
CalendarGrid,
CalendarGridHeader,
CalendarGridBody,
CalendarHeaderCell,
CalendarCell,
CalendarCellIndicator,
Button,
Description,
useLocale,
} 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 { locale } = useLocale();
const isDateUnavailable = (date: DateValue) =>
isWeekend(date, locale.value) || 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>