From 2e3fdd4800320ec863e080cb8c968e7d1b46edaa Mon Sep 17 00:00:00 2001 From: maoyingjie Date: Wed, 28 Oct 2026 16:35:26 +0800 Subject: [PATCH] fix(demos): inherit ConfigProvider locale and restore the format-options popover width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- apps/docs/components/calendar.md | 4 +- apps/docs/components/date-range-picker.md | 1 + apps/docs/demos/calendar-booking-calendar.vue | 4 +- apps/docs/demos/calendar-controlled.vue | 23 ++- apps/docs/demos/calendar-disabled.vue | 39 ++-- apps/docs/demos/calendar-read-only.vue | 44 +++-- .../docs/demos/calendar-unavailable-dates.vue | 4 +- .../date-range-picker-format-options.vue | 23 ++- docs/compatibility.md | 172 +++++++++--------- .../styles/components/date-range-picker.css | 12 ++ packages/vue/src/index.ts | 13 +- packages/vue/src/providers/context.ts | 16 +- tests/calendar-demos.test.ts | 126 ++++++++++++- tests/date-range-picker-demos.test.ts | 46 ++++- tests/package/client-checks.json | 2 + 15 files changed, 382 insertions(+), 147 deletions(-) diff --git a/apps/docs/components/calendar.md b/apps/docs/components/calendar.md index 9c6d85c..d5b4551 100644 --- a/apps/docs/components/calendar.md +++ b/apps/docs/components/calendar.md @@ -288,8 +288,8 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部 ### Related packages - [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具 -- 本库 `ConfigProvider` — 覆盖子树的 locale -- 本库 `ConfigProvider` — 统一 locale 与布局方向 +- 本库 `ConfigProvider` — 覆盖子树的 locale 与布局方向 +- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`,与组件继承链一致),供 `startOfWeek`、`isWeekend`、`DateFormatter` 等本地化计算使用 ## Vue 模型、DOM 与当前差异 diff --git a/apps/docs/components/date-range-picker.md b/apps/docs/components/date-range-picker.md index 65547b6..5ee2090 100644 --- a/apps/docs/components/date-range-picker.md +++ b/apps/docs/components/date-range-picker.md @@ -348,6 +348,7 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹 - [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具 - 本库 `ConfigProvider` — 为子树覆盖 locale、书写方向与 Portal 目标 +- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`),供 `DateFormatter`、`startOfWeek`、`isWeekend` 等本地化计算使用 ## 相关组件 diff --git a/apps/docs/demos/calendar-booking-calendar.vue b/apps/docs/demos/calendar-booking-calendar.vue index d883d3e..d29ea31 100644 --- a/apps/docs/demos/calendar-booking-calendar.vue +++ b/apps/docs/demos/calendar-booking-calendar.vue @@ -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(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); diff --git a/apps/docs/demos/calendar-disabled.vue b/apps/docs/demos/calendar-disabled.vue index a72285e..9cb4291 100644 --- a/apps/docs/demos/calendar-disabled.vue +++ b/apps/docs/demos/calendar-disabled.vue @@ -9,22 +9,31 @@ import { CalendarGridBody, CalendarHeaderCell, CalendarCell, + Description, } from "@heroui-vue/components"; +import { getLocalTimeZone, today } from "@internationalized/date"; diff --git a/apps/docs/demos/calendar-read-only.vue b/apps/docs/demos/calendar-read-only.vue index 4e0a775..5eb5812 100644 --- a/apps/docs/demos/calendar-read-only.vue +++ b/apps/docs/demos/calendar-read-only.vue @@ -9,27 +9,31 @@ import { CalendarGridBody, CalendarHeaderCell, CalendarCell, + Description, } from "@heroui-vue/components"; -import { parseDate } from "@internationalized/date"; +import { getLocalTimeZone, today } from "@internationalized/date"; diff --git a/apps/docs/demos/calendar-unavailable-dates.vue b/apps/docs/demos/calendar-unavailable-dates.vue index b5e80bc..078bd57 100644 --- a/apps/docs/demos/calendar-unavailable-dates.vue +++ b/apps/docs/demos/calendar-unavailable-dates.vue @@ -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);