feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -480,3 +480,7 @@ DateField/DateInputGroup 已公开,先读[DATE-02 报告](docs/migrations/DATE
|
||||
- 公共壳层须单独验收 Header/Search:CSS 用实际 `--field-background`,不能把 Tailwind 的 bg-field 当作存在 `--field` 变量。核对计算颜色与透明度;搜索遮罩按主题局部适配,不能直接拿 Modal 默认遮罩代表官网搜索。两行导航无中间边框、桌面 gap 4px,sticky 总高度和移动端一起检查。
|
||||
- 使用组件发现异常时先核对默认组件、真实 DOM 和覆盖来源;若是组件本身问题,修组件及行为回归,不在文档藏补丁。文档不得清零 Button 内边距后再叠图标负边距;版本使用原生 button 的 PopoverTrigger,链接按钮使用 Button asChild + a 保留导航语义,ToggleButtonGroup 分离模式用 isDetached,不重写其尺寸/间距。定制配色用组件提供的状态变量。
|
||||
- 左右文档导航遵循 Fumadocs 中性灰和 400 字重,不直接复用组件 muted 色或 Link 的默认 500 字重;导航禁用 hover/pressed 下划线,仍保留焦点环。普通正文 Link 的默认下划线行为不变,不能为导航定制而全局修改 Link。框架切换区域按用户要求留空,不显示 Vue 3 标记。
|
||||
|
||||
## DATE-03 日期迁移恢复(2026-10-24)
|
||||
|
||||
用户在文档任务完成后明确继续集成人负责的组件,DATE-02 暂停记录不再阻止日期接续。Calendar/CalendarYearPicker 的当前范围见 [DATE-03](docs/migrations/DATE-03-calendar.md)。月/周/日共用局部视图和接受值协议,不把受控焦点、选中与可见窗口混为一个值;pageBehavior=single 在多单位视图内也必须移动窗口。原生取消、无可用初始焦点、外部程序聚焦不抢焦点、重复补位日期与多选键盘重复分别回归。YearPicker 测真实覆盖几何/滚动/焦点和关闭拒绝,SSR/类型不能代替浏览器。Root/全部 Props、variants 与独立 YearPicker 部件从包根导出,消费契约须有实际反例。下一步 RangeCalendar → Picker/TimeField,颜色基建后续实施,仍由集成人维护日期状态边界。
|
||||
|
||||
@@ -55,6 +55,11 @@ export const componentItems: DocsItem[] = [
|
||||
url: "/components/button-group",
|
||||
category: "buttons",
|
||||
},
|
||||
{
|
||||
title: "Calendar 日历",
|
||||
url: "/components/calendar",
|
||||
category: "date-and-time",
|
||||
},
|
||||
{
|
||||
title: "Card 卡片",
|
||||
url: "/components/card",
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
---
|
||||
title: Calendar 日历
|
||||
description: 可组合日期选择器,支持月、周、日视图、导航与年份选择
|
||||
component: calendar
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Calendar } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="calendar-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期">
|
||||
<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>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="calendar-disabled" />
|
||||
|
||||
### 只读
|
||||
|
||||
<ComponentPreview name="calendar-read-only" />
|
||||
|
||||
### 默认值
|
||||
|
||||
<ComponentPreview name="calendar-default-value" />
|
||||
|
||||
### 年份选择
|
||||
|
||||
`CalendarYearPickerTrigger`、`CalendarYearPickerGrid` 及其 body/cell 子组件提供集成的年份导航模式。
|
||||
|
||||
<ComponentPreview name="calendar-year-picker" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
使用受控的 `v-model` 与 `v-model:focusedValue` 进行外部状态协调与自定义快捷操作。
|
||||
|
||||
<ComponentPreview name="calendar-controlled" />
|
||||
|
||||
### 日期范围限制
|
||||
|
||||
<ComponentPreview name="calendar-min-max-dates" />
|
||||
|
||||
### 不可用日期
|
||||
|
||||
使用 `isDateUnavailable` 阻止周末、节假日或已预订时段等日期。
|
||||
|
||||
<ComponentPreview name="calendar-unavailable-dates" />
|
||||
|
||||
### 月份周数
|
||||
|
||||
将 `weeksInMonth` 设为固定值(如 `6`)可在月份切换时保持网格高度稳定。在非公历 locale 中请谨慎使用,类似 `firstDayOfWeek`。
|
||||
|
||||
<ComponentPreview name="calendar-weeks-in-month" />
|
||||
|
||||
### 周视图
|
||||
|
||||
设置 `:visible-duration="{ weeks: n }"` 可一次显示一周或多周。导航按可见周范围前进。显示多周时使用 `pageBehavior="single"` 可每次移动一周。
|
||||
|
||||
<ComponentPreview name="calendar-week-view" />
|
||||
|
||||
### 日视图
|
||||
|
||||
设置 `:visible-duration="{ days: n }"` 可显示连续日期的滚动窗口。导航按可见日范围前进。显示多天时使用 `pageBehavior="single"` 可每次移动一天。
|
||||
|
||||
<ComponentPreview name="calendar-day-view" />
|
||||
|
||||
### 多选
|
||||
|
||||
设置 `selection-mode="multiple"` 允许选择多个日期。`modelValue`、`defaultValue` 与 `@change` 使用日期数组。
|
||||
|
||||
<ComponentPreview name="calendar-multiple-selection" />
|
||||
|
||||
### 聚焦值
|
||||
|
||||
使用 `v-model:focusedValue` 与 `@focusChange` 以编程方式控制聚焦日期。
|
||||
|
||||
<ComponentPreview name="calendar-focused-value" />
|
||||
|
||||
### 单元格标记
|
||||
|
||||
可自定义 `CalendarCell` 子节点,并使用 `CalendarCellIndicator` 显示事件等元数据。
|
||||
|
||||
<ComponentPreview name="calendar-with-indicators" />
|
||||
|
||||
### 自定义导航图标
|
||||
|
||||
向 `CalendarNavButton` 传入子节点以替换默认 chevron 图标。
|
||||
|
||||
<ComponentPreview name="calendar-custom-icons" />
|
||||
|
||||
### 多月份展示
|
||||
|
||||
使用 `visibleDuration` 与 `offset` 渲染多个月份网格,适用于预订与规划场景。
|
||||
|
||||
<ComponentPreview name="calendar-multiple-months" />
|
||||
|
||||
### 典型场景
|
||||
|
||||
<ComponentPreview name="calendar-booking-calendar" />
|
||||
|
||||
### 国际化日历
|
||||
|
||||
默认情况下,Calendar 使用用户 locale 的历法系统显示日期。可用 `ConfigProvider` 包裹 Calendar 并设置 [Unicode 历法 locale 扩展](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#adding_a_calendar_in_the_locale_string) 来覆盖。
|
||||
|
||||
以下示例展示印度历法系统:
|
||||
|
||||
<ComponentPreview name="calendar-international-calendar" />
|
||||
|
||||
**Note:** `@change` 事件始终返回与 `value` 或 `defaultValue` 相同历法系统的日期(未提供 value 时为公历),无论显示 locale 如何。这确保应用逻辑在单一历法系统下一致运行,同时仍以用户偏好的格式显示日期。
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="calendar-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-calendar {
|
||||
@apply w-72 rounded-2xl border border-border bg-surface p-3 shadow-sm;
|
||||
}
|
||||
|
||||
.hv-calendar__heading {
|
||||
@apply text-sm font-semibold text-default-foreground;
|
||||
}
|
||||
|
||||
.hv-calendar__cell[data-selected="true"] {
|
||||
@apply bg-accent text-accent-foreground;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Calendar 在 `packages/styles/components/calendar.css` 与 `packages/styles/components/calendar-year-picker.css` 中使用以下类:
|
||||
|
||||
- `.hv-calendar` - 根容器
|
||||
- `.hv-calendar__header` - 包含导航按钮与标题的头部行
|
||||
- `.hv-calendar__heading` - 当前月份标签
|
||||
- `.hv-calendar__nav-button` - 上/下月导航控件
|
||||
- `.hv-calendar__grid` - 主日期网格
|
||||
- `.hv-calendar__grid-header` - 星期标题行包装器
|
||||
- `.hv-calendar__grid-body` - 日期行包装器
|
||||
- `.hv-calendar__header-cell` - 星期标题单元格
|
||||
- `.hv-calendar__cell` - 可交互的日期单元格
|
||||
- `.hv-calendar__cell-indicator` - 日期单元格内的点指示器
|
||||
- `.hv-calendar-year-picker__trigger` - 年份选择器切换按钮
|
||||
- `.hv-calendar-year-picker__trigger-heading` - 年份选择器触发器内的标题文本
|
||||
- `.hv-calendar-year-picker__trigger-indicator` - 年份选择器触发器内的指示图标
|
||||
- `.hv-calendar-year-picker__year-grid` - 可选年份的覆盖网格
|
||||
- `.hv-calendar-year-picker__year-cell` - 单个年份选项
|
||||
|
||||
### 交互状态
|
||||
|
||||
Calendar 同时支持伪类与 状态 data 属性:
|
||||
|
||||
- **Selected**:`[data-selected="true"]`
|
||||
- **Today**:`[data-today="true"]`
|
||||
- **Unavailable**:`[data-unavailable="true"]`
|
||||
- **Outside month**:`[data-outside-month="true"]`
|
||||
- **Hovered**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Pressed**:`:active` 或 `[data-pressed="true"]`
|
||||
- **Focus visible**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Disabled**:`:disabled` 或 `[data-disabled="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Calendar
|
||||
|
||||
Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部件和作用域插槽表达;不继承 React 专属属性。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------------------- | ---------------------------------------------------------------------- | ----------------------- | --------------------------------------------------------------------------------------- |
|
||||
| `selectionMode` | `'single' \| 'multiple'` | `'single'` | 是否可选择单个或多个日期 |
|
||||
| `value` | `DateValue \| null` 或 `DateValue[] \| null` | - | 受控选中日期。`selectionMode` 为 `multiple` 时使用数组 |
|
||||
| `defaultValue` | `DateValue \| null` 或 `DateValue[] \| null` | - | 初始选中日期(非受控) |
|
||||
| `@change` | `(value: DateValue \| null)` 或 `(value: DateValue[] \| null) => void` | - | 选择变化时调用 |
|
||||
| `focusedValue` | `DateValue` | - | 受控聚焦日期 |
|
||||
| `@focusChange` | `(value: DateValue) => void` | - | 焦点移至其他日期时调用 |
|
||||
| `minValue` | `DateValue` | 历法感知的 `1900-01-01` | 最早可选日期 |
|
||||
| `maxValue` | `DateValue` | 历法感知的 `2099-12-31` | 最晚可选日期 |
|
||||
| `weeksInMonth` | `number` | - | 月份中的周数,覆盖 locale 默认值 |
|
||||
| `isDateUnavailable` | `(date: DateValue) => boolean` | - | 标记日期为不可用 |
|
||||
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | - | 覆盖 locale 默认的一周起始日 |
|
||||
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 翻页按可见时长还是单个单位前进 |
|
||||
| `selectionAlignment` | `'start' \| 'center' \| 'end'` | `'center'` | 初始渲染时可见范围与选择的对齐方式 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用交互与选择 |
|
||||
| `isReadOnly` | `boolean` | `false` | 内容可读但不可更改选择 |
|
||||
| `isInvalid` | `boolean` | `false` | 标记日历为无效以显示验证 UI |
|
||||
| `visibleDuration` | `{months?: number; weeks?: number; days?: number}` | `{months: 1}` | 可见时间范围。月视图用 `{ months: n }`,周视图用 `{ weeks: n }`,日视图用 `{ days: n }` |
|
||||
| `defaultYearPickerOpen` | `boolean` | `false` | 内部年份选择器初始打开状态 |
|
||||
| `isYearPickerOpen` | `boolean` | - | 受控年份选择器打开状态 |
|
||||
| `@yearPickerOpenChange` | `(isOpen: boolean) => void` | - | 年份选择器打开状态变化时调用 |
|
||||
|
||||
### Composition Parts
|
||||
|
||||
| Component | Description |
|
||||
| ------------------------------------ | -------------------------------------------------------------------------- |
|
||||
| `CalendarHeader` | 导航与标题的头部容器 |
|
||||
| `CalendarHeading` | 可见范围的格式化标题。支持 `offset`(多月布局)与 `format`(月/年/日选项) |
|
||||
| `CalendarNavButton` | 上/下月导航控件(`slot="previous"` 或 `slot="next"`) |
|
||||
| `CalendarGrid` | 单个月份的日期网格(多月布局支持 `offset`) |
|
||||
| `CalendarGridHeader` | 星期标题容器 |
|
||||
| `CalendarGridBody` | 日期单元格 body 容器 |
|
||||
| `CalendarHeaderCell` | 星期标签单元格 |
|
||||
| `CalendarCell` | 单个日期单元格 |
|
||||
| `CalendarCellIndicator` | 自定义元数据的可选指示元素 |
|
||||
| `CalendarYearPickerTrigger` | 切换年份选择器模式的触发器 |
|
||||
| `CalendarYearPickerTriggerHeading` | 年份选择器触发器内的本地化标题内容 |
|
||||
| `CalendarYearPickerTriggerIndicator` | 年份选择器触发器内的切换图标 |
|
||||
| `CalendarYearPickerGrid` | 覆盖式年份选择网格容器 |
|
||||
| `CalendarYearPickerGridBody` | 年份网格单元格的 body 渲染器 |
|
||||
| `CalendarYearPickerCell` | 单个年份选项单元格 |
|
||||
|
||||
### Year Picker Parts
|
||||
|
||||
年份选择器支持日期格式与窗口选项。独立部件直接从包根导入,不需要 React 上下文。
|
||||
|
||||
| Component | Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------- |
|
||||
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标签(如 `{month: 'short'}`) |
|
||||
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局) |
|
||||
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法等) |
|
||||
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 跨度 | 滑动窗口中显示的年份数。同时设置 `minValue` 与 `maxValue` 时默认为完整范围 |
|
||||
|
||||
### CalendarCell 作用域插槽
|
||||
|
||||
`CalendarCell` 的默认作用域插槽提供以下状态:
|
||||
|
||||
| Prop | 类型 | 描述 |
|
||||
| ---------------- | --------- | ---------------------- |
|
||||
| `formattedDate` | `string` | 单元格的本地化日期标签 |
|
||||
| `isSelected` | `boolean` | 日期是否选中 |
|
||||
| `isUnavailable` | `boolean` | 日期是否不可用 |
|
||||
| `isDisabled` | `boolean` | 单元格是否禁用 |
|
||||
| `isOutsideMonth` | `boolean` | 日期是否属于相邻月份 |
|
||||
|
||||
有关支持的历法系统及其标识符的完整列表,请参阅:
|
||||
|
||||
- [React Aria Calendar Implementations](https://react-aria.adobe.com/internationalized/date/Calendar#implementations)
|
||||
- [React Aria International Calendars](https://react-aria.adobe.com/Calendar#international-calendars)
|
||||
|
||||
### Related packages
|
||||
|
||||
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
||||
- 本库 `ConfigProvider` — 覆盖子树的 locale
|
||||
- 本库 `ConfigProvider` — 统一 locale 与布局方向
|
||||
|
||||
## Vue 模型、DOM 与当前差异
|
||||
|
||||
- 单选使用 `v-model`(`DateValue | null`),多选设置 `selection-mode="multiple"` 并使用日期数组。`value` 为受控别名;显式 `modelValue` 优先,`defaultValue` 只捕获初始值。`@change` 与 `update:modelValue` 提供复制后的提案,父拒绝不会改变选中显示。
|
||||
- 焦点使用 `v-model:focusedValue`,年份面板使用 `v-model:isYearPickerOpen`。年份选择只改变聚焦年份,不改变已选日期。`defaultFocusedValue` 固定非受控初始视图;跨时区 SSR 建议传入明确日期。
|
||||
- `locale`、`dir` 优先于 ConfigProvider;`timeZone` 用于“今天”标记。显示历法与公开模型历法分离;默认上下界按公历 1900-01-01 至 2099-12-31 转换到显示历法,与上游部分历法的近似年份偏移算法有差异。
|
||||
- 根为 `role="group"`,网格为语义 table/grid,CalendarCell 输出 td/gridcell + 原生 button。`class`、ARIA、DOM 事件落在真正可交互按钮;取消 Cell 的键盘或点击事件可阻止默认处理,祖先需使用捕获事件取消。`isDateDisabled` 完全禁用日期;`isDateUnavailable` 保留焦点但阻止选择。
|
||||
- 左右/上下键移动日期,Home/End 到周边界,PageUp/PageDown 移动月份,Shift+PageUp/PageDown 移动年份;Enter/Space 选择。年份层为三列,方向键与 Home/End 移动,Escape 关闭并恢复触发器。
|
||||
- Calendar 本身不产生原生命名表单输入,也不消费 Label/FieldError 的字段协议;表单字段与 Picker 后续共享 DateField 基建。当前尚未迁移 RangeCalendar、DatePicker 和 TimeField,不把这些能力当作已完成。
|
||||
- `weeksInMonth` 是行数下限,不裁掉真实月份日期。`visibleYears` 是以聚焦年份为中心的窗口;默认显示完整 min/max 年份范围。复杂 era 可通过年份插槽中的 `date` 传给 CalendarYearPickerCell,避免仅凭数字年份混淆。
|
||||
- 键盘适配层针对安装版 Reka 缺少 week/day view、年份层及原生取消缺口使用本地日期视图算法;不运行 React,也不承诺完整 React Aria 类型或全部读屏行为等价。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[DateField 日期字段](./date-field) · [Select 选择器](./select) · [Popover 弹出框](./popover)
|
||||
|
||||
Root 默认插槽还提供 `value`、`isDisabled`、`isReadOnly`、`isInvalid`、`focusedValue`、`visibleRange` 与 `isYearPickerOpen`。Cell 插槽还提供 `date`、`isOutsideVisibleRange`、`isToday`、`isHovered`、`isPressed`、`isFocused`、`isFocusVisible`。使用 `defaultFocusedValue`、`locale`、`dir`、`timeZone`、`isDateDisabled` 可显式设置初始视图、国际化和禁用规则。
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期">
|
||||
<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>
|
||||
</template>
|
||||
@@ -0,0 +1,79 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarCellIndicator,
|
||||
Button,
|
||||
Description,
|
||||
} 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 isDateUnavailable = (date: DateValue) =>
|
||||
isWeekend(date, "en-US") || 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>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
parseDate,
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const focusedDate = shallowRef<DateValue>(parseDate("2025-12-25"));
|
||||
function jump(date: DateValue) {
|
||||
value.value = date;
|
||||
focusedDate.value = date;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<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>
|
||||
<Button @click="jump(startOfMonth(today(getLocalTimeZone())))">
|
||||
本月
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
<Calendar
|
||||
aria-label="活动日期"
|
||||
v-model="value"
|
||||
v-model:focused-value="focusedDate"
|
||||
>
|
||||
<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">
|
||||
{{ value ? `已选择:${value.toString()}` : "未选择日期" }}
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconArrowLeft, IconArrowRight } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期">
|
||||
<CalendarHeader>
|
||||
<CalendarHeading />
|
||||
<CalendarNavButton slot="previous">
|
||||
<IconArrowLeft :size="16" aria-hidden="true" />
|
||||
</CalendarNavButton>
|
||||
<CalendarNavButton slot="next">
|
||||
<IconArrowRight :size="16" aria-hidden="true" />
|
||||
</CalendarNavButton>
|
||||
</CalendarHeader>
|
||||
<CalendarGrid>
|
||||
<CalendarGridHeader v-slot="{ day }">
|
||||
<CalendarHeaderCell>{{ day }}</CalendarHeaderCell>
|
||||
</CalendarGridHeader>
|
||||
<CalendarGridBody v-slot="{ date }">
|
||||
<CalendarCell :date="date" />
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
</template>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar
|
||||
aria-label="自定义样式日历"
|
||||
class="w-63 rounded-2xl border border-border/80 bg-surface p-3 shadow-sm ring-1 ring-accent/5 dark:border-border/90 dark:ring-accent/10"
|
||||
>
|
||||
<CalendarHeader class="px-0.5 pb-4">
|
||||
<CalendarHeading class="text-sm font-medium text-foreground" />
|
||||
<CalendarNavButton
|
||||
class="text-accent-soft-foreground hover:bg-default hover:text-accent-soft-foreground active:scale-95"
|
||||
slot="previous"
|
||||
/>
|
||||
<CalendarNavButton
|
||||
class="text-accent-soft-foreground hover:bg-default hover:text-accent-soft-foreground active:scale-95"
|
||||
slot="next"
|
||||
/>
|
||||
</CalendarHeader>
|
||||
<CalendarGrid>
|
||||
<CalendarGridHeader v-slot="{ day }">
|
||||
<CalendarHeaderCell class="pb-2 text-xs font-medium text-muted">
|
||||
{{ day }}
|
||||
</CalendarHeaderCell>
|
||||
</CalendarGridHeader>
|
||||
<CalendarGridBody v-slot="{ date }">
|
||||
<CalendarCell
|
||||
class="rounded-3xl hover:bg-default data-[hovered=true]:bg-default data-[outside-month=true]:text-muted data-[outside-month=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[selected=true]:hover:bg-accent-hover data-[selected=true]:data-[hovered=true]:bg-accent-hover data-[selected=true]:data-[outside-month=true]:bg-default data-[today=true]:bg-accent-soft data-[today=true]:text-accent-soft-foreground data-[today=true]:hover:bg-accent-soft-hover data-[today=true]:data-[hovered=true]:bg-accent-soft-hover data-[selected=true]:data-[today=true]:bg-accent data-[selected=true]:data-[today=true]:hover:bg-accent-hover"
|
||||
:date="date"
|
||||
/>
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
</template>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref } from "vue";
|
||||
const duration = ref("5");
|
||||
const options = [1, 5, 7, 8, 10, 14, 21];
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-6">
|
||||
<Select v-model="duration" class="w-40">
|
||||
<Label>可见天数</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in options"
|
||||
:key="option"
|
||||
:id="String(option)"
|
||||
:text-value="`${option} 天`"
|
||||
>
|
||||
{{ option }} 天
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<Calendar
|
||||
aria-label="日视图"
|
||||
:visible-duration="{ days: Number(duration) }"
|
||||
>
|
||||
<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>
|
||||
</template>
|
||||
@@ -0,0 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
import { parseDate } from "@internationalized/date";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期" :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>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
</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>
|
||||
</template>
|
||||
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Button,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import { parseDate, type DateValue } from "@internationalized/date";
|
||||
const focusedDate = shallowRef<DateValue>(parseDate("2025-06-15"));
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar aria-label="活动日期" v-model:focused-value="focusedDate">
|
||||
<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">
|
||||
聚焦:{{ focusedDate.toString() }}
|
||||
</Description>
|
||||
<div class="flex flex-wrap justify-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="focusedDate = parseDate('2025-01-01')"
|
||||
>
|
||||
跳转到一月
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="focusedDate = parseDate('2025-06-15')"
|
||||
>
|
||||
跳转到六月
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="focusedDate = parseDate('2025-12-25')"
|
||||
>
|
||||
跳转到圣诞节
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerCell,
|
||||
ConfigProvider,
|
||||
} from "@heroui-vue/components";
|
||||
import { today, getLocalTimeZone } from "@internationalized/date";
|
||||
</script>
|
||||
<template>
|
||||
<ConfigProvider locale="hi-IN-u-ca-indian">
|
||||
<Calendar aria-label="活动日期" :default-value="today(getLocalTimeZone())">
|
||||
<CalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<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>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</Calendar>
|
||||
</ConfigProvider>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { today, getLocalTimeZone } from "@internationalized/date";
|
||||
const now = today(getLocalTimeZone());
|
||||
const maxDate = now.add({ months: 3 });
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar aria-label="预约日期" :min-value="now" :max-value="maxDate">
|
||||
<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">
|
||||
请在今天与 {{ maxDate.toString() }} 之间选择日期。
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar
|
||||
aria-label="行程日期"
|
||||
:visible-duration="{ months: 2 }"
|
||||
class="@container-normal w-full max-w-none overflow-x-auto"
|
||||
>
|
||||
<div class="mx-auto flex w-max gap-8">
|
||||
<div class="w-64">
|
||||
<CalendarHeader>
|
||||
<CalendarHeading class="flex-none" />
|
||||
<CalendarNavButton slot="previous" />
|
||||
<div class="size-6" />
|
||||
</CalendarHeader>
|
||||
<CalendarGrid>
|
||||
<CalendarGridHeader v-slot="{ day }">
|
||||
<CalendarHeaderCell>{{ day }}</CalendarHeaderCell>
|
||||
</CalendarGridHeader>
|
||||
<CalendarGridBody v-slot="{ date }">
|
||||
<CalendarCell :date="date" />
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</div>
|
||||
<div class="w-64">
|
||||
<CalendarHeader>
|
||||
<CalendarHeading class="flex-none" :offset="{ months: 1 }" />
|
||||
<div class="size-6" />
|
||||
<CalendarNavButton slot="next" />
|
||||
</CalendarHeader>
|
||||
<CalendarGrid :offset="{ months: 1 }">
|
||||
<CalendarGridHeader v-slot="{ day }">
|
||||
<CalendarHeaderCell>{{ day }}</CalendarHeaderCell>
|
||||
</CalendarGridHeader>
|
||||
<CalendarGridBody v-slot="{ date }">
|
||||
<CalendarCell :date="date" />
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</div>
|
||||
</div>
|
||||
</Calendar>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
const value = shallowRef<DateValue[] | null>([]);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar aria-label="活动日期" selection-mode="multiple" v-model="value">
|
||||
<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">
|
||||
{{ value?.length ? `已选择 ${value.length} 个日期` : "可选择多个日期" }}
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
} from "@heroui-vue/components";
|
||||
import { parseDate } 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>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { isWeekend, type DateValue } from "@internationalized/date";
|
||||
const isDateUnavailable = (date: DateValue) => isWeekend(date, "en-US");
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar aria-label="预约日期" :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" />
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
<Description class="text-center">周末不可选</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { ref } from "vue";
|
||||
const duration = ref("1");
|
||||
const options = [1, 2, 3, 4, 5, 6, 8];
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-6">
|
||||
<Select v-model="duration" class="w-40">
|
||||
<Label>可见周数</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in options"
|
||||
:key="option"
|
||||
:id="String(option)"
|
||||
:text-value="`${option} 周`"
|
||||
>
|
||||
{{ option }} 周
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
<Calendar
|
||||
aria-label="周视图"
|
||||
:visible-duration="{ weeks: Number(duration) }"
|
||||
>
|
||||
<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>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<Calendar aria-label="活动日期" :weeks-in-month="6">
|
||||
<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">
|
||||
每月固定显示 6 周,切换月份时避免布局跳动
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarCellIndicator,
|
||||
} from "@heroui-vue/components";
|
||||
import { isToday, getLocalTimeZone } from "@internationalized/date";
|
||||
const datesWithEvents = [3, 7, 12, 15, 21, 28];
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期">
|
||||
<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="
|
||||
isToday(date, getLocalTimeZone()) ||
|
||||
datesWithEvents.includes(date.day)
|
||||
"
|
||||
/>
|
||||
</CalendarCell>
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</Calendar>
|
||||
</template>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerCell,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Calendar aria-label="活动日期">
|
||||
<CalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<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>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</Calendar>
|
||||
</template>
|
||||
+89
-85
@@ -2,91 +2,91 @@
|
||||
|
||||
基于固定上游提交的公共组件导出清单。验证中不等于完整兼容;目前没有组件完成视觉、浏览器与完整行为验收。
|
||||
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
|
||||
| calendar | 基建中(DATE-01,未公开) | 月历/多选/非公历/键盘/SSR 探针;公共部件、YearPicker 与 19 预览待实施,见日期基建决策 |
|
||||
| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar-year-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
|
||||
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
|
||||
| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
|
||||
|
||||
## 公共导出差异
|
||||
|
||||
@@ -210,3 +210,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
|
||||
## DOCS-01 文档架构(2026-10-24)
|
||||
|
||||
文档分区导航、布局尺寸、组件分类、预览/代码折叠按固定基线对齐,公共控件复用本库组件。缺少的公共 ComboBox、Table 不在本轮插入迁移,搜索结果和 Markdown API 表保留原生语义。Link/BreadcrumbsItem 省略 target 时不输出该属性,仍为浏览器默认同窗口行为;显式 target 保留。验证范围、视觉差异与未验收项见 [DOCS-01](migrations/DOCS-01-shell-alignment.md)。
|
||||
|
||||
## DATE-03 Calendar / YearPicker
|
||||
|
||||
本轮恢复日期迁移并公开 Calendar/CalendarRoot、日期九部件与 YearPicker 六部件、十九个预览。范围、底座适配依据、DOM/模型/年份层契约及尚未验收能力见 [DATE-03](migrations/DATE-03-calendar.md)。本轮不完成其他日期/时间/颜色组件。
|
||||
|
||||
@@ -73,3 +73,7 @@ Calendar 键盘探针同时发送 key/code;安装版用 code 导航。只发 k
|
||||
本轮公共 DateField/DateInputGroup 已实现,基线正文实际包含 render-function 共 **17** 例,早期 16 例计数更正。新增空值接受协议探针:完整空值提案被拒绝时要清空底座 segmentValues;仅刷新 null 副本不会触发 watch。使用公开注入上下文的局部适配,保持 DOM/焦点不变,见 [DATE-02](../migrations/DATE-02-date-field.md)。该报告和 verification.md 替代本文件此前“没有公开组件验收”的阶段状态。
|
||||
|
||||
用户要求暂停后续日期组件;先做文档整体结构/布局/公共组件对齐。Calendar/YearPicker 仍只是底座探针。
|
||||
|
||||
## DATE-03 接续
|
||||
|
||||
2026-10-24 用户明确恢复集成人迁移。Calendar/YearPicker 已实施公开部件、十九例和局部视图/键盘适配;前述暂停及“只有探针”属于历史阶段。单一模式所有者的取舍、真实差异与验收边界见 [DATE-03](../migrations/DATE-03-calendar.md),Range/Picker/Time 不在本轮完成。
|
||||
|
||||
@@ -314,3 +314,7 @@ DateField 七部件与 DateInputGroup 六部件、17 例已落地,范围和差
|
||||
## 2026-10-24 M35/M36 接手收尾
|
||||
|
||||
后续迁移必读 [M35–M36 多轮复核经验](./migrations/M35-M36-lessons.md)。本轮反复修完已知探针仍遗漏原契约,集成人接手补了 Table 导航/范围/逻辑窗口/列宽/语义和 Toast 默认结构/焦点/测量/隔离/SSR。最终能力以 [验收](./migrations/M35-M36-acceptance.md) 为准;五份 review 是历史失败证据,不是当前限制。公开 Props 从包根导出、独立产物类型反例、原生布局命中区、跨应用实例、完整演示内容都纳入交付清单。
|
||||
|
||||
## DATE-03 集成人接续
|
||||
|
||||
用户恢复日期迁移:Calendar/CalendarYearPicker 的公开部件与 19 个示例已落地,底座缺口使用共享日期视图/键盘薄适配,见 [DATE-03](migrations/DATE-03-calendar.md)。其他 AI 不改写 date/calendar 或 calendar/context;RangeCalendar、Picker/TimeField 由集成人继续。先前暂停日历的文字仅为文档优化阶段记录。
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# DATE-03 Calendar / CalendarYearPicker
|
||||
|
||||
2026-10-24,用户在文档壳层优化后明确继续集成人负责的迁移。工作目录 heroui-vue-core,从同步 main 的 feat/calendar-year-picker 实施;DATE-02 的暂停要求属于此前阶段,本轮恢复日期组件。
|
||||
|
||||
## 基线、范围与来源
|
||||
|
||||
固定 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960:calendar、calendar-day-view-grid-body/header、calendar-year-picker、utils/calendar.ts、同名 CSS/tv、中文 calendar.mdx 与 demos/cn/calendar。原 Apache-2.0 声明保留在 third-party/HEROUI-LICENSE;CSS 数值加 hv- 命名空间,默认 Chevron 路径来自基线 icons.tsx。演示自定义图标使用既有 Tabler Vue,无新依赖。
|
||||
|
||||
公开 Calendar/CalendarRoot、九个普通部件与六个 YearPicker 部件,独立 YearPicker 部件可以从包根导入;Calendar/YearPicker variants、各部件 Props、模型/日期/作用域插槽类型均导出。十九个正文预览按基线次序提供真实 Vue SFC,预览、源码、复制与高亮共用同一文件;新增页面纳入唯一导航清单。
|
||||
|
||||
## 适配决策
|
||||
|
||||
前轮已验证安装版 Reka 2.11.0:仅支持月份数量,缺少统一 week/day visibleDuration 和年份层;Cell 先执行自己的键盘处理,再冒泡给消费者,不能以普通原生取消解决全部模式。因此本轮采用局部日期视图/键盘适配层,不混用两套月/周/日焦点状态,也不修改安装依赖。它使用 @internationalized/date 3.12.4 做日历算术和 locale 转换、既有 useChoiceValue 做接受值协议,类型化 inject 只在该日期组合内共享视图与部件。没有引入另一整库、React 运行时或全局键盘/焦点队列。
|
||||
|
||||
- 月、周、日、offset 多月布局共用 calendarRange/calendarRows;短日窗口紧凑,长日窗口周对齐,前导日期禁用、尾部为空。weeksInMonth 是行数下限,不裁掉真实月份日期。
|
||||
- 选中模型、聚焦日期和可见窗口分开。DateValue 复制保留已选值的 calendar、DateTime 秒/毫秒和 zone;空选中不受显示/聚焦历法影响,默认提案为公历。受控拒绝不会保存乐观选择,同一提案可再次触发。
|
||||
- 聚焦受控拒绝恢复接受的 DOM 日期;外部聚焦月份改变时,只在日期单元格原本持有焦点时保留它,不抢走外部按钮焦点。单步翻页独立移动窗口,不能只改变仍在旧窗口内的焦点。
|
||||
- 根为 group,日期网格是 table/grid,Cell 是 td/gridcell + 原生 button。多选标注 aria-multiselectable,不可用日可键盘聚焦但不能选择。重复的相邻月份补位日期显示但不可操作/对读屏隐藏,避免多月布局同一天出现两个活动目标。
|
||||
- Calendar 不产生原生命名表单值、不另建 Form/field 协议;后续 Picker 组合由字段层承载提交/reset。父 Fieldset 的禁用语义通过现有 disabled scope 继承。
|
||||
- YearPicker 使用三列覆盖层,ResizeObserver 追踪真实日网格的 offsetTop/height;打开定位并聚焦年份,方向/Home/End 导航,选择后恢复日期焦点,Escape 回到触发器。隐藏层 inert/aria-hidden,日期层在年份打开时 inert,取消与受控关闭拒绝分别处理。
|
||||
- 原生事件落到实际按钮,用户处理器先于默认行为;取消点击/键盘不会继续选择/导航。交互插槽和 data 状态提供真实 hover/press/focus/focus-visible。按住 Space/Enter 不重复切换多选,方向键仍可重复导航。
|
||||
|
||||
## 明确差异与边界
|
||||
|
||||
- Vue 使用具名组件、v-model、v-model:focusedValue、v-model:isYearPickerOpen 和作用域插槽;不导出 React 的 YearPickerContext/useCalendarOrRangeState 或 Stately state 对象,不宣称继承 RAC 全部类型。
|
||||
- 默认上下界按公历 1900-01-01 至 2099-12-31 转换到显示历法;上游部分历法采用近似年份偏移。本库使用真实日期转换,差异在公开文档列出。
|
||||
- YearPicker 默认完整上下界年份;visibleYears 限定居中窗口。era 可能重复数字年份时,应将年份插槽的 date 传给 Cell,支持 era/date 扩展而不只凭数字年份识别。
|
||||
- 非公历月/周算术包含 13 月,已做模型/视图验证;未完成所有 era 的手工读屏矩阵,不能挪用 Calendar 结果声明 DateField 13 月分段编辑已完成。
|
||||
- 预订示例沿用周末与 bookedDates 规则,并把基线不可达的标记条件改为实际已预订日期显示点;预订按钮追加内联状态反馈,避免只展示无行为按钮。
|
||||
- 默认空视图取本地今天。跨时区 SSR 传明确 defaultFocusedValue/focusedValue 与 timeZone;未宣称不提供初始日期的跨午夜 SSR 总是一致。
|
||||
- RangeCalendar、TimeField、DatePicker/DateRangePicker、颜色族仍未在本轮实施。
|
||||
|
||||
## 验证
|
||||
|
||||
新增日期视图、公开 DOM/键盘/取消/受控/时区、年份层、十九例同页/ID、真正 Node SSR 和实际 jsdom 水合测试;公共类型在独立 tarball 的 NodeNext 与 bundler 下使用正反例验证。最终完整数量、构建和产物结果见 verification.md。
|
||||
|
||||
5174 真实浏览器重点验证 252px 根宽和 36px 单元格、年份层 208px 高度与当前年滚动可见、选择年份恢复日期焦点、多周 Select/翻页和十日窗口;四张 API 表均 696px 且无横溢出。深浅色与同源 Shiki 已检查。保留浏览器截图,不以它替代进出动画事件或逐像素验收。
|
||||
|
||||
未宣称自动视觉截图差异、完整读屏、物理触屏、全浏览器、Nuxt 或所有日期族验收。下一步按同一值/焦点边界实施 RangeCalendar,再接日期选择弹层与 TimeField,颜色基建排在日期族之后。
|
||||
@@ -198,3 +198,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
固定 ce90ea3 的 `apps/docs/src/components/fumadocs/layouts/notebook`、page/toc、`apps/docs/src/app/global.css`、中文组件 meta/overview、component-preview-container、component-source/codeblock-client 与版本/框架/搜索控件。布局尺寸、导航分区、示例结构适配到 VitePress 和本库 Vue 组件,保留 HeroUI Apache-2.0 来源声明;没有运行时依赖相邻仓库。分类缩略图未复制,缺失组件与搜索/Table 原生语义保留项见 [DOCS-01](migrations/DOCS-01-shell-alignment.md)。
|
||||
|
||||
2026-10-24 视觉返修实际对照官网 components/Button 页面;总览直接引用官方组件目录同源 `heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/related-components/{light,dark}-<name>.png` 设计缩略图(来源规则见固定 `component-item.tsx`)。不下载或重绘媒体,图片失败仍保留本地名称/说明/导航;实际 Vue 演示保持原 SFC。官网为视觉补验依据,不替换固定组件 API 基线。
|
||||
|
||||
## DATE-03 Calendar / YearPicker(2026-10-24)
|
||||
|
||||
固定 ce90ea3 的 calendar、calendar-day-view-grid-body/header、calendar-year-picker、utils/calendar.ts、同名 CSS/tv、中文正文与 19 个演示。样式加 hv- 前缀并保留数值;默认箭头路径取自 icons.tsx,Apache-2.0 声明保留。Vue 的本地日期视图/键盘与既有接受值协议替代不能覆盖所有模式的安装版月历,未复制底层库实现或加入 React 依赖;实际差异与验证见 [DATE-03](migrations/DATE-03-calendar.md)。
|
||||
|
||||
@@ -898,3 +898,11 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
### 左右导航配色与悬浮状态
|
||||
|
||||
实际官网深色导航读数为中性灰 lab(48.496 0 0)、400 字重,与 Tailwind neutral-500 对应;本地原为偏冷的组件 muted/500 字重,现已分离文档导航颜色。普通项中性灰、当前项中性前景,侧栏保留选中表面/阴影,右侧保留章节指示线。两侧导航覆盖装饰线而不更改普通 Link 默认契约,浏览器实际 :hover/data-hovered 状态的 textDecorationLine=none,焦点环不移除。主题深浅色及导航跳转验证,壳层 **12 项**、typecheck、build:docs、格式/diff 检查通过;构建仍有既存 chunk 提示。本轮同时移除上一请求的 Vue 3 标记及废弃样式,框架位置留空。截图 `/private/tmp/heroui-docs-navigation-review.png`,不扩大为整站逐像素验收。
|
||||
|
||||
## DATE-03 Calendar / CalendarYearPicker(2026-10-24)
|
||||
|
||||
- 完整 **73 文件 / 891 项通过**;新增 28 项覆盖日期视图、公开模型/取消/焦点/只读/禁用/多选/重复按键、年份层、十九例同页与唯一 ID、真正 Node SSR 和实际 jsdom 水合。typecheck、build:docs、全仓 Prettier 与 diff 检查通过,仍有既存文档 chunk 体积提示。
|
||||
- Calendar/CalendarRoot、九个日历部件、六个独立 YearPicker 部件、全部 Props 与 variants 已导出;十九个基线 SFC 接入文档与唯一导航清单。源码适配与公开差异见 [DATE-03](migrations/DATE-03-calendar.md)。未继续 Range/Picker/Time/颜色组件。
|
||||
- 5174 浏览器验证月视图实际 252px、日期格 36px,ArrowRight+Enter 聚焦并选择 2026-10-25;年份层高 208px、scrollTop=1340、2026 年真实可见,选择 2027 年关闭并恢复 2027-10-24 日期焦点。周视图切两周后显示 10/18–31,下一页 11/1–14;十天窗口有十个可选日期及两个禁用前导补位。深浅色、同 SFC 高亮及四张 696px 满宽表无横溢出已验,截图 `/private/tmp/heroui-calendar-review.png`。
|
||||
- 最终两份 tarball 独立安装到 `/private/tmp/heroui-slider-consumer`,Calendar ESM/Node SSR/CSS、NodeNext/bundler 严格正反类型通过;单多选、实际泛型 SFC 模型/事件、部件必需属性及作用域插槽反例实际触发诊断。DateField/Select 类型与运行、ListBox 运行消费回归通过,无源码 alias。
|
||||
- 本轮为局部日期视图/键盘适配,复用现有接受值与 Intl 日期库,不宣称 Reka 已具备 week/day/YearPicker。没有自动逐像素、完整读屏、物理触屏、Nuxt 或全部日期族的完成结论。
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* =============================================================================
|
||||
* Calendar Year Picker Component Styles
|
||||
*
|
||||
* Internal component used inside Calendar / RangeCalendar to provide a
|
||||
* toggleable year selector. Uses CSS :has() on the parent .hv-calendar to
|
||||
* drive crossfade transitions.
|
||||
*
|
||||
* The year grid is absolutely positioned and sized via JS to match the
|
||||
* day grid's exact area. This keeps the calendar's original block layout
|
||||
* completely untouched.
|
||||
*
|
||||
* BEM naming: calendar-year-picker__element, calendar-year-picker--modifier
|
||||
* ============================================================================= */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Positioning Context
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar:has(.hv-calendar-year-picker__year-grid),
|
||||
.hv-range-calendar:has(.hv-calendar-year-picker__year-grid) {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Crossfade + Blur Transitions
|
||||
*
|
||||
* The crossfade is staggered to avoid both grids being semi-transparent at
|
||||
* the same time (ghosting). When opening, the day grid fades out first,
|
||||
* then the year grid fades in. When closing, the year grid fades out first,
|
||||
* then the day grid fades in (via transition-delay).
|
||||
*
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
/* Day grid – default visible */
|
||||
.hv-calendar:has(.hv-calendar-year-picker__year-grid)
|
||||
> [data-slot="calendar-grid"],
|
||||
.hv-range-calendar:has(.hv-calendar-year-picker__year-grid)
|
||||
> [data-slot="range-calendar-grid"] {
|
||||
will-change: opacity;
|
||||
transition:
|
||||
opacity 150ms var(--ease-out),
|
||||
visibility 0ms linear;
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Day grid – hidden when year picker is open (fade + blur out) */
|
||||
.hv-calendar:has(.hv-calendar-year-picker__year-grid[data-open="true"])
|
||||
> [data-slot="calendar-grid"],
|
||||
.hv-range-calendar:has(.hv-calendar-year-picker__year-grid[data-open="true"])
|
||||
> [data-slot="range-calendar-grid"] {
|
||||
@apply pointer-events-none opacity-0;
|
||||
visibility: hidden;
|
||||
transition:
|
||||
opacity 150ms var(--ease-out),
|
||||
visibility 0ms linear 150ms;
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Trigger Button
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar-year-picker__trigger {
|
||||
@apply flex flex-1 items-center justify-start gap-1 rounded-lg outline-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
touch-action: manipulation;
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible {
|
||||
@apply status-focused;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar-year-picker__trigger-heading {
|
||||
@apply text-sm font-medium;
|
||||
|
||||
transition: color 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
.hv-calendar-year-picker__trigger-indicator {
|
||||
@apply text-xs text-accent-soft-foreground rtl:[transform:rotate(180deg)];
|
||||
|
||||
transition: transform 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Rotate chevron when open */
|
||||
.hv-calendar-year-picker__trigger[data-open="true"]
|
||||
.hv-calendar-year-picker__trigger-indicator {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.hv-calendar-year-picker__trigger[data-open="true"]
|
||||
.hv-calendar-year-picker__trigger-heading {
|
||||
@apply text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Year Grid Container
|
||||
*
|
||||
* Absolutely positioned over the day grid area. The exact `top` and `height`
|
||||
* are set via JS to match the sibling day grid element.
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar-year-picker__year-grid {
|
||||
@apply pointer-events-none absolute start-0 end-0 grid scrollbar content-start gap-1 overflow-y-auto p-1 opacity-0;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
/* When closing: instant (no transition) */
|
||||
will-change: opacity;
|
||||
}
|
||||
|
||||
.hv-calendar-year-picker__year-grid[data-open="true"] {
|
||||
@apply pointer-events-auto opacity-100;
|
||||
|
||||
/* When opening: slight delay so the day grid starts fading out first */
|
||||
transition: opacity 200ms var(--ease-out) 50ms;
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Year Cell
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar-year-picker__year-cell {
|
||||
@apply relative inline-flex h-8 items-center justify-center rounded-3xl px-2.5 text-sm font-medium outline-none select-none no-highlight;
|
||||
touch-action: manipulation;
|
||||
|
||||
/**
|
||||
* Transitions – same as .tag
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
color 100ms var(--ease-smooth),
|
||||
scale 100ms var(--ease-smooth),
|
||||
opacity 100ms var(--ease-smooth),
|
||||
background-color 100ms var(--ease-smooth),
|
||||
box-shadow 100ms var(--ease-out);
|
||||
@apply origin-center transform-gpu motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Hover state (when not selected) – only on devices that support hover */
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:is(:hover, [data-hovered="true"]):not([data-selected="true"]) {
|
||||
@apply bg-default text-default-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
/* Selected state (current year) – same as .tag[data-selected] */
|
||||
&[data-selected="true"],
|
||||
&[aria-selected="true"] {
|
||||
@apply bg-accent text-accent-foreground;
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:is(:hover, [data-hovered="true"]) {
|
||||
@apply bg-accent-hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible {
|
||||
@apply status-focused;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* =============================================================================
|
||||
* Calendar Component Styles
|
||||
*
|
||||
* A compound component for date selection.
|
||||
* Uses BEM naming convention: calendar, calendar__element, calendar--modifier
|
||||
* ============================================================================= */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Base Calendar Styles
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar {
|
||||
@apply w-63 max-w-63;
|
||||
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
/* Week view – visibleDuration={{ weeks: n }} */
|
||||
.hv-calendar--week-view {
|
||||
.hv-calendar__cell {
|
||||
/* Keep cells circular on the 7-column grid; only filled cells take space. */
|
||||
@apply aspect-square size-auto w-full place-self-center;
|
||||
}
|
||||
}
|
||||
|
||||
/* Day view – visibleDuration={{ days: n }} */
|
||||
.hv-calendar--day-view {
|
||||
.hv-calendar__cell {
|
||||
@apply aspect-square size-auto w-full place-self-center;
|
||||
}
|
||||
|
||||
/*
|
||||
* Isolate header and body into separate 7-column grids. With display:contents
|
||||
* on the root grid, fewer than 7 weekday headers flow into the same row as dates.
|
||||
*/
|
||||
.hv-calendar__grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.hv-calendar__grid-header {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply w-full;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__grid-body {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply mt-1 w-full;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
& > tr:first-child > td {
|
||||
@apply mt-0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Calendar Header
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar__header {
|
||||
@apply flex items-center justify-between px-0.5 pb-4;
|
||||
|
||||
&:has(.hv-calendar-year-picker__trigger[data-open="true"]) {
|
||||
.hv-calendar__nav-button {
|
||||
@apply pointer-events-none opacity-0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__heading {
|
||||
@apply flex-1 text-sm font-medium;
|
||||
}
|
||||
|
||||
.hv-calendar__nav-button {
|
||||
@apply flex size-6 items-center justify-center rounded-2xl text-accent-soft-foreground;
|
||||
|
||||
will-change: scale;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out),
|
||||
background-color 100ms var(--ease-out),
|
||||
box-shadow 100ms var(--ease-out),
|
||||
opacity 150ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Hover state – only on devices that support hover (avoids false triggers on touch) */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-default text-accent-soft-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible,
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__nav-button-icon {
|
||||
@apply size-4 rtl:rotate-180;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Calendar Grid
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar__grid {
|
||||
/* Override table display with CSS Grid for easier customization */
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply w-full;
|
||||
|
||||
&[aria-readonly="true"] {
|
||||
.hv-calendar__cell {
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__grid-header {
|
||||
/* Grid header (thead) styles */
|
||||
display: contents;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__grid-body {
|
||||
/* Grid body (tbody) styles */
|
||||
display: contents;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
/* Add top spacing between header and first body row */
|
||||
& > tr:first-child > td {
|
||||
@apply mt-1;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-calendar__grid-row {
|
||||
/* Use 'contents' so cells participate directly in grid */
|
||||
/* Note: This class can be used for custom row styling if needed */
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.hv-calendar__header-cell {
|
||||
/* Header cell (th - weekday names) styles */
|
||||
@apply flex items-center justify-center pb-2 text-xs font-medium text-muted;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Calendar Cells
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-calendar__cell {
|
||||
/* Cell (td) wrapper styles - margins now work with grid layout */
|
||||
@apply relative flex aspect-square size-full items-center justify-center rounded-3xl text-center text-sm font-medium outline-none no-highlight;
|
||||
|
||||
will-change: scale;
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out),
|
||||
box-shadow 100ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Today indicator */
|
||||
&[data-today="true"] {
|
||||
@apply bg-accent-soft text-accent-soft-foreground;
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover:not([data-selected="true"]),
|
||||
&[data-hovered="true"]:not([data-selected="true"]) {
|
||||
@apply bg-accent-soft-hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Selected state */
|
||||
&[data-selected="true"] {
|
||||
@apply bg-accent text-accent-foreground;
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
@apply bg-default;
|
||||
transform: scale(0.95);
|
||||
|
||||
&[data-selected="true"] {
|
||||
@apply bg-accent-hover;
|
||||
}
|
||||
}
|
||||
|
||||
/* Hover state – only on devices that support hover (avoids false triggers on touch) */
|
||||
@media (hover: hover) {
|
||||
&:hover:not([data-selected="true"]),
|
||||
&[data-hovered="true"]:not([data-selected="true"]) {
|
||||
@apply bg-default;
|
||||
}
|
||||
}
|
||||
|
||||
/* Outside month (previous/next month days) */
|
||||
&[data-outside-month="true"] {
|
||||
@apply text-muted opacity-50;
|
||||
}
|
||||
|
||||
&[data-selected="true"][data-outside-month="true"] {
|
||||
@apply bg-default;
|
||||
}
|
||||
|
||||
/* Unavailable dates */
|
||||
&[data-unavailable="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled:not([data-outside-month="true"]),
|
||||
&[data-disabled="true"]:not([data-outside-month="true"]) {
|
||||
@apply status-disabled;
|
||||
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cell indicator - small dot at bottom center of cell */
|
||||
.hv-calendar__cell-indicator {
|
||||
@apply absolute bottom-1 left-1/2 size-[3px] -translate-x-1/2 rounded-xs bg-muted;
|
||||
|
||||
/* Indicator color changes when cell is selected */
|
||||
[data-selected="true"] > & {
|
||||
@apply bg-accent-foreground;
|
||||
}
|
||||
}
|
||||
@@ -154,3 +154,7 @@
|
||||
|
||||
@import "./components/date-input-group.css" layer(components);
|
||||
@import "./components/date-field.css" layer(components);
|
||||
|
||||
@import "./components/calendar.css" layer(components);
|
||||
|
||||
@import "./components/calendar-year-picker.css" layer(components);
|
||||
|
||||
@@ -1580,3 +1580,50 @@ export const tableVariants = tv({
|
||||
});
|
||||
|
||||
export type TableVariants = VariantProps<typeof tableVariants>;
|
||||
|
||||
export const calendarVariants = tv({
|
||||
defaultVariants: {},
|
||||
slots: {
|
||||
/** Root calendar container */
|
||||
base: "hv-calendar",
|
||||
/** Calendar cell (td) */
|
||||
cell: "hv-calendar__cell",
|
||||
/** Cell indicator (small dot at bottom of cell) */
|
||||
cellIndicator: "hv-calendar__cell-indicator",
|
||||
/** Calendar grid (table) */
|
||||
grid: "hv-calendar__grid",
|
||||
/** Grid body (tbody) */
|
||||
gridBody: "hv-calendar__grid-body",
|
||||
/** Grid header (thead) */
|
||||
gridHeader: "hv-calendar__grid-header",
|
||||
/** Grid row (tr) */
|
||||
gridRow: "hv-calendar__grid-row",
|
||||
/** Calendar header containing heading and navigation */
|
||||
header: "hv-calendar__header",
|
||||
/** Header cell (th - day names) */
|
||||
headerCell: "hv-calendar__header-cell",
|
||||
/** Month/year heading text */
|
||||
heading: "hv-calendar__heading",
|
||||
/** Previous/Next navigation button */
|
||||
navButton: "hv-calendar__nav-button",
|
||||
/** Navigation button icon */
|
||||
navButtonIcon: "hv-calendar__nav-button-icon",
|
||||
},
|
||||
variants: {},
|
||||
});
|
||||
|
||||
export type CalendarVariants = VariantProps<typeof calendarVariants>;
|
||||
|
||||
export const calendarYearPickerVariants = tv({
|
||||
slots: {
|
||||
trigger: "hv-calendar-year-picker__trigger",
|
||||
triggerHeading: "hv-calendar-year-picker__trigger-heading",
|
||||
triggerIndicator: "hv-calendar-year-picker__trigger-indicator",
|
||||
yearCell: "hv-calendar-year-picker__year-cell",
|
||||
yearGrid: "hv-calendar-year-picker__year-grid",
|
||||
},
|
||||
});
|
||||
|
||||
export type CalendarYearPickerVariants = VariantProps<
|
||||
typeof calendarYearPickerVariants
|
||||
>;
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
<script setup lang="ts" generic="M extends CalendarSelectionMode = 'single'">
|
||||
import {
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
nextTick,
|
||||
onMounted,
|
||||
onBeforeUnmount,
|
||||
provide,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
useId,
|
||||
watch,
|
||||
} from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
GregorianCalendar,
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
toCalendar,
|
||||
toCalendarDate,
|
||||
isSameDay,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import {
|
||||
copyDateValue,
|
||||
copyDateValues,
|
||||
dateForLocale,
|
||||
dateValueKey,
|
||||
} from "../date/value";
|
||||
import {
|
||||
calendarRange,
|
||||
calendarDuration,
|
||||
calendarHeading,
|
||||
} from "../date/calendar";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import {
|
||||
calendarKey,
|
||||
type CalendarModel,
|
||||
type CalendarOptions,
|
||||
type CalendarSelectionMode,
|
||||
type CalendarContext,
|
||||
} from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<CalendarOptions<M>>();
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: CalendarModel<M>];
|
||||
change: [value: CalendarModel<M>];
|
||||
"update:focusedValue": [value: DateValue];
|
||||
focusChange: [value: DateValue];
|
||||
"update:isYearPickerOpen": [value: boolean];
|
||||
yearPickerOpenChange: [value: boolean];
|
||||
}>();
|
||||
defineSlots<{
|
||||
default?: (state: {
|
||||
value: CalendarModel<M>;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
isInvalid: boolean;
|
||||
focusedValue: DateValue;
|
||||
visibleRange: { start: DateValue; end: DateValue };
|
||||
isYearPickerOpen: boolean;
|
||||
}) => unknown;
|
||||
}>();
|
||||
const attrs = useAttrs(),
|
||||
instance = getCurrentInstance()!,
|
||||
config = useConfig();
|
||||
const root = shallowRef<HTMLElement>(),
|
||||
trigger = shallowRef<HTMLElement>();
|
||||
const headingId = `hv-calendar-${useId()}-heading`;
|
||||
const locale = computed(() => props.locale ?? config?.locale.value ?? "en-US");
|
||||
const dir = computed(() => props.dir ?? config?.dir.value ?? "ltr");
|
||||
const timeZone = computed(() => props.timeZone ?? getLocalTimeZone());
|
||||
const disabled = useInheritedDisabled(() => props.isDisabled || props.disabled);
|
||||
const readOnly = computed(() => !!props.isReadOnly);
|
||||
const multiple = computed(() => props.selectionMode === "multiple");
|
||||
const invalid = computed(() => !!props.isInvalid);
|
||||
const options = computed(() => ({
|
||||
locale: locale.value,
|
||||
firstDayOfWeek: props.firstDayOfWeek,
|
||||
visibleDuration: props.visibleDuration,
|
||||
weeksInMonth: props.weeksInMonth,
|
||||
}));
|
||||
type Value = DateValue | DateValue[] | null;
|
||||
const copy = (value: Value | undefined): Value =>
|
||||
Array.isArray(value) ? copyDateValues(value) : copyDateValue(value ?? null);
|
||||
const has = (key: string) => Object.hasOwn(instance.vnode.props ?? {}, key);
|
||||
const model = useChoiceValue<Value>(
|
||||
() =>
|
||||
copy(
|
||||
has("modelValue") || has("model-value") ? props.modelValue : props.value,
|
||||
),
|
||||
() => copy(props.defaultValue),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => {
|
||||
emit("update:modelValue", copy(value) as CalendarModel<M>);
|
||||
emit("change", copy(value) as CalendarModel<M>);
|
||||
},
|
||||
);
|
||||
const selectedValues = computed(() => {
|
||||
const value = model.value.value;
|
||||
return Array.isArray(value) ? value : value ? [value] : [];
|
||||
});
|
||||
const initial = copyDateValue(
|
||||
props.defaultFocusedValue ?? selectedValues.value[0] ?? today(timeZone.value),
|
||||
);
|
||||
const focusModel = useChoiceValue<DateValue>(
|
||||
() => copyDateValue(props.focusedValue ?? initial),
|
||||
() => copyDateValue(initial),
|
||||
["focusedValue", "focused-value"],
|
||||
(value) => {
|
||||
emit("update:focusedValue", value.copy());
|
||||
emit("focusChange", value.copy());
|
||||
},
|
||||
);
|
||||
const focus = computed(() =>
|
||||
toCalendarDate(dateForLocale(focusModel.value.value, locale.value)),
|
||||
);
|
||||
const min = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(props.minValue ?? new CalendarDate(1900, 1, 1), locale.value),
|
||||
),
|
||||
);
|
||||
const max = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(
|
||||
props.maxValue ?? new CalendarDate(2099, 12, 31),
|
||||
locale.value,
|
||||
),
|
||||
),
|
||||
);
|
||||
function aligned(date: typeof focus.value) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
const alignment = props.selectionAlignment ?? "center";
|
||||
const amount =
|
||||
alignment === "start"
|
||||
? 0
|
||||
: alignment === "end"
|
||||
? count - 1
|
||||
: Math.floor((count - 1) / 2);
|
||||
return date.subtract({ [unit]: amount });
|
||||
}
|
||||
const anchor = shallowRef(aligned(focus.value));
|
||||
const visible = computed(() => calendarRange(anchor.value, options.value));
|
||||
const yearModel = useChoiceValue(
|
||||
() => !!props.isYearPickerOpen,
|
||||
() => !!props.defaultYearPickerOpen,
|
||||
["isYearPickerOpen", "is-year-picker-open"],
|
||||
(value) => {
|
||||
emit("update:isYearPickerOpen", value);
|
||||
emit("yearPickerOpenChange", value);
|
||||
},
|
||||
);
|
||||
const yearOpen = computed(() => yearModel.value.value);
|
||||
function disabledDay(value: DateValue) {
|
||||
return (
|
||||
disabled.value ||
|
||||
toCalendarDate(value).compare(min.value) < 0 ||
|
||||
toCalendarDate(value).compare(max.value) > 0 ||
|
||||
!!props.isDateDisabled?.(value.copy())
|
||||
);
|
||||
}
|
||||
const tabStop = computed(() => {
|
||||
const range = visible.value;
|
||||
if (
|
||||
!disabledDay(focus.value) &&
|
||||
focus.value.compare(range.start) >= 0 &&
|
||||
focus.value.compare(range.end) <= 0
|
||||
)
|
||||
return focus.value;
|
||||
let date = range.start;
|
||||
while (date.compare(range.end) <= 0) {
|
||||
if (!disabledDay(date)) return date;
|
||||
const next = date.add({ days: 1 });
|
||||
if (isSameDay(date, next)) break;
|
||||
date = next;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const unavailable = (date: DateValue) =>
|
||||
!!props.isDateUnavailable?.(date.copy());
|
||||
const selected = (date: DateValue) =>
|
||||
selectedValues.value.some((value) => isSameDay(value, date));
|
||||
function request(value: DateValue) {
|
||||
if (disabledDay(value) || unavailable(value) || readOnly.value) return;
|
||||
const fallback = Array.isArray(props.defaultValue)
|
||||
? props.defaultValue[0]
|
||||
: props.defaultValue;
|
||||
const original =
|
||||
selectedValues.value[0] ??
|
||||
fallback ??
|
||||
toCalendarDate(toCalendar(focus.value, new GregorianCalendar()));
|
||||
// Preserve the public model's calendar, date class, time and zone.
|
||||
const day = toCalendar(value, original.calendar);
|
||||
const next = original.set({
|
||||
era: day.era,
|
||||
year: day.year,
|
||||
month: day.month,
|
||||
day: day.day,
|
||||
});
|
||||
if (props.selectionMode === "multiple") {
|
||||
const values = selectedValues.value;
|
||||
model.request(
|
||||
selected(value)
|
||||
? copyDateValues(values.filter((date) => !isSameDay(date, value)))
|
||||
: copyDateValues([...values, next]),
|
||||
);
|
||||
} else if (!selected(value)) model.request(next.copy());
|
||||
}
|
||||
function focusDate(date: DateValue, moveDOM = false) {
|
||||
if (disabledDay(date)) return;
|
||||
const original = focusModel.value.value;
|
||||
const converted = toCalendar(date, original.calendar);
|
||||
if (!isSameDay(original, converted)) focusModel.request(converted.copy());
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const restoreControlledFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === "calendar-cell";
|
||||
if (moveDOM || restoreControlledFocus)
|
||||
void nextTick(() => {
|
||||
if (yearOpen.value) return;
|
||||
const iso = (tabStop.value ?? focus.value).toString();
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="calendar-cell"][data-date="${iso}"]:not([data-outside-month])`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => dateValueKey(focus.value),
|
||||
() => {
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const retainFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === "calendar-cell";
|
||||
if (
|
||||
focus.value.compare(visible.value.start) < 0 ||
|
||||
focus.value.compare(visible.value.end) > 0
|
||||
)
|
||||
anchor.value = aligned(focus.value);
|
||||
if (retainFocus)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value)
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="calendar-cell"][tabindex="0"]`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[locale, () => props.visibleDuration, () => props.firstDayOfWeek],
|
||||
() => {
|
||||
anchor.value = aligned(focus.value);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
watch(
|
||||
() => selectedValues.value.map(dateValueKey).join("|"),
|
||||
() => {
|
||||
if (
|
||||
!has("focusedValue") &&
|
||||
!has("focused-value") &&
|
||||
selectedValues.value[0]
|
||||
)
|
||||
focusDate(selectedValues.value[0]);
|
||||
},
|
||||
);
|
||||
function pageStep(direction: -1 | 1) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
return { [unit]: direction * (props.pageBehavior === "single" ? 1 : count) };
|
||||
}
|
||||
function pageDisabled(direction: -1 | 1) {
|
||||
if (disabled.value || yearOpen.value) return true;
|
||||
const range = calendarRange(
|
||||
anchor.value.add(pageStep(direction)),
|
||||
options.value,
|
||||
);
|
||||
return range.end.compare(min.value) < 0 || range.start.compare(max.value) > 0;
|
||||
}
|
||||
let pageRevision = 0;
|
||||
onBeforeUnmount(() => {
|
||||
pageRevision++;
|
||||
});
|
||||
function page(direction: -1 | 1) {
|
||||
if (pageDisabled(direction)) return;
|
||||
const nextAnchor = anchor.value.add(pageStep(direction));
|
||||
const range = calendarRange(nextAnchor, options.value);
|
||||
let date = focus.value.add(pageStep(direction));
|
||||
if (date.compare(min.value) < 0) date = min.value;
|
||||
if (date.compare(max.value) > 0) date = max.value;
|
||||
// Disabled target days must not make an otherwise navigable month inert.
|
||||
if (disabledDay(date)) {
|
||||
let candidate = range.start;
|
||||
while (candidate.compare(range.end) <= 0 && disabledDay(candidate)) {
|
||||
const next = candidate.add({ days: 1 });
|
||||
if (isSameDay(candidate, next)) return;
|
||||
candidate = next;
|
||||
}
|
||||
if (candidate.compare(range.end) > 0) return;
|
||||
date = candidate;
|
||||
}
|
||||
focusDate(date);
|
||||
const revision = ++pageRevision;
|
||||
void nextTick(() => {
|
||||
if (revision === pageRevision && isSameDay(focus.value, date))
|
||||
anchor.value = nextAnchor;
|
||||
});
|
||||
}
|
||||
function setYearOpen(value: boolean, restore = false) {
|
||||
if (disabled.value) return;
|
||||
yearModel.request(value);
|
||||
if (!value && restore)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value) trigger.value?.focus();
|
||||
});
|
||||
}
|
||||
provide(calendarKey, {
|
||||
root,
|
||||
trigger,
|
||||
focus,
|
||||
anchor,
|
||||
options,
|
||||
min,
|
||||
max,
|
||||
disabled,
|
||||
tabStop,
|
||||
readOnly,
|
||||
multiple,
|
||||
invalid,
|
||||
dir,
|
||||
timeZone,
|
||||
yearOpen,
|
||||
headingId,
|
||||
selected,
|
||||
disabledDay,
|
||||
unavailable,
|
||||
request,
|
||||
focusDate,
|
||||
page,
|
||||
pageDisabled,
|
||||
setYearOpen,
|
||||
} satisfies CalendarContext);
|
||||
onMounted(() => {
|
||||
if (props.autoFocus && tabStop.value) focusDate(tabStop.value, true);
|
||||
});
|
||||
defineExpose({
|
||||
get element() {
|
||||
return root.value;
|
||||
},
|
||||
focus: () => {
|
||||
if (tabStop.value) focusDate(tabStop.value, true);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as ?? 'div'"
|
||||
ref="root"
|
||||
v-bind="attrs"
|
||||
class="hv-calendar"
|
||||
:class="{
|
||||
'hv-calendar--week-view': visible.unit === 'weeks',
|
||||
'hv-calendar--day-view': visible.unit === 'days',
|
||||
}"
|
||||
role="group"
|
||||
:aria-label="
|
||||
(attrs['aria-label'] as string | undefined) ??
|
||||
(attrs['aria-labelledby'] ? undefined : calendarHeading(anchor, options))
|
||||
"
|
||||
:dir="dir"
|
||||
:data-slot="'calendar'"
|
||||
:data-disabled="disabled || undefined"
|
||||
:aria-disabled="disabled || undefined"
|
||||
:aria-invalid="isInvalid || undefined"
|
||||
>
|
||||
<slot
|
||||
:value="copy(model.value.value) as CalendarModel<M>"
|
||||
:is-disabled="disabled"
|
||||
:is-read-only="readOnly"
|
||||
:is-invalid="invalid"
|
||||
:focused-value="focus"
|
||||
:visible-range="{ start: visible.start, end: visible.end }"
|
||||
:is-year-picker-open="yearOpen"
|
||||
/>
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,122 @@
|
||||
import {
|
||||
inject,
|
||||
type ComputedRef,
|
||||
type InjectionKey,
|
||||
type ShallowRef,
|
||||
} from "vue";
|
||||
import type { CalendarDate, DateValue } from "@internationalized/date";
|
||||
import type {
|
||||
CalendarDuration,
|
||||
CalendarViewOptions,
|
||||
CalendarWeekday,
|
||||
} from "../date/calendar";
|
||||
export type CalendarSelectionMode = "single" | "multiple";
|
||||
export type CalendarModel<M extends CalendarSelectionMode = "single"> =
|
||||
M extends "multiple" ? DateValue[] | null : DateValue | null;
|
||||
export interface CalendarOptions<M extends CalendarSelectionMode = "single"> {
|
||||
modelValue?: CalendarModel<M>;
|
||||
value?: CalendarModel<M>;
|
||||
defaultValue?: CalendarModel<M>;
|
||||
selectionMode?: M;
|
||||
focusedValue?: DateValue;
|
||||
defaultFocusedValue?: DateValue;
|
||||
minValue?: DateValue;
|
||||
maxValue?: DateValue;
|
||||
visibleDuration?: CalendarDuration;
|
||||
firstDayOfWeek?: CalendarWeekday;
|
||||
weeksInMonth?: number;
|
||||
pageBehavior?: "visible" | "single";
|
||||
selectionAlignment?: "start" | "center" | "end";
|
||||
isDateUnavailable?: (date: DateValue) => boolean;
|
||||
isDateDisabled?: (date: DateValue) => boolean;
|
||||
isDisabled?: boolean;
|
||||
disabled?: boolean;
|
||||
isReadOnly?: boolean;
|
||||
isInvalid?: boolean;
|
||||
autoFocus?: boolean;
|
||||
isYearPickerOpen?: boolean;
|
||||
defaultYearPickerOpen?: boolean;
|
||||
locale?: string;
|
||||
dir?: "ltr" | "rtl";
|
||||
timeZone?: string;
|
||||
as?: string;
|
||||
}
|
||||
export interface CalendarCellState {
|
||||
date: DateValue;
|
||||
formattedDate: string;
|
||||
isSelected: boolean;
|
||||
isUnavailable: boolean;
|
||||
isDisabled: boolean;
|
||||
isOutsideMonth: boolean;
|
||||
isOutsideVisibleRange: boolean;
|
||||
isToday: boolean;
|
||||
isFocused: boolean;
|
||||
isFocusVisible: boolean;
|
||||
isHovered: boolean;
|
||||
isPressed: boolean;
|
||||
}
|
||||
export interface CalendarContext {
|
||||
root: ShallowRef<HTMLElement | undefined>;
|
||||
trigger: ShallowRef<HTMLElement | undefined>;
|
||||
focus: ComputedRef<CalendarDate>;
|
||||
anchor: ShallowRef<CalendarDate>;
|
||||
options: ComputedRef<CalendarViewOptions>;
|
||||
min: ComputedRef<CalendarDate>;
|
||||
max: ComputedRef<CalendarDate>;
|
||||
tabStop: ComputedRef<CalendarDate | undefined>;
|
||||
disabled: ComputedRef<boolean>;
|
||||
readOnly: ComputedRef<boolean>;
|
||||
multiple: ComputedRef<boolean>;
|
||||
invalid: ComputedRef<boolean>;
|
||||
dir: ComputedRef<"ltr" | "rtl">;
|
||||
timeZone: ComputedRef<string>;
|
||||
yearOpen: ComputedRef<boolean>;
|
||||
headingId: string;
|
||||
selected: (value: DateValue) => boolean;
|
||||
disabledDay: (value: DateValue) => boolean;
|
||||
unavailable: (value: DateValue) => boolean;
|
||||
request: (value: DateValue) => void;
|
||||
focusDate: (value: DateValue, moveDOM?: boolean) => void;
|
||||
page: (direction: -1 | 1) => void;
|
||||
pageDisabled: (direction: -1 | 1) => boolean;
|
||||
setYearOpen: (value: boolean, restore?: boolean) => void;
|
||||
}
|
||||
export const calendarKey: InjectionKey<CalendarContext> = Symbol("hv-calendar");
|
||||
export function useCalendar() {
|
||||
const value = inject(calendarKey, undefined);
|
||||
if (!value) throw new Error("Calendar parts require Calendar.");
|
||||
return value;
|
||||
}
|
||||
export const calendarGridKey: InjectionKey<
|
||||
ComputedRef<{
|
||||
rows: (CalendarDate | null)[][];
|
||||
month: CalendarDate;
|
||||
weekdays: string[];
|
||||
}>
|
||||
> = Symbol("hv-calendar-grid");
|
||||
export function useCalendarGrid() {
|
||||
const value = inject(calendarGridKey, undefined);
|
||||
if (!value) throw new Error("Calendar grid parts require CalendarGrid.");
|
||||
return value;
|
||||
}
|
||||
export interface CalendarYearState {
|
||||
year: number;
|
||||
date: CalendarDate;
|
||||
formattedYear: string;
|
||||
isSelected: boolean;
|
||||
isCurrentYear: boolean;
|
||||
isOpen: boolean;
|
||||
selectYear: () => void;
|
||||
}
|
||||
export const calendarYearKey: InjectionKey<{
|
||||
entries: ComputedRef<CalendarDate[]>;
|
||||
active: ShallowRef<string>;
|
||||
label: (date: CalendarDate) => string;
|
||||
state: (date: CalendarDate) => CalendarYearState;
|
||||
select: (date: CalendarDate) => void;
|
||||
}> = Symbol("hv-calendar-years");
|
||||
export function useCalendarYears() {
|
||||
const value = inject(calendarYearKey, undefined);
|
||||
if (!value) throw new Error("Year cells require CalendarYearPickerGrid.");
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,533 @@
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
mergeProps,
|
||||
provide,
|
||||
ref,
|
||||
watch,
|
||||
useId,
|
||||
type PropType,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import {
|
||||
DateFormatter,
|
||||
endOfWeek,
|
||||
startOfWeek,
|
||||
isSameDay,
|
||||
isSameMonth,
|
||||
isToday,
|
||||
type DateDuration,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
calendarHeading,
|
||||
calendarRange,
|
||||
calendarRows,
|
||||
calendarWeekdays,
|
||||
} from "../date/calendar";
|
||||
import {
|
||||
calendarGridKey,
|
||||
useCalendar,
|
||||
useCalendarGrid,
|
||||
type CalendarCellState,
|
||||
} from "./context";
|
||||
|
||||
/** Default chevrons ported from ce90ea3 icons.tsx, Apache-2.0. */
|
||||
export function calendarChevron(
|
||||
previous = false,
|
||||
className = "hv-calendar__nav-button-icon",
|
||||
) {
|
||||
return h(
|
||||
"svg",
|
||||
{
|
||||
class: className,
|
||||
"aria-hidden": "true",
|
||||
role: "presentation",
|
||||
fill: "none",
|
||||
width: 16,
|
||||
height: 16,
|
||||
viewBox: "0 0 16 16",
|
||||
},
|
||||
[
|
||||
h("path", {
|
||||
d: previous
|
||||
? "M10.53 2.97a.75.75 0 0 1 0 1.06L6.56 8l3.97 3.97a.75.75 0 1 1-1.06 1.06l-4.5-4.5a.75.75 0 0 1 0-1.06l4.5-4.5a.75.75 0 0 1 1.06 0"
|
||||
: "M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z",
|
||||
fill: "currentColor",
|
||||
"fill-rule": "evenodd",
|
||||
"clip-rule": "evenodd",
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
function staticPart(
|
||||
name: string,
|
||||
tag: string,
|
||||
className: string,
|
||||
slot: string,
|
||||
) {
|
||||
return defineComponent({
|
||||
name,
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: tag } },
|
||||
setup(props, { attrs, slots }) {
|
||||
useCalendar();
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(
|
||||
{
|
||||
class: className,
|
||||
"data-slot": slot,
|
||||
"aria-hidden":
|
||||
slot === "calendar-cell-indicator" ? "true" : undefined,
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
export const CalendarHeader = staticPart(
|
||||
"CalendarHeader",
|
||||
"header",
|
||||
"hv-calendar__header",
|
||||
"calendar-header",
|
||||
);
|
||||
export const CalendarHeaderCell = staticPart(
|
||||
"CalendarHeaderCell",
|
||||
"th",
|
||||
"hv-calendar__header-cell",
|
||||
"calendar-header-cell",
|
||||
);
|
||||
export const CalendarCellIndicator = staticPart(
|
||||
"CalendarCellIndicator",
|
||||
"span",
|
||||
"hv-calendar__cell-indicator",
|
||||
"calendar-cell-indicator",
|
||||
);
|
||||
export const CalendarHeading = defineComponent({
|
||||
name: "CalendarHeading",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "h2" },
|
||||
offset: Object as PropType<DateDuration>,
|
||||
format: Object as PropType<Intl.DateTimeFormatOptions>,
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar(),
|
||||
id = `hv-calendar-heading-${useId()}`;
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(
|
||||
{
|
||||
id,
|
||||
class: "hv-calendar__heading",
|
||||
"data-slot": "calendar-heading",
|
||||
"aria-live": "polite",
|
||||
"aria-atomic": "true",
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
slots.default?.() ??
|
||||
calendarHeading(
|
||||
ctx.anchor.value,
|
||||
ctx.options.value,
|
||||
props.offset,
|
||||
props.format,
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarNavButton = defineComponent({
|
||||
name: "CalendarNavButton",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
slot: { type: String as PropType<"previous" | "next">, default: "next" },
|
||||
isDisabled: Boolean,
|
||||
disabled: Boolean,
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
return () => {
|
||||
const direction = props.slot === "previous" ? -1 : 1;
|
||||
const disabled =
|
||||
props.isDisabled || props.disabled || ctx.pageDisabled(direction);
|
||||
return h(
|
||||
"button",
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
class: "hv-calendar__nav-button",
|
||||
"aria-label": direction === -1 ? "Previous" : "Next",
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
"data-slot": "calendar-nav-button",
|
||||
disabled,
|
||||
tabindex: ctx.yearOpen.value ? -1 : attrs.tabindex,
|
||||
"data-disabled": disabled || undefined,
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (!event.defaultPrevented && !disabled) ctx.page(direction);
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.() ?? [calendarChevron(direction === -1)],
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
export const CalendarGrid = defineComponent({
|
||||
name: "CalendarGrid",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
offset: Object as PropType<DateDuration>,
|
||||
weekdayStyle: {
|
||||
type: String as PropType<"narrow" | "short" | "long">,
|
||||
default: "short",
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
const grid = computed(() => ({
|
||||
...calendarRows(ctx.anchor.value, ctx.options.value, props.offset),
|
||||
weekdays: calendarWeekdays(
|
||||
ctx.anchor.value,
|
||||
ctx.options.value,
|
||||
props.weekdayStyle,
|
||||
),
|
||||
}));
|
||||
provide(calendarGridKey, grid);
|
||||
return () =>
|
||||
h(
|
||||
"table",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid",
|
||||
role: "grid",
|
||||
"aria-label": calendarHeading(
|
||||
ctx.anchor.value,
|
||||
ctx.options.value,
|
||||
props.offset,
|
||||
),
|
||||
"aria-readonly": ctx.readOnly.value || undefined,
|
||||
"aria-invalid": ctx.invalid.value || undefined,
|
||||
"aria-multiselectable": ctx.multiple.value || undefined,
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
"data-slot": "calendar-grid",
|
||||
"aria-hidden": ctx.yearOpen.value || undefined,
|
||||
inert: ctx.yearOpen.value ? "" : undefined,
|
||||
},
|
||||
),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarGridHeader = defineComponent({
|
||||
name: "CalendarGridHeader",
|
||||
inheritAttrs: false,
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: { day: string; index: number }) => VNodeChild;
|
||||
}>,
|
||||
setup(_props, { attrs, slots }) {
|
||||
const grid = useCalendarGrid();
|
||||
return () =>
|
||||
h(
|
||||
"thead",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid-header",
|
||||
"data-slot": "calendar-grid-header",
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
[
|
||||
h(
|
||||
"tr",
|
||||
grid.value.weekdays.map(
|
||||
(day, index) =>
|
||||
slots.default?.({ day, index }) ??
|
||||
h(CalendarHeaderCell, { key: index }, () => day),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarGridBody = defineComponent({
|
||||
name: "CalendarGridBody",
|
||||
inheritAttrs: false,
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: { date: DateValue }) => VNodeChild;
|
||||
}>,
|
||||
setup(_props, { attrs, slots }) {
|
||||
const grid = useCalendarGrid();
|
||||
return () =>
|
||||
h(
|
||||
"tbody",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid-body",
|
||||
"data-slot": "calendar-grid-body",
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
grid.value.rows.map((row, index) =>
|
||||
h(
|
||||
"tr",
|
||||
{ key: index, class: "hv-calendar__grid-row" },
|
||||
row.map((date, index) =>
|
||||
date
|
||||
? (slots.default?.({ date: date.copy() }) ??
|
||||
h(CalendarCell, { date, key: date.toString() }))
|
||||
: h("td", { key: `empty-${index}`, "aria-hidden": "true" }),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarCell = defineComponent({
|
||||
name: "CalendarCell",
|
||||
inheritAttrs: false,
|
||||
props: { date: { type: Object as PropType<DateValue>, required: true } },
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: CalendarCellState) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots, expose }) {
|
||||
const ctx = useCalendar(),
|
||||
grid = useCalendarGrid();
|
||||
const hovered = ref(false),
|
||||
pressed = ref(false),
|
||||
focused = ref(false),
|
||||
focusVisible = ref(false);
|
||||
let element: HTMLButtonElement | undefined;
|
||||
expose({
|
||||
get element() {
|
||||
return element;
|
||||
},
|
||||
focus: () => element?.focus(),
|
||||
});
|
||||
const state = computed<CalendarCellState>(() => {
|
||||
const range = calendarRange(ctx.anchor.value, ctx.options.value);
|
||||
const outside =
|
||||
props.date.compare(range.start) < 0 ||
|
||||
props.date.compare(range.end) > 0;
|
||||
const outsideMonth =
|
||||
range.unit === "months" && !isSameMonth(props.date, grid.value.month);
|
||||
return {
|
||||
date: props.date.copy(),
|
||||
formattedDate: props.date.day.toLocaleString(ctx.options.value.locale),
|
||||
isSelected: ctx.selected(props.date),
|
||||
isUnavailable: ctx.unavailable(props.date),
|
||||
isDisabled: outside || outsideMonth || ctx.disabledDay(props.date),
|
||||
isOutsideMonth: outsideMonth,
|
||||
isOutsideVisibleRange: outside,
|
||||
isToday: isToday(props.date, ctx.timeZone.value),
|
||||
isFocused: focused.value,
|
||||
isHovered: hovered.value,
|
||||
isPressed: pressed.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
};
|
||||
});
|
||||
watch(
|
||||
() => state.value.isDisabled || ctx.readOnly.value,
|
||||
(value) => {
|
||||
if (value) {
|
||||
hovered.value = false;
|
||||
pressed.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
function keydown(event: KeyboardEvent) {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.isComposing ||
|
||||
(event.repeat && (event.key === " " || event.key === "Enter")) ||
|
||||
state.value.isDisabled ||
|
||||
ctx.yearOpen.value ||
|
||||
event.metaKey ||
|
||||
event.ctrlKey ||
|
||||
event.altKey
|
||||
)
|
||||
return;
|
||||
const date = props.date;
|
||||
const sign = ctx.dir.value === "rtl" ? -1 : 1;
|
||||
let target: DateValue;
|
||||
let step = 1;
|
||||
switch (event.key) {
|
||||
case "ArrowLeft":
|
||||
step = -sign;
|
||||
target = date.add({ days: step });
|
||||
break;
|
||||
case "ArrowRight":
|
||||
step = sign;
|
||||
target = date.add({ days: step });
|
||||
break;
|
||||
case "ArrowUp":
|
||||
step = -7;
|
||||
target = date.add({ days: step });
|
||||
break;
|
||||
case "ArrowDown":
|
||||
step = 7;
|
||||
target = date.add({ days: step });
|
||||
break;
|
||||
case "Home":
|
||||
target = startOfWeek(
|
||||
date,
|
||||
ctx.options.value.locale,
|
||||
ctx.options.value.firstDayOfWeek,
|
||||
);
|
||||
break;
|
||||
case "End":
|
||||
target = endOfWeek(
|
||||
date,
|
||||
ctx.options.value.locale,
|
||||
ctx.options.value.firstDayOfWeek,
|
||||
);
|
||||
step = -1;
|
||||
break;
|
||||
case "PageUp":
|
||||
step = -1;
|
||||
target = date.subtract(event.shiftKey ? { years: 1 } : { months: 1 });
|
||||
break;
|
||||
case "PageDown":
|
||||
target = date.add(event.shiftKey ? { years: 1 } : { months: 1 });
|
||||
break;
|
||||
case "Enter":
|
||||
case " ":
|
||||
event.preventDefault();
|
||||
pressed.value = true;
|
||||
ctx.request(date);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (target.compare(ctx.min.value) < 0) target = ctx.min.value;
|
||||
if (target.compare(ctx.max.value) > 0) target = ctx.max.value;
|
||||
// Bounds are finite and calendar arithmetic may saturate at year limits.
|
||||
while (
|
||||
target.compare(ctx.min.value) >= 0 &&
|
||||
target.compare(ctx.max.value) <= 0
|
||||
) {
|
||||
if (!ctx.disabledDay(target)) {
|
||||
ctx.focusDate(target, true);
|
||||
return;
|
||||
}
|
||||
const next = target.add({ days: step });
|
||||
if (isSameDay(next, target)) return;
|
||||
target = next;
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
const value = state.value;
|
||||
const label = new DateFormatter(ctx.options.value.locale, {
|
||||
dateStyle: "full",
|
||||
timeZone: "UTC",
|
||||
}).format(props.date.toDate("UTC"));
|
||||
return h(
|
||||
"td",
|
||||
{
|
||||
role: "gridcell",
|
||||
"aria-selected": value.isSelected,
|
||||
"aria-hidden": value.isOutsideMonth || undefined,
|
||||
"aria-disabled": value.isDisabled || value.isUnavailable || undefined,
|
||||
},
|
||||
[
|
||||
h(
|
||||
"button",
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
class: "hv-calendar__cell",
|
||||
tabindex:
|
||||
!ctx.yearOpen.value &&
|
||||
!value.isDisabled &&
|
||||
ctx.tabStop.value &&
|
||||
isSameDay(props.date, ctx.tabStop.value) &&
|
||||
!value.isOutsideMonth
|
||||
? 0
|
||||
: -1,
|
||||
"aria-label": label,
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
ref: (node: unknown) => {
|
||||
element = node as HTMLButtonElement | undefined;
|
||||
},
|
||||
"data-slot": "calendar-cell",
|
||||
"data-date": props.date.toString(),
|
||||
disabled: value.isDisabled,
|
||||
"data-selected": value.isSelected || undefined,
|
||||
"data-today": value.isToday || undefined,
|
||||
"data-disabled": value.isDisabled || undefined,
|
||||
"data-unavailable": value.isUnavailable || undefined,
|
||||
"data-outside-month": value.isOutsideMonth || undefined,
|
||||
"aria-disabled":
|
||||
value.isDisabled || value.isUnavailable || undefined,
|
||||
onKeydown: keydown,
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
!ctx.yearOpen.value &&
|
||||
!value.isDisabled
|
||||
) {
|
||||
if (!focused.value) ctx.focusDate(props.date);
|
||||
ctx.request(props.date);
|
||||
}
|
||||
},
|
||||
"data-focused": focused.value || undefined,
|
||||
"data-focus-visible": focusVisible.value || undefined,
|
||||
"data-hovered": hovered.value || undefined,
|
||||
"data-pressed": pressed.value || undefined,
|
||||
onPointerenter: () => {
|
||||
if (!value.isDisabled) hovered.value = true;
|
||||
},
|
||||
onPointerleave: () => {
|
||||
hovered.value = false;
|
||||
pressed.value = false;
|
||||
},
|
||||
onPointerdown: (event: PointerEvent) => {
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
!value.isDisabled &&
|
||||
!ctx.readOnly.value
|
||||
)
|
||||
pressed.value = true;
|
||||
},
|
||||
onPointerup: () => {
|
||||
pressed.value = false;
|
||||
},
|
||||
onKeyup: () => {
|
||||
pressed.value = false;
|
||||
},
|
||||
onFocus: (event: FocusEvent) => {
|
||||
focused.value = true;
|
||||
focusVisible.value = (
|
||||
event.currentTarget as HTMLElement
|
||||
).matches(":focus-visible");
|
||||
if (!value.isDisabled && !ctx.yearOpen.value)
|
||||
ctx.focusDate(props.date);
|
||||
},
|
||||
onBlur: () => {
|
||||
focused.value = false;
|
||||
focusVisible.value = false;
|
||||
pressed.value = false;
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.(value) ?? value.formattedDate,
|
||||
),
|
||||
],
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,422 @@
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
mergeProps,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
provide,
|
||||
shallowRef,
|
||||
watch,
|
||||
type PropType,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { useResizeObserver } from "@vueuse/core";
|
||||
import {
|
||||
DateFormatter,
|
||||
today,
|
||||
type CalendarDate,
|
||||
type DateDuration,
|
||||
} from "@internationalized/date";
|
||||
import { calendarHeading, calendarYears } from "../date/calendar";
|
||||
import { dateForLocale } from "../date/value";
|
||||
import {
|
||||
calendarYearKey,
|
||||
useCalendar,
|
||||
useCalendarYears,
|
||||
type CalendarYearState,
|
||||
} from "./context";
|
||||
import { calendarChevron } from "./parts";
|
||||
|
||||
export interface CalendarYearPickerTriggerState {
|
||||
isOpen: boolean;
|
||||
monthYear: string;
|
||||
toggle: () => void;
|
||||
}
|
||||
export const CalendarYearPickerTrigger = defineComponent({
|
||||
name: "CalendarYearPickerTrigger",
|
||||
inheritAttrs: false,
|
||||
props: { isDisabled: Boolean, disabled: Boolean },
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: CalendarYearPickerTriggerState) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
const disabled = computed(
|
||||
() => props.isDisabled || props.disabled || ctx.disabled.value,
|
||||
);
|
||||
const toggle = () => {
|
||||
if (!disabled.value) ctx.setYearOpen(!ctx.yearOpen.value);
|
||||
};
|
||||
return () => {
|
||||
const monthYear = calendarHeading(ctx.anchor.value, ctx.options.value);
|
||||
return h(
|
||||
"button",
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
class: "hv-calendar-year-picker__trigger",
|
||||
"aria-label": `${monthYear}, year selector`,
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
ref: (node: unknown) => {
|
||||
ctx.trigger.value = node as HTMLElement | undefined;
|
||||
},
|
||||
disabled: disabled.value,
|
||||
"data-slot": "calendar-year-picker-trigger",
|
||||
"data-open": ctx.yearOpen.value || undefined,
|
||||
"aria-expanded": ctx.yearOpen.value,
|
||||
"aria-controls": ctx.yearOpen.value
|
||||
? `${ctx.headingId}-years`
|
||||
: undefined,
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (!event.defaultPrevented) toggle();
|
||||
},
|
||||
onKeydown: (event: KeyboardEvent) => {
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
event.key === "Escape" &&
|
||||
ctx.yearOpen.value
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
ctx.setYearOpen(false, true);
|
||||
}
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.({ isOpen: ctx.yearOpen.value, monthYear, toggle }) ??
|
||||
monthYear,
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
export const CalendarYearPickerTriggerHeading = defineComponent({
|
||||
name: "CalendarYearPickerTriggerHeading",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "span" },
|
||||
offset: Object as PropType<DateDuration>,
|
||||
format: Object as PropType<Intl.DateTimeFormatOptions>,
|
||||
},
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: CalendarYearPickerTriggerState) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
return () => {
|
||||
const monthYear = calendarHeading(
|
||||
ctx.anchor.value,
|
||||
ctx.options.value,
|
||||
props.offset,
|
||||
props.format,
|
||||
);
|
||||
return h(
|
||||
props.as,
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar-year-picker__trigger-heading",
|
||||
"data-slot": "calendar-year-picker-trigger-heading",
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
slots.default?.({
|
||||
isOpen: ctx.yearOpen.value,
|
||||
monthYear,
|
||||
toggle: () => ctx.setYearOpen(!ctx.yearOpen.value),
|
||||
}) ?? monthYear,
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
export const CalendarYearPickerTriggerIndicator = defineComponent({
|
||||
name: "CalendarYearPickerTriggerIndicator",
|
||||
inheritAttrs: false,
|
||||
setup(_props, { attrs, slots }) {
|
||||
useCalendar();
|
||||
return () =>
|
||||
h(
|
||||
"span",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar-year-picker__trigger-indicator",
|
||||
"data-slot": "calendar-year-picker-trigger-indicator",
|
||||
"aria-hidden": "true",
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
slots.default?.() ?? [calendarChevron(false, "")],
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarYearPickerGrid = defineComponent({
|
||||
name: "CalendarYearPickerGrid",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
visibleYears: Number,
|
||||
format: Object as PropType<Intl.DateTimeFormatOptions>,
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
const element = shallowRef<HTMLElement>();
|
||||
const top = shallowRef(0),
|
||||
height = shallowRef(0),
|
||||
active = shallowRef("");
|
||||
let revision = 0;
|
||||
const all = computed(() => calendarYears(ctx.min.value, ctx.max.value));
|
||||
const entries = computed(() => {
|
||||
if (props.visibleYears == null) return all.value;
|
||||
const count = props.visibleYears;
|
||||
if (!Number.isSafeInteger(count) || count < 1)
|
||||
throw new RangeError("visibleYears requires a positive integer.");
|
||||
const index = all.value.findIndex(
|
||||
(date) =>
|
||||
date.year === ctx.focus.value.year &&
|
||||
date.era === ctx.focus.value.era,
|
||||
);
|
||||
const start = Math.max(
|
||||
0,
|
||||
Math.min(index - Math.floor(count / 2), all.value.length - count),
|
||||
);
|
||||
return all.value.slice(start, start + count);
|
||||
});
|
||||
const label = (date: CalendarDate) =>
|
||||
new DateFormatter(ctx.options.value.locale, {
|
||||
year: "numeric",
|
||||
...props.format,
|
||||
timeZone: "UTC",
|
||||
}).format(date.toDate("UTC"));
|
||||
function measure() {
|
||||
const grid = ctx.root.value?.querySelector<HTMLElement>(
|
||||
'[data-slot="calendar-grid"]',
|
||||
);
|
||||
if (grid) {
|
||||
top.value = grid.offsetTop;
|
||||
height.value = grid.offsetHeight;
|
||||
}
|
||||
}
|
||||
function focusYear(key: string) {
|
||||
const cell = element.value?.querySelector<HTMLElement>(
|
||||
`[data-year-key="${key}"]`,
|
||||
);
|
||||
cell?.focus({ preventScroll: true });
|
||||
cell?.scrollIntoView?.({ block: "nearest" });
|
||||
}
|
||||
const rootGrid = computed(() =>
|
||||
ctx.root.value?.querySelector<HTMLElement>('[data-slot="calendar-grid"]'),
|
||||
);
|
||||
useResizeObserver(rootGrid, measure);
|
||||
onMounted(measure);
|
||||
watch(
|
||||
() => ctx.yearOpen.value,
|
||||
async (open, old) => {
|
||||
const request = ++revision;
|
||||
await nextTick();
|
||||
if (request !== revision || !element.value) return;
|
||||
measure();
|
||||
if (open) {
|
||||
const date =
|
||||
entries.value.find(
|
||||
(date) =>
|
||||
date.year === ctx.focus.value.year &&
|
||||
date.era === ctx.focus.value.era,
|
||||
) ?? entries.value[0];
|
||||
if (date) {
|
||||
active.value = date.toString();
|
||||
focusYear(active.value);
|
||||
}
|
||||
} else if (
|
||||
old &&
|
||||
element.value.contains(element.value.ownerDocument.activeElement)
|
||||
)
|
||||
ctx.trigger.value?.focus();
|
||||
},
|
||||
{ immediate: true, flush: "post" },
|
||||
);
|
||||
watch(
|
||||
() => entries.value.map((date) => date.toString()).join("|"),
|
||||
() => {
|
||||
if (!entries.value.some((date) => date.toString() === active.value))
|
||||
active.value = entries.value[0]?.toString() ?? "";
|
||||
},
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
revision++;
|
||||
});
|
||||
function select(date: CalendarDate) {
|
||||
if (!ctx.yearOpen.value || ctx.disabled.value) return;
|
||||
let target = ctx.focus.value.set({ era: date.era, year: date.year });
|
||||
if (target.compare(ctx.min.value) < 0) target = ctx.min.value;
|
||||
if (target.compare(ctx.max.value) > 0) target = ctx.max.value;
|
||||
ctx.focusDate(target, true);
|
||||
ctx.setYearOpen(false);
|
||||
}
|
||||
function state(date: CalendarDate): CalendarYearState {
|
||||
const current = dateForLocale(
|
||||
today(ctx.timeZone.value),
|
||||
ctx.options.value.locale,
|
||||
);
|
||||
return {
|
||||
year: date.year,
|
||||
date: date.copy(),
|
||||
formattedYear: label(date),
|
||||
isSelected:
|
||||
date.year === ctx.focus.value.year &&
|
||||
date.era === ctx.focus.value.era,
|
||||
isCurrentYear: date.year === current.year && date.era === current.era,
|
||||
isOpen: ctx.yearOpen.value,
|
||||
selectYear: () => select(date),
|
||||
};
|
||||
}
|
||||
provide(calendarYearKey, { entries, active, label, state, select });
|
||||
function keydown(event: KeyboardEvent) {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.isComposing ||
|
||||
ctx.disabled.value ||
|
||||
!ctx.yearOpen.value
|
||||
)
|
||||
return;
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
ctx.setYearOpen(false, true);
|
||||
return;
|
||||
}
|
||||
const index = entries.value.findIndex(
|
||||
(date) => date.toString() === active.value,
|
||||
);
|
||||
let next = index;
|
||||
const sign = ctx.dir.value === "rtl" ? -1 : 1;
|
||||
switch (event.key) {
|
||||
case "ArrowRight":
|
||||
next += sign;
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
next -= sign;
|
||||
break;
|
||||
case "ArrowDown":
|
||||
next += 3;
|
||||
break;
|
||||
case "ArrowUp":
|
||||
next -= 3;
|
||||
break;
|
||||
case "Home":
|
||||
next = 0;
|
||||
break;
|
||||
case "End":
|
||||
next = entries.value.length - 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const date =
|
||||
entries.value[Math.max(0, Math.min(next, entries.value.length - 1))];
|
||||
if (date) {
|
||||
active.value = date.toString();
|
||||
focusYear(active.value);
|
||||
}
|
||||
}
|
||||
return () =>
|
||||
h(
|
||||
"div",
|
||||
mergeProps(
|
||||
{
|
||||
id: `${ctx.headingId}-years`,
|
||||
class: "hv-calendar-year-picker__year-grid",
|
||||
role: "listbox",
|
||||
"aria-label": "Year",
|
||||
style: { top: `${top.value}px`, height: `${height.value}px` },
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
ref: element,
|
||||
"data-slot": "calendar-year-picker-grid",
|
||||
"data-open": ctx.yearOpen.value || undefined,
|
||||
"aria-hidden": !ctx.yearOpen.value,
|
||||
inert: !ctx.yearOpen.value ? "" : undefined,
|
||||
onKeydown: keydown,
|
||||
},
|
||||
),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarYearPickerGridBody = defineComponent({
|
||||
name: "CalendarYearPickerGridBody",
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: CalendarYearState) => VNodeChild;
|
||||
}>,
|
||||
setup(_props, { slots }) {
|
||||
const ctx = useCalendarYears();
|
||||
return () =>
|
||||
ctx.entries.value.map(
|
||||
(date) =>
|
||||
slots.default?.(ctx.state(date)) ??
|
||||
h(CalendarYearPickerCell, {
|
||||
date,
|
||||
year: date.year,
|
||||
key: date.toString(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
export const CalendarYearPickerCell = defineComponent({
|
||||
name: "CalendarYearPickerCell",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
year: { type: Number, required: true },
|
||||
era: String,
|
||||
date: Object as PropType<CalendarDate>,
|
||||
},
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: CalendarYearState) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots }) {
|
||||
const ctx = useCalendarYears(),
|
||||
calendar = useCalendar();
|
||||
return () => {
|
||||
const date =
|
||||
props.date ??
|
||||
ctx.entries.value.find(
|
||||
(date) =>
|
||||
date.year === props.year && (!props.era || date.era === props.era),
|
||||
);
|
||||
if (!date) return null;
|
||||
const state = ctx.state(date);
|
||||
return h(
|
||||
"button",
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
role: "option",
|
||||
class: "hv-calendar-year-picker__year-cell",
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
"data-slot": "calendar-year-picker-cell",
|
||||
"data-year": date.year,
|
||||
"data-year-key": date.toString(),
|
||||
"data-selected": state.isSelected || undefined,
|
||||
"aria-selected": state.isSelected,
|
||||
tabindex:
|
||||
state.isOpen && ctx.active.value === date.toString() ? 0 : -1,
|
||||
disabled: calendar.disabled.value,
|
||||
onFocus: () => {
|
||||
ctx.active.value = date.toString();
|
||||
},
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (!event.defaultPrevented) ctx.select(date);
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.(state) ?? state.formattedYear,
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,167 @@
|
||||
import {
|
||||
CalendarDate,
|
||||
DateFormatter,
|
||||
endOfMonth,
|
||||
endOfWeek,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
isSameDay,
|
||||
isSameMonth,
|
||||
toCalendarDate,
|
||||
type DateDuration,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { dateForLocale } from "./value";
|
||||
export type CalendarWeekday =
|
||||
"sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat";
|
||||
export type CalendarDuration =
|
||||
| { months: number; weeks?: never; days?: never }
|
||||
| { weeks: number; months?: never; days?: never }
|
||||
| { days: number; months?: never; weeks?: never };
|
||||
export interface CalendarViewOptions {
|
||||
locale: string;
|
||||
visibleDuration?: CalendarDuration;
|
||||
firstDayOfWeek?: CalendarWeekday;
|
||||
weeksInMonth?: number;
|
||||
}
|
||||
export function calendarDuration(value: CalendarDuration = { months: 1 }) {
|
||||
const entries = Object.entries(value).filter(([, count]) => count != null);
|
||||
if (
|
||||
entries.length !== 1 ||
|
||||
!["months", "weeks", "days"].includes(entries[0]![0]) ||
|
||||
!Number.isSafeInteger(entries[0]![1]) ||
|
||||
entries[0]![1] <= 0
|
||||
)
|
||||
throw new RangeError(
|
||||
"Calendar visibleDuration requires one positive integer unit.",
|
||||
);
|
||||
return {
|
||||
unit: entries[0]![0] as "months" | "weeks" | "days",
|
||||
count: entries[0]![1] as number,
|
||||
};
|
||||
}
|
||||
export function calendarRange(anchor: DateValue, options: CalendarViewOptions) {
|
||||
const { unit, count } = calendarDuration(options.visibleDuration);
|
||||
const date = toCalendarDate(dateForLocale(anchor, options.locale));
|
||||
const start =
|
||||
unit === "months"
|
||||
? startOfMonth(date)
|
||||
: unit === "weeks"
|
||||
? startOfWeek(date, options.locale, options.firstDayOfWeek)
|
||||
: date;
|
||||
const end =
|
||||
unit === "months"
|
||||
? endOfMonth(start.add({ months: count - 1 }))
|
||||
: start.add({ days: unit === "weeks" ? count * 7 - 1 : count - 1 });
|
||||
return { start, end, unit, count };
|
||||
}
|
||||
/** Source-compatible month/week/day rows. Day views >=7 align weeks, with
|
||||
* disabled leading dates and empty trailing cells; short day views stay compact. */
|
||||
export function calendarRows(
|
||||
anchor: DateValue,
|
||||
options: CalendarViewOptions,
|
||||
offset: DateDuration = {},
|
||||
) {
|
||||
const range = calendarRange(anchor, options);
|
||||
const month = startOfMonth(range.start.add(offset));
|
||||
let start: CalendarDate, end: CalendarDate;
|
||||
if (range.unit === "months") {
|
||||
start = startOfWeek(month, options.locale, options.firstDayOfWeek);
|
||||
end = endOfWeek(endOfMonth(month), options.locale, options.firstDayOfWeek);
|
||||
if (options.weeksInMonth != null) {
|
||||
if (
|
||||
!Number.isSafeInteger(options.weeksInMonth) ||
|
||||
options.weeksInMonth < 1
|
||||
)
|
||||
throw new RangeError(
|
||||
"Calendar weeksInMonth requires a positive integer.",
|
||||
);
|
||||
// Never remove actual month days when a requested minimum is too small.
|
||||
const fixedEnd = start.add({ days: options.weeksInMonth * 7 - 1 });
|
||||
if (fixedEnd.compare(end) > 0) end = fixedEnd;
|
||||
}
|
||||
} else {
|
||||
start =
|
||||
range.unit === "days" && range.count < 7
|
||||
? range.start
|
||||
: startOfWeek(range.start, options.locale, options.firstDayOfWeek);
|
||||
end = range.end;
|
||||
}
|
||||
const rows: (CalendarDate | null)[][] = [];
|
||||
let cursor = start;
|
||||
while (cursor.compare(end) <= 0) {
|
||||
const row: (CalendarDate | null)[] = [];
|
||||
for (let index = 0; index < 7; index++) {
|
||||
row.push(cursor.compare(end) <= 0 ? cursor : null);
|
||||
const next = cursor.add({ days: 1 });
|
||||
if (isSameDay(cursor, next)) {
|
||||
while (row.length < 7) row.push(null);
|
||||
rows.push(row);
|
||||
return { rows, month, range };
|
||||
}
|
||||
cursor = next;
|
||||
}
|
||||
rows.push(row);
|
||||
}
|
||||
return { rows, month, range };
|
||||
}
|
||||
export function calendarWeekdays(
|
||||
anchor: DateValue,
|
||||
options: CalendarViewOptions,
|
||||
style: "narrow" | "short" | "long" = "short",
|
||||
) {
|
||||
const range = calendarRange(anchor, options);
|
||||
const start =
|
||||
range.unit === "days" && range.count < 7
|
||||
? range.start
|
||||
: startOfWeek(range.start, options.locale, options.firstDayOfWeek);
|
||||
const count = range.unit === "days" && range.count < 7 ? range.count : 7;
|
||||
const formatter = new DateFormatter(options.locale, {
|
||||
weekday: style,
|
||||
timeZone: "UTC",
|
||||
});
|
||||
return Array.from({ length: count }, (_, index) =>
|
||||
formatter.format(start.add({ days: index }).toDate("UTC")),
|
||||
);
|
||||
}
|
||||
export function calendarHeading(
|
||||
anchor: DateValue,
|
||||
options: CalendarViewOptions,
|
||||
offset?: DateDuration,
|
||||
format?: Intl.DateTimeFormatOptions,
|
||||
) {
|
||||
const range = calendarRange(anchor, options);
|
||||
const formatter = new DateFormatter(options.locale, {
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
...(range.unit !== "months" ? { day: "numeric" as const } : {}),
|
||||
...format,
|
||||
timeZone: "UTC",
|
||||
});
|
||||
if (offset) return formatter.format(range.start.add(offset).toDate("UTC"));
|
||||
if (
|
||||
isSameDay(range.start, range.end) ||
|
||||
(range.unit === "months" && range.count === 1)
|
||||
)
|
||||
return formatter.format(range.start.toDate("UTC"));
|
||||
return formatter.formatRange(
|
||||
range.start.toDate("UTC"),
|
||||
range.end.toDate("UTC"),
|
||||
);
|
||||
}
|
||||
export function calendarYears(min: DateValue, max: DateValue) {
|
||||
const result: CalendarDate[] = [];
|
||||
let current = startOfYear(toCalendarDate(min));
|
||||
const last = toCalendarDate(max);
|
||||
while (current.compare(last) <= 0) {
|
||||
result.push(current);
|
||||
const next = startOfYear(current.add({ years: 1 }));
|
||||
if (next.compare(current) <= 0) break;
|
||||
current = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function sameCalendarMonth(a: DateValue, b: DateValue) {
|
||||
return isSameMonth(a, b);
|
||||
}
|
||||
@@ -884,3 +884,69 @@ export { toast, toastQueue } from "./components/toast/toast";
|
||||
|
||||
export type { TableKey } from "./components/table/context";
|
||||
export { default as TableLoadMore } from "./components/table/TableLoadMoreItem.vue";
|
||||
|
||||
export {
|
||||
default as Calendar,
|
||||
default as CalendarRoot,
|
||||
} from "./components/calendar/Calendar.vue";
|
||||
export {
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarHeaderCell,
|
||||
CalendarCell,
|
||||
CalendarCellIndicator,
|
||||
} from "./components/calendar/parts";
|
||||
export {
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerCell,
|
||||
} from "./components/calendar/year-picker";
|
||||
export type {
|
||||
CalendarCellState,
|
||||
CalendarModel,
|
||||
CalendarOptions,
|
||||
CalendarSelectionMode,
|
||||
CalendarYearState,
|
||||
} from "./components/calendar/context";
|
||||
export type {
|
||||
CalendarDuration,
|
||||
CalendarWeekday,
|
||||
} from "./components/date/calendar";
|
||||
|
||||
export type {
|
||||
CalendarProps,
|
||||
CalendarRootProps,
|
||||
CalendarHeaderProps,
|
||||
CalendarHeadingProps,
|
||||
CalendarNavButtonProps,
|
||||
CalendarGridProps,
|
||||
CalendarGridHeaderProps,
|
||||
CalendarGridBodyProps,
|
||||
CalendarHeaderCellProps,
|
||||
CalendarCellProps,
|
||||
CalendarCellIndicatorProps,
|
||||
CalendarYearPickerTriggerProps,
|
||||
CalendarYearPickerTriggerHeadingProps,
|
||||
CalendarYearPickerTriggerIndicatorProps,
|
||||
CalendarYearPickerGridProps,
|
||||
CalendarYearPickerGridBodyProps,
|
||||
CalendarYearPickerCellProps,
|
||||
} from "./types";
|
||||
|
||||
export {
|
||||
calendarVariants,
|
||||
calendarYearPickerVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
CalendarVariants,
|
||||
CalendarYearPickerVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type { CalendarYearPickerTriggerState as CalendarYearPickerTriggerRenderProps } from "./components/calendar/year-picker";
|
||||
export type { CalendarYearState as CalendarYearPickerCellRenderProps } from "./components/calendar/context";
|
||||
|
||||
@@ -728,3 +728,74 @@ export type TableLoadMoreContentProps = InstanceType<
|
||||
typeof TableLoadMoreContent
|
||||
>["$props"];
|
||||
export type TableLoadMoreProps = TableLoadMoreItemProps;
|
||||
|
||||
import type {
|
||||
CalendarOptions,
|
||||
CalendarSelectionMode,
|
||||
CalendarModel,
|
||||
} from "./components/calendar/context";
|
||||
import type { AllowedComponentProps, VNodeProps } from "vue";
|
||||
export type CalendarProps<M extends CalendarSelectionMode = "single"> =
|
||||
CalendarOptions<M> &
|
||||
AllowedComponentProps &
|
||||
VNodeProps & {
|
||||
"onUpdate:modelValue"?: (value: CalendarModel<M>) => void;
|
||||
onChange?: (value: CalendarModel<M>) => void;
|
||||
"onUpdate:focusedValue"?: (
|
||||
value: import("@internationalized/date").DateValue,
|
||||
) => void;
|
||||
onFocusChange?: (
|
||||
value: import("@internationalized/date").DateValue,
|
||||
) => void;
|
||||
"onUpdate:isYearPickerOpen"?: (value: boolean) => void;
|
||||
onYearPickerOpenChange?: (value: boolean) => void;
|
||||
};
|
||||
export type CalendarRootProps<M extends CalendarSelectionMode = "single"> =
|
||||
CalendarProps<M>;
|
||||
import type * as CalendarParts from "./components/calendar/parts";
|
||||
import type * as CalendarYears from "./components/calendar/year-picker";
|
||||
export type CalendarHeaderProps = InstanceType<
|
||||
typeof CalendarParts.CalendarHeader
|
||||
>["$props"];
|
||||
export type CalendarHeadingProps = InstanceType<
|
||||
typeof CalendarParts.CalendarHeading
|
||||
>["$props"];
|
||||
export type CalendarNavButtonProps = InstanceType<
|
||||
typeof CalendarParts.CalendarNavButton
|
||||
>["$props"];
|
||||
export type CalendarGridProps = InstanceType<
|
||||
typeof CalendarParts.CalendarGrid
|
||||
>["$props"];
|
||||
export type CalendarGridHeaderProps = InstanceType<
|
||||
typeof CalendarParts.CalendarGridHeader
|
||||
>["$props"];
|
||||
export type CalendarGridBodyProps = InstanceType<
|
||||
typeof CalendarParts.CalendarGridBody
|
||||
>["$props"];
|
||||
export type CalendarHeaderCellProps = InstanceType<
|
||||
typeof CalendarParts.CalendarHeaderCell
|
||||
>["$props"];
|
||||
export type CalendarCellProps = InstanceType<
|
||||
typeof CalendarParts.CalendarCell
|
||||
>["$props"];
|
||||
export type CalendarCellIndicatorProps = InstanceType<
|
||||
typeof CalendarParts.CalendarCellIndicator
|
||||
>["$props"];
|
||||
export type CalendarYearPickerTriggerProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerTrigger
|
||||
>["$props"];
|
||||
export type CalendarYearPickerTriggerHeadingProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerTriggerHeading
|
||||
>["$props"];
|
||||
export type CalendarYearPickerTriggerIndicatorProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerTriggerIndicator
|
||||
>["$props"];
|
||||
export type CalendarYearPickerGridProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerGrid
|
||||
>["$props"];
|
||||
export type CalendarYearPickerGridBodyProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerGridBody
|
||||
>["$props"];
|
||||
export type CalendarYearPickerCellProps = InstanceType<
|
||||
typeof CalendarYears.CalendarYearPickerCell
|
||||
>["$props"];
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, type Component } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
} from "../packages/vue/src/index";
|
||||
const demos = import.meta.glob("../apps/docs/demos/calendar-*.vue", {
|
||||
eager: true,
|
||||
import: "default",
|
||||
}) as Record<string, Component>;
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
it("mounts all nineteen baseline demos together without duplicate IDs or Vue warnings", async () => {
|
||||
expect(Object.keys(demos)).toHaveLength(19);
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
"div",
|
||||
Object.entries(demos).map(([key, demo]) => h(demo, { key })),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
await flushPromises();
|
||||
const ids = Array.from(document.querySelectorAll("[id]")).map((e) => e.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
});
|
||||
it("hydrates an explicitly dated calendar without replacing the server grid", async () => {
|
||||
const Root = defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultFocusedValue: new CalendarDate(2024, 2, 10),
|
||||
locale: "en-US",
|
||||
timeZone: "UTC",
|
||||
},
|
||||
() =>
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
),
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
host.innerHTML = await renderToString(createSSRApp(Root));
|
||||
document.body.append(host);
|
||||
const grid = host.querySelector("table");
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const app = createSSRApp(Root);
|
||||
app.mount(host);
|
||||
await flushPromises();
|
||||
expect(host.querySelector("table")).toBe(grid);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
app.unmount();
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
} from "../packages/vue/src/index";
|
||||
it("renders month and year markup without browser globals and stable explicit dates", async () => {
|
||||
const value = new CalendarDate(2024, 2, 29);
|
||||
const app = createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultValue: value,
|
||||
defaultFocusedValue: value,
|
||||
locale: "en-US",
|
||||
timeZone: "UTC",
|
||||
},
|
||||
() => [
|
||||
h(CalendarHeader, () => h(CalendarHeading)),
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
h(CalendarYearPickerGrid, () => h(CalendarYearPickerGridBody)),
|
||||
],
|
||||
),
|
||||
});
|
||||
const html = await renderToString(app);
|
||||
expect(html).toContain('data-date="2024-02-29"');
|
||||
expect(html).toContain('data-selected="true"');
|
||||
expect(html).toContain("February 2024");
|
||||
expect(html).toContain("inert");
|
||||
});
|
||||
it("renders the actual non-Gregorian weekday/month view and day windows on the server", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultFocusedValue: new CalendarDate(2024, 2, 10),
|
||||
locale: "hi-IN-u-ca-indian",
|
||||
visibleDuration: { days: 3 },
|
||||
selectionAlignment: "start",
|
||||
},
|
||||
() =>
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(html.match(/data-slot="calendar-cell"/g) ?? []).toHaveLength(3);
|
||||
expect(html).toContain("2024-02-10");
|
||||
expect(html).not.toContain("Sunday");
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
CalendarDate,
|
||||
HebrewCalendar,
|
||||
PersianCalendar,
|
||||
toCalendar,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
calendarDuration,
|
||||
calendarRange,
|
||||
calendarRows,
|
||||
calendarWeekdays,
|
||||
calendarHeading,
|
||||
calendarYears,
|
||||
} from "../packages/vue/src/components/date/calendar";
|
||||
const date = new CalendarDate(2024, 2, 10);
|
||||
const options = { locale: "en-US" };
|
||||
describe("calendar view adapter", () => {
|
||||
it("renders leap-month rows and offset grids with real calendar arithmetic", () => {
|
||||
const view = calendarRows(date, options);
|
||||
expect(view.rows.flat().some((d) => d?.toString() === "2024-02-29")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(view.rows).toHaveLength(5);
|
||||
expect(
|
||||
calendarRows(date, { ...options, weeksInMonth: 6 }).rows,
|
||||
).toHaveLength(6);
|
||||
expect(calendarRows(date, options, { months: 1 }).month.toString()).toBe(
|
||||
"2024-03-01",
|
||||
);
|
||||
});
|
||||
it("generates true week views across month boundaries", () => {
|
||||
const view = calendarRows(new CalendarDate(2024, 2, 29), {
|
||||
...options,
|
||||
visibleDuration: { weeks: 2 },
|
||||
firstDayOfWeek: "mon",
|
||||
});
|
||||
expect(view.rows).toHaveLength(2);
|
||||
expect(view.range.start.toString()).toBe("2024-02-26");
|
||||
expect(view.range.end.toString()).toBe("2024-03-10");
|
||||
});
|
||||
it("keeps short day views compact and long day views aligned with empty trailing cells", () => {
|
||||
const short = calendarRows(date, {
|
||||
...options,
|
||||
visibleDuration: { days: 3 },
|
||||
});
|
||||
expect(short.rows[0]!.map((d) => d?.day ?? null)).toEqual([
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
]);
|
||||
const long = calendarRows(date, {
|
||||
...options,
|
||||
visibleDuration: { days: 10 },
|
||||
});
|
||||
expect(long.rows).toHaveLength(3);
|
||||
expect(long.rows.at(-1)!.filter(Boolean)).toHaveLength(2);
|
||||
expect(
|
||||
calendarWeekdays(date, { ...options, visibleDuration: { days: 3 } }),
|
||||
).toEqual(["Sat", "Sun", "Mon"]);
|
||||
});
|
||||
it("converts the view to the locale calendar without mutating a Gregorian value", () => {
|
||||
const view = calendarRange(date, { locale: "fa-IR-u-ca-persian" });
|
||||
expect(view.start.calendar.identifier).toBe("persian");
|
||||
expect(view.start.month).toBe(
|
||||
toCalendar(date, new PersianCalendar()).month,
|
||||
);
|
||||
expect(date.calendar.identifier).toBe("gregory");
|
||||
});
|
||||
it("includes 13-month calendar dates and calendar-aware year entries", () => {
|
||||
const hebrew = toCalendar(
|
||||
new CalendarDate(2024, 9, 10),
|
||||
new HebrewCalendar(),
|
||||
);
|
||||
expect(hebrew.calendar.getMonthsInYear(hebrew)).toBe(13);
|
||||
const view = calendarRows(hebrew.set({ month: 13 }), {
|
||||
locale: "he-IL-u-ca-hebrew",
|
||||
});
|
||||
expect(view.month.month).toBe(13);
|
||||
const years = calendarYears(hebrew, hebrew.add({ years: 2 }));
|
||||
expect(years).toHaveLength(3);
|
||||
expect(years.every((y) => y.month === 1 && y.day === 1)).toBe(true);
|
||||
});
|
||||
it("formats ranges and rejects ambiguous or invalid durations", () => {
|
||||
expect(calendarHeading(date, options)).toBe("February 2024");
|
||||
expect(
|
||||
calendarHeading(date, { ...options, visibleDuration: { months: 2 } }),
|
||||
).toContain("March");
|
||||
for (const value of [
|
||||
{ days: 0 },
|
||||
{ days: -1 },
|
||||
{ months: 1.5 },
|
||||
{ weeks: 1, days: 1 },
|
||||
{},
|
||||
])
|
||||
expect(() => calendarDuration(value as never)).toThrow(RangeError);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,290 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef, type Component } from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
PersianCalendar,
|
||||
toCalendar,
|
||||
parseZonedDateTime,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import * as library from "../packages/vue/src/index";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
const parts = `<CalendarHeader><CalendarHeading/><CalendarNavButton slot="previous"/><CalendarNavButton slot="next"/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`;
|
||||
function fixture(attributes = "", setup = () => ({}), children = parts) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: Object.fromEntries(
|
||||
Object.entries(library).filter(([name]) => name.startsWith("Calendar")),
|
||||
) as Record<string, Component>,
|
||||
setup: () => ({ initial, ...setup() }),
|
||||
template: `<Calendar aria-label="Date" :default-focused-value="initial" ${attributes}>${children}</Calendar>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const cell = (w: ReturnType<typeof mount>, iso: string) =>
|
||||
w.get<HTMLElement>(
|
||||
`[data-slot="calendar-cell"][data-date="${iso}"]:not([data-outside-month])`,
|
||||
);
|
||||
const calendar = (w: ReturnType<typeof mount>) =>
|
||||
w.findComponent(library.Calendar);
|
||||
async function key(
|
||||
w: ReturnType<typeof mount>,
|
||||
iso: string,
|
||||
key: string,
|
||||
extra = {},
|
||||
) {
|
||||
cell(w, iso).element.focus();
|
||||
await cell(w, iso).trigger("keydown", { key, code: key, ...extra });
|
||||
await flushPromises();
|
||||
}
|
||||
describe("Calendar public contract", () => {
|
||||
it("renders semantic grids and selects a date without named native submission", async () => {
|
||||
const w = fixture();
|
||||
expect(w.find('table[role="grid"]').exists()).toBe(true);
|
||||
expect(w.findAll("th")).toHaveLength(7);
|
||||
await cell(w, "2024-02-29").trigger("click");
|
||||
expect(cell(w, "2024-02-29").attributes("data-selected")).toBe("true");
|
||||
expect(calendar(w).emitted("change")![0]![0]).toBeInstanceOf(CalendarDate);
|
||||
expect(w.find("input[name]").exists()).toBe(false);
|
||||
});
|
||||
it("keeps controlled rejected values and allows the same proposal again", async () => {
|
||||
const w = fixture(':model-value="initial"');
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
expect(calendar(w).emitted("change")).toHaveLength(2);
|
||||
expect(cell(w, "2024-02-10").attributes("data-selected")).toBe("true");
|
||||
expect(cell(w, "2024-02-11").attributes("data-selected")).toBeUndefined();
|
||||
});
|
||||
it("supports multiple toggling and copies proposals without mutating parent dates", async () => {
|
||||
const w = fixture('selection-mode="multiple" :default-value="[initial]"');
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
expect(
|
||||
(calendar(w).emitted("change")![0]![0] as DateValue[]).map((d) =>
|
||||
d.toString(),
|
||||
),
|
||||
).toEqual(["2024-02-10", "2024-02-11"]);
|
||||
await cell(w, "2024-02-10").trigger("click");
|
||||
expect(cell(w, "2024-02-10").attributes("data-selected")).toBeUndefined();
|
||||
expect(initial.toString()).toBe("2024-02-10");
|
||||
});
|
||||
it("exposes actual hover, focus and pressed slot state without repeating a held selection", async () => {
|
||||
const w = fixture(
|
||||
'selection-mode="multiple"',
|
||||
() => ({}),
|
||||
`<CalendarGrid><CalendarGridHeader/><CalendarGridBody v-slot="{date}"><CalendarCell :date="date" v-slot="{formattedDate,isHovered,isPressed,isFocused}"><span>{{ formattedDate }}:{{ isHovered }}:{{ isPressed }}:{{ isFocused }}</span></CalendarCell></CalendarGridBody></CalendarGrid>`,
|
||||
);
|
||||
const day = cell(w, "2024-02-10");
|
||||
await day.trigger("pointerenter");
|
||||
expect(day.text()).toContain(":true:false:false");
|
||||
day.element.focus();
|
||||
await flushPromises();
|
||||
expect(day.text()).toContain(":true:false:true");
|
||||
await day.trigger("keydown", { key: " ", code: "Space" });
|
||||
expect(day.attributes("data-pressed")).toBe("true");
|
||||
await day.trigger("keydown", { key: " ", code: "Space", repeat: true });
|
||||
expect(calendar(w).emitted("change")).toHaveLength(1);
|
||||
await day.trigger("keyup", { key: " ", code: "Space" });
|
||||
expect(day.attributes("data-pressed")).toBeUndefined();
|
||||
});
|
||||
it("preserves time precision and zone in date-only selection", async () => {
|
||||
for (const value of [
|
||||
new CalendarDateTime(2024, 2, 10, 13, 14, 45, 123),
|
||||
parseZonedDateTime("2024-02-10T13:14:45.123-08:00[America/Los_Angeles]"),
|
||||
]) {
|
||||
const w = fixture(':default-value="value"', () => ({ value }));
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
const next = calendar(w).emitted("change")![0]![0] as DateValue;
|
||||
expect(next.toString()).toBe(value.set({ day: 11 }).toString());
|
||||
}
|
||||
});
|
||||
it("distinguishes disabled from focusable unavailable dates and honors actual keyboard cancellation", async () => {
|
||||
const w = fixture(
|
||||
':is-date-disabled="d=>d.day===11" :is-date-unavailable="d=>d.day===12"',
|
||||
);
|
||||
await key(w, "2024-02-10", "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(w, "2024-02-12").element);
|
||||
await cell(w, "2024-02-12").trigger("click");
|
||||
expect(calendar(w).emitted("change")).toBeUndefined();
|
||||
const cancelled = fixture(
|
||||
"",
|
||||
() => ({}),
|
||||
`<CalendarGrid><CalendarGridHeader/><CalendarGridBody v-slot="{date}"><CalendarCell :date="date" @keydown.prevent /></CalendarGridBody></CalendarGrid>`,
|
||||
);
|
||||
await key(cancelled, "2024-02-10", "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(cancelled, "2024-02-10").element);
|
||||
});
|
||||
it("supports readonly navigation and fully disabled controls", async () => {
|
||||
const ro = fixture("is-read-only");
|
||||
await key(ro, "2024-02-10", "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(ro, "2024-02-11").element);
|
||||
await cell(ro, "2024-02-11").trigger("click");
|
||||
expect(calendar(ro).emitted("change")).toBeUndefined();
|
||||
const disabled = fixture("is-disabled");
|
||||
expect(disabled.findAll("button:not(:disabled)")).toHaveLength(0);
|
||||
});
|
||||
it("pages with bounds, RTL keyboard movement and programmatic focused values", async () => {
|
||||
const focus = shallowRef<DateValue>(initial);
|
||||
const w = fixture(
|
||||
'v-model:focused-value="focus" dir="rtl" :min-value="initial" :max-value="initial.add({months:1})"',
|
||||
() => ({ focus }),
|
||||
);
|
||||
await key(w, "2024-02-10", "ArrowLeft");
|
||||
expect(focus.value.day).toBe(11);
|
||||
await key(w, "2024-02-11", "PageDown");
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("March");
|
||||
focus.value = new CalendarDate(2024, 2, 15);
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).toBe(
|
||||
"February 2024",
|
||||
);
|
||||
});
|
||||
it("pages a single unit even when the proposed focus remains inside a multi-unit view", async () => {
|
||||
const w = fixture(':visible-duration="{months:2}" page-behavior="single"');
|
||||
await w.get('[aria-label="Next"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("March");
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("April");
|
||||
const rejected = fixture(
|
||||
':focused-value="initial" :visible-duration="{weeks:2}" page-behavior="single"',
|
||||
);
|
||||
const heading = rejected.get('[data-slot="calendar-heading"]').text();
|
||||
await rejected.get('[aria-label="Next"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(rejected.get('[data-slot="calendar-heading"]').text()).toBe(heading);
|
||||
});
|
||||
it("keeps one Tab stop when the initial focused day is disabled", () => {
|
||||
const w = fixture(':is-date-disabled="d=>d.day===10"');
|
||||
expect(w.findAll('[data-slot="calendar-cell"][tabindex="0"]')).toHaveLength(
|
||||
1,
|
||||
);
|
||||
expect(cell(w, "2024-02-01").attributes("tabindex")).toBe("0");
|
||||
});
|
||||
it("retains keyboard focus across programmatic month changes without stealing outside focus", async () => {
|
||||
const focused = shallowRef<DateValue>(initial);
|
||||
const w = fixture('v-model:focused-value="focused"', () => ({ focused }));
|
||||
cell(w, "2024-02-10").element.focus();
|
||||
focused.value = new CalendarDate(2025, 6, 15);
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(cell(w, "2025-06-15").element);
|
||||
const outside = document.createElement("button");
|
||||
document.body.append(outside);
|
||||
outside.focus();
|
||||
focused.value = new CalendarDate(2024, 2, 20);
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(outside);
|
||||
});
|
||||
it("honors per-control disabled state and native event cancellation on navigation", async () => {
|
||||
const w = fixture(
|
||||
"",
|
||||
() => ({}),
|
||||
`<CalendarHeader><CalendarHeading/><CalendarNavButton disabled slot="next"/><CalendarNavButton slot="previous" @click.prevent/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`,
|
||||
);
|
||||
expect(w.get('[aria-label="Next"]').attributes("disabled")).toBe("");
|
||||
await w.get('[aria-label="Previous"]').trigger("click");
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).toBe(
|
||||
"February 2024",
|
||||
);
|
||||
});
|
||||
it("renders true weekly, daily and offset multi-month layouts", () => {
|
||||
expect(
|
||||
fixture(':visible-duration="{weeks:2}"').findAll("tbody tr"),
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
fixture(
|
||||
':visible-duration="{days:3}" selection-alignment="start"',
|
||||
).findAll('[data-slot="calendar-cell"]'),
|
||||
).toHaveLength(3);
|
||||
const two = fixture(
|
||||
':visible-duration="{months:2}"',
|
||||
() => ({}),
|
||||
`${parts}<CalendarGrid :offset="{months:1}"><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`,
|
||||
);
|
||||
expect(two.findAll("table")).toHaveLength(2);
|
||||
expect(cell(two, "2024-03-15").element.tagName === "BUTTON").toBe(true);
|
||||
expect(two.findAll('[data-date="2024-03-01"]:not(:disabled)')).toHaveLength(
|
||||
1,
|
||||
);
|
||||
});
|
||||
it("keeps empty selection Gregorian independently of the focused view calendar", async () => {
|
||||
const persian = toCalendar(initial, new PersianCalendar());
|
||||
const w = fixture(
|
||||
':focused-value="persian" locale="fa-IR-u-ca-persian"',
|
||||
() => ({ persian }),
|
||||
);
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
const value = calendar(w).emitted("change")![0]![0] as DateValue;
|
||||
expect(value.calendar.identifier).toBe("gregory");
|
||||
expect(value.toString()).toBe("2024-02-11");
|
||||
});
|
||||
it("restores accepted DOM focus after a controlled pointer focus is rejected", async () => {
|
||||
const w = fixture(':focused-value="initial"');
|
||||
cell(w, "2024-02-11").element.focus();
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(cell(w, "2024-02-10").element);
|
||||
});
|
||||
it("translates the actual calendar view and selection back to the public Gregorian model", async () => {
|
||||
const w = fixture(':default-value="initial" locale="hi-IN-u-ca-indian"');
|
||||
expect(w.get('[data-slot="calendar-heading"]').text()).not.toContain(
|
||||
"February",
|
||||
);
|
||||
await cell(w, "2024-02-11").trigger("click");
|
||||
const next = calendar(w).emitted("change")![0]![0] as DateValue;
|
||||
expect(next.calendar.identifier).toBe("gregory");
|
||||
expect(next.toString()).toBe("2024-02-11");
|
||||
});
|
||||
});
|
||||
describe("CalendarYearPicker", () => {
|
||||
const children = `<CalendarHeader><CalendarYearPickerTrigger><CalendarYearPickerTriggerHeading/><CalendarYearPickerTriggerIndicator/></CalendarYearPickerTrigger><CalendarNavButton slot="previous"/><CalendarNavButton slot="next"/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid><CalendarYearPickerGrid><CalendarYearPickerGridBody/></CalendarYearPickerGrid>`;
|
||||
it("keeps hidden years out of Tab, focuses the selected year and escapes back to the trigger", async () => {
|
||||
const w = fixture("", () => ({}), children);
|
||||
expect(
|
||||
w.get('[data-slot="calendar-year-picker-grid"]').attributes("inert"),
|
||||
).toBe("");
|
||||
await w.get('[data-slot="calendar-year-picker-trigger"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(document.activeElement?.getAttribute("data-year")).toBe("2024");
|
||||
await w.get('[data-year="2024"]').trigger("keydown", { key: "ArrowDown" });
|
||||
expect(document.activeElement?.getAttribute("data-year")).toBe("2027");
|
||||
await w.get('[data-year="2027"]').trigger("keydown", { key: "Escape" });
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(
|
||||
w.get('[data-slot="calendar-year-picker-trigger"]').element,
|
||||
);
|
||||
});
|
||||
it("selects a year without changing the selected day value, and respects close rejection", async () => {
|
||||
const w = fixture(':default-value="initial"', () => ({}), children);
|
||||
await w.get('[data-slot="calendar-year-picker-trigger"]').trigger("click");
|
||||
await flushPromises();
|
||||
await w.get('[data-year="2026"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(w.find('[data-slot="calendar-heading"]').exists()).toBe(false);
|
||||
expect(
|
||||
w.get('[data-slot="calendar-year-picker-trigger-heading"]').text(),
|
||||
).toContain("2026");
|
||||
expect(calendar(w).emitted("change")).toBeUndefined();
|
||||
const rejected = fixture(
|
||||
':is-year-picker-open="true"',
|
||||
() => ({}),
|
||||
children,
|
||||
);
|
||||
await flushPromises();
|
||||
await rejected.get('[data-year="2026"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(
|
||||
rejected
|
||||
.get('[data-slot="calendar-year-picker-grid"]')
|
||||
.attributes("data-open"),
|
||||
).toBe("true");
|
||||
});
|
||||
});
|
||||
@@ -25,3 +25,5 @@ SELECT-01 增加 `consume-select.mjs` / `select-contract.ts`。新 tarball 安
|
||||
DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消费者显式安装 `@internationalized/date@3.12.4`,运行完整 ISO 时区提交/SSR/样式检查,分别用 NodeNext 与 bundler 验证 DateValue、粒度、变体、范围和 segment 的正反类型,不从源码 alias 取公共类型。
|
||||
|
||||
M35–M36 使用 `consume-m35-m36.mjs` / `m35-m36-contract.ts`,新建 `/private/tmp/heroui-m35-consumer`。pnpm 11 的本地样式 tarball override 写在消费者 `pnpm-workspace.yaml`;不依赖已弃用的 package.json pnpm 字段。分别验证 ESM/CSS、真正 node SSR、所有部件导出,以及 bundler/NodeNext 类型正反例(含 Promise 参数推断)。
|
||||
|
||||
DATE-03 新增 `consume-calendar.mjs` / `calendar-contract.ts`,安装两份新 tarball 后运行 Node ESM/SSR/CSS 与 NodeNext/bundler 类型正反例,保留 DateField/Select 回归。Calendar 的泛型 Root 使用实际 SFC 参数类型核对单选、事件推断与错误模型,Cell/YearPicker Props 和作用域插槽不能退化为 any。
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { h } from "vue";
|
||||
import { CalendarDate, type DateValue } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarCell,
|
||||
CalendarGrid,
|
||||
CalendarYearPickerCell,
|
||||
type CalendarProps,
|
||||
type CalendarCellProps,
|
||||
type CalendarGridProps,
|
||||
type CalendarYearPickerGridProps,
|
||||
type CalendarYearPickerCellProps,
|
||||
} from "@heroui-vue/components";
|
||||
const date = new CalendarDate(2024, 2, 10);
|
||||
const single: CalendarProps = {
|
||||
modelValue: date,
|
||||
visibleDuration: { months: 2 },
|
||||
firstDayOfWeek: "mon",
|
||||
};
|
||||
const multiple: CalendarProps<"multiple"> = {
|
||||
selectionMode: "multiple",
|
||||
modelValue: [date],
|
||||
};
|
||||
const grid: CalendarGridProps = { offset: { months: 1 }, weekdayStyle: "long" };
|
||||
const cell: CalendarCellProps = { date };
|
||||
const year: CalendarYearPickerGridProps = {
|
||||
visibleYears: 20,
|
||||
format: { era: "short", year: "numeric" },
|
||||
};
|
||||
// @ts-expect-error single mode is not an array model
|
||||
const wrong: CalendarProps = { modelValue: [date] };
|
||||
const wrongMultiple: CalendarProps<"multiple"> = {
|
||||
selectionMode: "multiple",
|
||||
// @ts-expect-error multiple mode is not a scalar model
|
||||
modelValue: date,
|
||||
};
|
||||
// @ts-expect-error visible duration has a single unit
|
||||
const mixed: CalendarProps = { visibleDuration: { months: 1, weeks: 1 } };
|
||||
// @ts-expect-error DateValue is not JS Date
|
||||
const wrongDate: CalendarCellProps = { date: new Date() };
|
||||
// @ts-expect-error weekday format is explicit
|
||||
const wrongGrid: CalendarGridProps = { weekdayStyle: "numeric" };
|
||||
// @ts-expect-error no text selection mode
|
||||
const wrongMode: CalendarProps = { selectionMode: "none" };
|
||||
type RootProps = Parameters<typeof Calendar<"single">>[0];
|
||||
// @ts-expect-error actual SFC single mode keeps the scalar constraint
|
||||
const invalidRoot: RootProps = { modelValue: [date] };
|
||||
void invalidRoot;
|
||||
const rootProps: RootProps = {
|
||||
modelValue: date,
|
||||
"onUpdate:modelValue": (value) => {
|
||||
const expected: DateValue | null = value;
|
||||
// @ts-expect-error event payload is not a string
|
||||
const invalid: string = value;
|
||||
void [expected, invalid];
|
||||
},
|
||||
};
|
||||
type CellSlot = Parameters<
|
||||
NonNullable<InstanceType<typeof CalendarCell>["$slots"]["default"]>
|
||||
>[0];
|
||||
const state = {} as CellSlot;
|
||||
const selected: boolean = state.isSelected;
|
||||
// @ts-expect-error slot state retains boolean, not any
|
||||
const invalidSlot: number = state.isSelected;
|
||||
void [rootProps, selected, invalidSlot];
|
||||
h(CalendarGrid, grid);
|
||||
h(CalendarYearPickerCell, { year: 2024 });
|
||||
void [
|
||||
single,
|
||||
multiple,
|
||||
grid,
|
||||
cell,
|
||||
year,
|
||||
wrong,
|
||||
wrongMultiple,
|
||||
mixed,
|
||||
wrongDate,
|
||||
wrongGrid,
|
||||
wrongMode,
|
||||
];
|
||||
|
||||
// @ts-expect-error a year cell requires a numeric year
|
||||
const missingYear: CalendarYearPickerCellProps = {};
|
||||
void missingYear;
|
||||
@@ -0,0 +1,63 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import * as ui from "@heroui-vue/components";
|
||||
const names = [
|
||||
"Calendar",
|
||||
"CalendarRoot",
|
||||
"CalendarHeader",
|
||||
"CalendarHeading",
|
||||
"CalendarNavButton",
|
||||
"CalendarGrid",
|
||||
"CalendarGridHeader",
|
||||
"CalendarGridBody",
|
||||
"CalendarHeaderCell",
|
||||
"CalendarCell",
|
||||
"CalendarCellIndicator",
|
||||
"CalendarYearPickerTrigger",
|
||||
"CalendarYearPickerTriggerHeading",
|
||||
"CalendarYearPickerTriggerIndicator",
|
||||
"CalendarYearPickerGrid",
|
||||
"CalendarYearPickerGridBody",
|
||||
"CalendarYearPickerCell",
|
||||
];
|
||||
for (const name of names) assert.ok(ui[name], name);
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
ui.Calendar,
|
||||
{
|
||||
defaultValue: new CalendarDate(2024, 2, 29),
|
||||
defaultFocusedValue: new CalendarDate(2024, 2, 29),
|
||||
locale: "en-US",
|
||||
timeZone: "UTC",
|
||||
},
|
||||
() => [
|
||||
h(ui.CalendarHeading),
|
||||
h(ui.CalendarGrid, () => [
|
||||
h(ui.CalendarGridHeader),
|
||||
h(ui.CalendarGridBody),
|
||||
]),
|
||||
h(ui.CalendarYearPickerGrid, () => h(ui.CalendarYearPickerGridBody)),
|
||||
],
|
||||
),
|
||||
}),
|
||||
);
|
||||
assert.match(html, /2024-02-29/);
|
||||
assert.match(html, /data-selected="true"/);
|
||||
assert.match(html, /February 2024/);
|
||||
const css = fs.readFileSync(
|
||||
import.meta.resolve("@heroui-vue/styles/css").replace("file://", ""),
|
||||
"utf8",
|
||||
);
|
||||
for (const token of [
|
||||
".hv-calendar__cell",
|
||||
".hv-calendar--week-view",
|
||||
".hv-calendar--day-view",
|
||||
".hv-calendar-year-picker__year-cell",
|
||||
])
|
||||
assert.ok(css.includes(token), token);
|
||||
console.log("Calendar independent tarball ESM/Node SSR/CSS passed");
|
||||
Reference in New Issue
Block a user