Files

56 lines
11 KiB
Markdown
Raw Permalink 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.
# 10-datetime:calendar / range-calendar / date-field / date-picker / date-range-picker / time-field
机械数据复核说明:demo_cjk/demo_strings 中 `use client`、模板循环(`${option} 周`、`{ date }`、`{ segment }` 等)均已剔除;up_ex/vue_ex 中 "render-function 仅 Vue 多" 为提取误报(上游多行 `<ComponentPreview\n name="…-render-function" />`,两侧文档与注册表均有,如 `heroui/apps/docs/src/demos/cn/index.ts:1049,1086,1129,2646`),示例清单两侧完全一致(含次序)。
### calendar
- [示例] calendar-disabled:上游 `heroui/apps/docs/src/demos/cn/calendar/disabled.tsx` 有 `defaultValue={today(getLocalTimeZone())}` 与 `<Description class="text-center">日历已禁用</Description>`(wrapper `flex flex-col items-center gap-4`);`heroui-vue/apps/docs/demos/calendar-disabled.vue` 均缺失,仅裸 Calendar。
- [示例] calendar-read-only:同类缺失——上游"日历为只读"文案 + `defaultValue={today(...)}`;Vue 无文案且用固定 `parseDate('2025-02-14')`(calendar-read-only.vue:17-21)。
- [示例] calendar-controlled:上游第二排按钮 `设为今天/设为圣诞节/清空`(`flex gap-2`、variant secondary/tertiary)Vue 完全缺失(cn/calendar/controlled.tsx:71-101);文案"已选日期:…(未选)"→"已选择:…/未选择日期"。
- [示例] calendar-controlled/booking-calendar/unavailable-dates:上游用 `useLocale()` 得 locale 传 `startOfWeek(today, locale)`、`isWeekend(date, locale)`;Vue 硬编码 `'en-US'`(calendar-controlled.vue:39、calendar-booking-calendar.vue:28、calendar-unavailable-dates.vue:15)→ 非 en-US locale 下"本周"起点与周末判定不同。
- [示例] calendar-custom-icons:上游用内联 SVG path(M15.41…),Vue 用 `@tabler/icons-vue` IconArrowLeft/Right——图标字形不同(本库"示例用 Tabler"约定,全组示例同此,如 `@gravity-ui/icons`→Tabler,仅记一次)。
- [API] Year Picker Parts `visibleYears` 默认值:上游 calendar.mdx:261 "min–max 跨度或 `20`",Vue calendar.md:269 只写 "min–max 跨度"(range-calendar.md:286 保留"或 20",Vue 文档内部不一致)。
- [API] 年份部件 `format` 类型 `DateFormatterOptions` → `Intl.DateTimeFormatOptions`(calendar.md:266-268)。
- [样式] 文档"全局 CSS"示例 `.hv-calendar__heading` 用 `text-default-foreground`,上游 `.calendar__heading` 用 `text-default-700`(calendar.mdx:156-158)——示例代码颜色字面量不同;实际 calendar.css 两侧逐字一致。
- [实现] 年份选择器:上游仓库将 calendar-year-picker 标为"进行中"(heroui/AGENTS.md,测试豁免),Vue 已实现并公开 6 个 `CalendarYearPicker*` 部件(超出基线状态,非缺失)。
- [文档] Related packages:Vue calendar.md:291-292 出现两条重复的 ConfigProvider(合并 I18nProvider+useLocale 所致),无 `useLocale` 对应条目(轻微)。
### range-calendar
- [样式] `.hv-range-calendar__cell` 比上游多 `w-full`(heroui-vue/packages/styles/components/range-calendar.css:185-187,注释"RAC uses a stretching block here; the Vue primitive is a native button";上游 range-calendar.css:184 无)——补偿原生 button 拉伸;`.hv-calendar__cell` 无此项但其基线规则自带 `size-full`(calendar.css:186),结构(td>button>span.__cell-button)两侧一致,实际视觉(td 内按钮宽度/点击域)待核实。
- [API] `value` 类型 `RangeValue<DateValue>`→`CalendarDateRange`、`@change` 参数多 `| null`:框架映射/命名差异,非缺失。Vue 另有"补充属性"(defaultFocusedValue、autoFocus、timeZone、`isDateDisabled` 等)为新增能力(上游无 `isDateDisabled`)。
- [示例] 全部 20 个示例内容、文案、类名一致(week/day-view 差异为模板循环误报)。
### date-field
- [示例] date-field-full-width:wrapper `w-[400px] space-y-4` → `w-[400px] max-w-full space-y-4`;date-field-granularity:`flex gap-4` → `flex flex-wrap gap-4`(布局类轻微差异)。
- [API] 上游 DateField.Input 表列 `variant`(date-field.mdx:332-336)但上游实现未接收:`heroui/packages/react/src/components/date-input-group/date-input-group.tsx:97-113` 的 Input 无 variant(仅根级 42-48)——上游文档与自身代码矛盾;Vue DateFieldInput 只列 `class`/`as`,与双方实现一致(TimeField 同此问题)。
- [API] `validate` 签名 `(value: DateValue) => ValidationError | true | null | undefined` → `(value: DateValue | null) => string | string[] | true | null | undefined`(date-field.md:228);DateValue Types 一节上游含 `Time` 条目(date-field.mdx:286),Vue 移除并注明 Time 不属于 DateField 值类型。
- [样式] date-input-group 端点选择器 `[slot="start"/"end"]` → `[data-endpoint=…]`(date-input-group.css:74-80 ↔ 上游 72-78):底座适配,@apply 值逐一相同,未发现视觉差异。
- [样式] 时间字段/日期字段 CSS(date-field.css、time-field.css、calendar.css)归一化后仅许可头差异。
- [示例] date-field-form-example:`已提交日期:` 仅为上游 `console.log` 文本(cn/date-field/form-example.tsx:28),非可见内容,剔除。
### date-picker
- [API] 覆盖差异(重点核对项):上游 date-picker.mdx API 表仅 13 行(value/defaultValue/onChange、isOpen/defaultOpen/onOpenChange、isDisabled/isInvalid、minValue/maxValue、name、children、render),`placeholderValue`、`shouldCloseOnSelect`、`isDateUnavailable`、`granularity`、`hourCycle` 等一律不在表中,仅"格式选项"正文提及 granularity/hourCycle/hideTimeZone/shouldForceLeadingZeros,其余靠"继承 RAC 全部 props"(date-picker.mdx:168-184)。Vue(date-picker.md:201-254)分组列出并给默认值:placeholderValue=本地今天、shouldCloseOnSelect=`true`、granularity=`'day'`、hourCycle=由 locale 决定、isDateUnavailable/validationBehavior='native' 等——为覆盖新增,无缺失。
- [API] 默认值不一致:Vue DatePicker `granularity` 默认写 `'day'`,而本组 date-field 为"日期默认 day、时间默认 minute"、date-range-picker 为"由接受值推断"(date-range-picker.md:242),三处口径不一(与 RAC"随值推断"口径待核实)。
- [API] `shouldCloseOnSelect` 为 Vue 新增 prop(上游 date-picker.tsx 无此 prop、文档无此项,默认行为=选中即关);默认 `true` 不改变默认行为(能力新增)。
- [样式/动画] popover `data-placement^=`→`data-side^=`、`--trigger-anchor-point`→`--reka-popper-transform-origin`(date-picker.css:42-70 ↔ 上游 42-68):底座适配,进入动画(fade-in-0 zoom-in-95 + 四向 slide-in)方向映射一致;Vue 额外增加 `&[data-exiting],&[data-entering]{motion-reduce:animate-none/transition-none}`(reduced-motion 补充,非缺失)。
- [实现] 触发器 `data-focus-visible` 由 `@focus/@blur` 无条件切换(heroui-vue/.../date-picker/DatePickerTrigger.vue:79-81,date-range-picker/DateRangePickerTrigger.vue:79-81),鼠标点击聚焦也会置 true;配合 CSS `&[data-focus-visible="true"]{@apply status-focused}`(两侧同规则),鼠标点击可能显示键盘焦点环,上游 RAC Button 仅键盘聚焦置位(待核实)。
- [实现] 关闭后焦点回触发器(上游 date-picker.tsx:50-80 的 `shouldRestoreFocusToTriggerRef` + rAF)在 Vue DatePicker.vue:234-288 等价复刻,无差异。
### date-range-picker
- [示例] date-range-picker-format-options:Popover 内容 wrapper `flex w-full flex-col gap-3` → `flex w-[276px] flex-col gap-3`(cn/date-range-picker/format-options.tsx:116 ↔ date-range-picker-format-options.vue:137),弹层内容宽度由自适应变固定 276px;且 `new DateFormatter(locale,…)`(useLocale)→ 硬编码 `"zh-CN"`(vue:81 ↔ tsx:50-51),非 zh-CN 环境月份缩写/格式不同。
- [示例] date-range-picker-controlled:`slot="start"/"end"`→`endpoint="start"/"end"` 为底座适配;"至" 文案为模板字符串误报,其余一致。
- [API] 与 date-picker 同口径:placeholderValue、shouldCloseOnSelect("完成第二个端点后关闭")、isDateUnavailable、granularity("由接受值推断")、hourCycle 上游表未列、Vue 列出;`allowsNonContiguousRanges` 两侧均列(默认 false),一致。
- [文档] Vue 新增 Variants 节(`dateRangePickerVariants` 五 slot)与"DateFieldInput 端点入口"表,上游无对应章节(新增非缺失);Vue 兼容说明记录 `index.ts` 额外 `InputContainer` 导出未被页面引用。
### time-field
- [示例] time-field-form-example:Vue 新增 `<output class="text-sm text-muted">已提交:…</output>`(time-field-form-example.vue:80-82),上游仅 `console.log("Time submitted:",…)`(cn/time-field/form-example.tsx:28)——多一段可见提交反馈。
- [API] 重点项两侧一致:placeholderValue"默认随小时制为 12:00 AM 或 00:00"、granularity `'hour'|'minute'|'second'` 默认 `'minute'`、hourCycle"由 locale 决定"、shouldForceLeadingZeros(time-field.mdx:179-215 ↔ time-field.md:185-225)。`validate` 返回类型 `ValidationError`→`ValidateResult` 为类型命名差异;Vue 提供 `TimeFieldInputContainer`(上游 TimeField 组合清单无 InputContainer,仅 DateField 有)。
- [实现] 分段行为:Vue 明确 Segment 上 Enter 触发原生表单 `requestSubmit()`、blur 不重复提交已接受值、`@keydown.prevent` 才可取消数字/增减编辑(time-field.md:457 及兼容说明);React Aria 分段无 Enter 提交语义(待核实)——行为新增/差异。`step/stepSnapping` 两侧均未公开。
- [样式] time-field.css、TimeFieldGroup 样式段与上游逐字一致(复用 date-input-group 类,含 segment 前导零/焦点样式)。
## 本组小结
1. calendar-disabled / calendar-read-only 示例缺 `defaultValue={today()}` 与说明文案("日历已禁用"/"日历为只读"),calendar-controlled 缺"设为今天/设为圣诞节/清空"按钮行——可见内容缺失。
2. locale 硬编码:calendar 三个示例 `isWeekend/startOfWeek` 固定 'en-US'(上游随 useLocale),date-range-picker-format-options 的 DateFormatter 固定 'zh-CN'——非默认 locale 下行为/格式错。
3. date-picker/date-range-picker 触发器 `data-focus-visible` 由 @focus 无条件置位,鼠标点击可能显示键盘焦点环(上游 RAC 仅键盘置位)(待核实)。
4. date-range-picker-format-options 弹层内容宽度 `w-[276px]` 对上游 `w-full`,格式选项弹层可见宽度不同。
5. granularity 默认值三处口径不一(DatePicker `'day'` vs DateRangePicker"由接受值推断" vs DateField"日期 day/时间 minute"),且 `visibleYears` 默认值 calendar 页漏"或 20";另 range-calendar `__cell` 多 `w-full`、trigger focus 状态为适配残留风险(待核实)。