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
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
CalendarCellIndicator,
|
||||
Button,
|
||||
Description,
|
||||
useLocale,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef, ref } from "vue";
|
||||
import {
|
||||
@@ -24,8 +25,9 @@ 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, "en-US") || bookedDates.includes(date.day);
|
||||
isWeekend(date, locale.value) || bookedDates.includes(date.day);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Description,
|
||||
useLocale,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const focusedDate = shallowRef<DateValue>(parseDate("2025-12-25"));
|
||||
const { locale } = useLocale();
|
||||
function jump(date: DateValue) {
|
||||
value.value = date;
|
||||
focusedDate.value = date;
|
||||
@@ -33,7 +35,7 @@ function jump(date: DateValue) {
|
||||
<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 @click="jump(startOfWeek(today(getLocalTimeZone()), locale))">
|
||||
本周
|
||||
</Button>
|
||||
<Button @click="jump(startOfMonth(today(getLocalTimeZone())))">
|
||||
@@ -60,7 +62,24 @@ function jump(date: DateValue) {
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
<Description class="text-center">
|
||||
{{ value ? `已选择:${value.toString()}` : "未选择日期" }}
|
||||
已选日期:{{ value ? value.toString() : "(未选)" }}
|
||||
</Description>
|
||||
<div class="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="jump(today(getLocalTimeZone()))"
|
||||
>
|
||||
设为今天
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="jump(parseDate('2025-12-25'))"
|
||||
>
|
||||
设为圣诞节
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="value = null">清空</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -9,22 +9,31 @@ import {
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期" is-disabled>
|
||||
<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>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar
|
||||
aria-label="活动日期"
|
||||
is-disabled
|
||||
:default-value="today(getLocalTimeZone())"
|
||||
>
|
||||
<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">日历已禁用</Description>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -9,27 +9,31 @@ import {
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { parseDate } from "@internationalized/date";
|
||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar
|
||||
aria-label="活动日期"
|
||||
is-read-only
|
||||
:default-value="parseDate('2025-02-14')"
|
||||
>
|
||||
<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>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar
|
||||
aria-label="活动日期"
|
||||
is-read-only
|
||||
:default-value="today(getLocalTimeZone())"
|
||||
>
|
||||
<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">日历为只读</Description>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -10,9 +10,11 @@ import {
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
useLocale,
|
||||
} from "@heroui-vue/components";
|
||||
import { isWeekend, type DateValue } from "@internationalized/date";
|
||||
const isDateUnavailable = (date: DateValue) => isWeekend(date, "en-US");
|
||||
const { locale } = useLocale();
|
||||
const isDateUnavailable = (date: DateValue) => isWeekend(date, locale.value);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
TimeFieldGroup,
|
||||
TimeFieldInput,
|
||||
TimeFieldSegment,
|
||||
useLocale,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
DateFormatter,
|
||||
@@ -61,6 +62,7 @@ const granularity = ref<Granularity>("minute");
|
||||
const hourCycle = ref<HourCycle>(12);
|
||||
const hideTimeZone = ref(false);
|
||||
const shouldForceLeadingZeros = ref(false);
|
||||
const { locale } = useLocale();
|
||||
const cycle = computed(() => (hourCycle.value === 24 ? 24 : 12) as 12 | 24);
|
||||
const timeGranularity = computed(() =>
|
||||
granularity.value !== "day" ? granularity.value : undefined,
|
||||
@@ -78,14 +80,17 @@ const defaultValue = computed<DateRange>(() => {
|
||||
start: parseZonedDateTime(`2026-02-03T08:45:00[${localTimeZone}]`),
|
||||
};
|
||||
});
|
||||
const dateFormatter = new DateFormatter("zh-CN", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
});
|
||||
const dateFormatter = computed(
|
||||
() =>
|
||||
new DateFormatter(locale.value, {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
}),
|
||||
);
|
||||
function formatDate(range: DateRange) {
|
||||
const localTimeZone = getLocalTimeZone();
|
||||
return dateFormatter.formatRange(
|
||||
return dateFormatter.value.formatRange(
|
||||
range.start.toDate(localTimeZone),
|
||||
range.end.toDate(localTimeZone),
|
||||
);
|
||||
@@ -133,8 +138,10 @@ const hourCycleOptions: { label: string; value: HourCycle }[] = [
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<!-- Portaled content keeps an auto-sized wrapper; the pinned example's
|
||||
w-full maps to the 252px calendar plus the popover's 24px padding. -->
|
||||
<DateRangePickerPopover class="flex w-[276px] flex-col gap-3">
|
||||
w-full fills the popover's positioning container — see the
|
||||
.hv-date-range-picker__popover.w-full adapter in date-range-picker.css,
|
||||
which maps it to the same viewport width as the upstream chain. -->
|
||||
<DateRangePickerPopover class="flex w-full flex-col gap-3">
|
||||
<RangeCalendar aria-label="出行日期" class="w-full">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
|
||||
Reference in New Issue
Block a user