feat: migrate public DateRangePicker with shared range field and calendar owners
This commit is contained in:
@@ -110,6 +110,11 @@ export const componentItems: DocsItem[] = [
|
||||
url: "/components/date-picker",
|
||||
category: "date-and-time",
|
||||
},
|
||||
{
|
||||
title: "DateRangePicker 日期范围选择器",
|
||||
url: "/components/date-range-picker",
|
||||
category: "date-and-time",
|
||||
},
|
||||
{
|
||||
title: "Description 描述",
|
||||
url: "/components/description",
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
---
|
||||
title: DateRangePicker 日期范围选择器
|
||||
description: 通过 DateField 与 RangeCalendar 组合的可组合日期范围选择器
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import {
|
||||
DateRangePicker,
|
||||
DateField,
|
||||
Label,
|
||||
RangeCalendar,
|
||||
} from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="date-range-picker-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
`DateRangePicker` 采用组合优先 API。显式组合 `DateField` 与 `RangeCalendar` 以控制结构与样式。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
Label,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker>
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
```
|
||||
|
||||
> Vue 保留 `slot` 作为插槽语法,固定源 `DateField.Input slot="start"` / `slot="end"` 的端点语义改由可类型检查的 `DateFieldInput endpoint="start" | "end"` 表达。两个端点共用 `DateFieldGroup`、`DateFieldInputContainer`、`DateFieldSegment` 与 `DateFieldSuffix`,没有另建同义日期部件。
|
||||
|
||||
> **DateRangePicker** 拥有唯一的接受范围值、字段校验、两个命名提交值和原生 reset;未显式绑定值的 RangeCalendar 继承该范围、约束、locale/dir、禁用/只读/无效与非连续范围策略。显式 `v-model`、`default-value`、`min-value`、`max-value`、`is-date-unavailable`、`allows-non-contiguous-ranges` 覆盖对应继承项。
|
||||
|
||||
## 示例
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="date-range-picker-disabled" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="date-range-picker-controlled" />
|
||||
|
||||
### 表单校验
|
||||
|
||||
<ComponentPreview name="date-range-picker-with-validation" />
|
||||
|
||||
### 格式选项
|
||||
|
||||
使用 `granularity`、`hourCycle`、`hideTimeZone`、`shouldForceLeadingZeros` 等 props 控制 DateRangePicker 值的显示方式。
|
||||
|
||||
<ComponentPreview name="date-range-picker-format-options" />
|
||||
|
||||
### 表单示例
|
||||
|
||||
<ComponentPreview name="date-range-picker-form-example" />
|
||||
|
||||
### 自定义指示器
|
||||
|
||||
未提供默认插槽内容时,`DateRangePickerTriggerIndicator` 渲染默认日历图标。传入子元素可替换。
|
||||
|
||||
<ComponentPreview name="date-range-picker-with-custom-indicator" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
Vue 版本使用 `as` 与原生属性替代 React `render`;以下示例在根、标签、字段组、分段和触发器上设置自定义元素与 `data-custom`。
|
||||
|
||||
<ComponentPreview name="date-range-picker-render-function" />
|
||||
|
||||
### 国际化日历
|
||||
|
||||
默认情况下,DateRangePicker 使用用户 locale 的日历系统显示日期。可用 `ConfigProvider` 包裹并设置 [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="date-range-picker-international-calendar" />
|
||||
|
||||
**Note:** 无论显示的 locale 如何,`change` 事件始终返回与 `value` 或 `defaultValue` 相同日历系统的日期(未提供 value 时为 Gregorian)。这确保应用逻辑在单一日历系统下一致运行,同时仍可按用户偏好格式显示日期。
|
||||
|
||||
完整支持的日历系统及其标识符列表请参阅:
|
||||
|
||||
- [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)
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="date-range-picker-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
使用 `@layer components` 自定义 DateRangePicker 基础类。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-date-range-picker {
|
||||
@apply inline-flex flex-col gap-1;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__trigger {
|
||||
@apply inline-flex items-center justify-between;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__trigger-indicator {
|
||||
@apply text-muted;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__range-separator {
|
||||
@apply px-2 text-default;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__popover {
|
||||
@apply min-w-[var(--reka-popper-anchor-width)] p-0;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 命名以便复用自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
DateRangePicker 在 `packages/styles/components/date-range-picker.css` 中使用以下类:
|
||||
|
||||
- `.hv-date-range-picker` - 根包裹层
|
||||
- `.hv-date-range-picker__trigger` - 打开 popover 的触发器部分
|
||||
- `.hv-date-range-picker__trigger-indicator` - 默认/自定义指示器 slot
|
||||
- `.hv-date-range-picker__range-separator` - 开始与结束日期输入之间的分隔符
|
||||
- `.hv-date-range-picker__popover` - Popover 内容包裹层
|
||||
|
||||
### 交互状态
|
||||
|
||||
DateRangePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态:
|
||||
|
||||
- **Open**:触发器上 `[data-open="true"]`
|
||||
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
|
||||
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Hover**:触发器上 `:hover`
|
||||
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
|
||||
- **Read only**:根容器上 `[data-readonly="true"]`
|
||||
- **Required**:根容器上 `[data-required="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹层能力,通过 Vue `v-model`、具名部件与作用域插槽表达。未列出的 React 专属类型、Context 与 PressEvent 不导出。
|
||||
|
||||
### DateRangePicker
|
||||
|
||||
#### Value Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------ | --------------------------------------------------------------- | -------- | ------------------------------------------------------------------ |
|
||||
| `modelValue` / `value` | `{ start: DateValue; end: DateValue } \| null` | - | 受控接受范围。显式 `null` 表示空值,优先于 `value`。 |
|
||||
| `defaultValue` | `{ start: DateValue; end: DateValue } \| null` | - | 非受控初始范围。 |
|
||||
| `update:modelValue` / `change` | `(value: { start: DateValue; end: DateValue } \| null) => void` | - | 完整范围接受值变化时调用;同一次编辑只触发一次,半个范围不会提交。 |
|
||||
| `placeholderValue` | `DateValue \| null` | 本地今天 | 空值时影响分段占位、显示历法、日历初始焦点和时间模板。 |
|
||||
|
||||
#### Open Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------------------------------------------- | --------------------------- | ------- | ------------------------------------------------------ |
|
||||
| `open` / `isOpen` | `boolean` | - | 受控 popover 打开状态。`open` 优先。 |
|
||||
| `defaultOpen` | `boolean` | `false` | 非受控初始打开状态。 |
|
||||
| `update:open` / `update:isOpen` / `openChange` | `(isOpen: boolean) => void` | - | popover 打开状态变化时调用。 |
|
||||
| `shouldCloseOnSelect` | `boolean` | `true` | 完成第二个端点后是否关闭 popover;第一次点击不会关闭。 |
|
||||
|
||||
#### Validation Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------------- | ------------------------------------------------------------------------------------ | ---------- | ------------------------------------------------ |
|
||||
| `isRequired` | `boolean` | `false` | 是否在提交表单前要求完整范围。 |
|
||||
| `isInvalid` | `boolean` | - | 标记字段为无效以显示校验状态。 |
|
||||
| `minValue` | `DateValue \| null` | - | 最小可选日期,同时约束两个端点、字段校验与日历。 |
|
||||
| `maxValue` | `DateValue \| null` | - | 最大可选日期,同时约束两个端点、字段校验与日历。 |
|
||||
| `isDateUnavailable` | `(date: DateValue) => boolean` | - | 标记不可用日期;端点为不可用时阻止提交该范围。 |
|
||||
| `allowsNonContiguousRanges` | `boolean` | `false` | 允许范围跨越不可用内点;始终不能跨越禁用日期。 |
|
||||
| `validate` | `(value: { start; end } \| null) => string \| string[] \| true \| null \| undefined` | - | 自定义校验函数。 |
|
||||
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 使用原生 HTML 表单校验还是 ARIA 属性。 |
|
||||
|
||||
#### Format Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------- | ------------------------------------------------------------- | ------------------------- | ----------------------------------------------- |
|
||||
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 由接受值推断 | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
|
||||
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
|
||||
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
|
||||
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
|
||||
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
|
||||
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
|
||||
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 RangeCalendar 的一周起始日。 |
|
||||
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 RangeCalendar 翻页按可见范围或单步前进。 |
|
||||
|
||||
#### State & Form Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------- | --------- | ------- | --------------------------------------------------------- |
|
||||
| `isDisabled` / `disabled` | `boolean` | `false` | 禁用两个端点、触发器与日历选择。 |
|
||||
| `isReadOnly` | `boolean` | `false` | 只读:可查看与提交,不可编辑或选择;触发器同样禁用。 |
|
||||
| `startName` | `string` | - | 起始日期的原生表单 name;以 ISO 8601 字符串提交起始端点。 |
|
||||
| `endName` | `string` | - | 结束日期的原生表单 name;以 ISO 8601 字符串提交结束端点。 |
|
||||
| `form` | `string` | - | 关联到外部表单 id,两个命名值都提交到该表单。 |
|
||||
| `autoFocus` | `boolean` | `false` | 挂载后聚焦第一个日期分段。 |
|
||||
| `autoComplete` | `string` | `'off'` | 传给两个隐藏 ISO 文本输入。 |
|
||||
| `as` | `string` | `'div'` | 根元素标签;属性、事件与引用归属该元素。 |
|
||||
|
||||
### Composition Parts
|
||||
|
||||
| 组件 | 描述 |
|
||||
| ----------------------------------------- | ------------------------------------------------------------------------ |
|
||||
| `DateRangePicker` / `DateRangePickerRoot` | 根日期范围选择器容器与唯一状态所有者。 |
|
||||
| `DateRangePickerTrigger` | 触发按钮,通常渲染在 `DateFieldSuffix` 内;可取消的 click 不会打开面板。 |
|
||||
| `DateRangePickerTriggerIndicator` | 带默认日历图标的指示器 slot。 |
|
||||
| `DateRangePickerRangeSeparator` | 开始与结束日期输入之间的分隔符;默认 `" - "`,`aria-hidden`。 |
|
||||
| `DateRangePickerPopover` | `RangeCalendar` 内容的 Popover 包裹层;默认 `placement="bottom"`。 |
|
||||
|
||||
日期输入使用既有的 `DateFieldGroup`、`DateFieldInput`、`DateFieldInputContainer`、`DateFieldSegment`、`DateFieldSuffix`;端点通过 `DateFieldInput` 的 `endpoint` prop 选择。日历使用 `RangeCalendar*` 部件;年份切换复用既有 `CalendarYearPicker*` 部件,对应固定源的 `RangeCalendar.YearPicker*`,没有新增同义年份部件。
|
||||
|
||||
### DateFieldInput 端点入口
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------ | ------- | --------------------------------------------------------------------------- |
|
||||
| `endpoint` | `'start' \| 'end'` | - | 在 DateRangePicker 根内选择范围端点;缺失时回退到普通 DateField/TimeField。 |
|
||||
| `as` | `string` | `'div'` | 两端输入容器标签。 |
|
||||
|
||||
端点输入共享一个字段禁用/只读/无效/前导零与 locale 上下文;`endpoint` 仅选择 Reka 的起点或终点分段集合,不创建第二个接受值。
|
||||
|
||||
### 默认插槽与 Render Props
|
||||
|
||||
默认插槽提供响应式状态和操作。`state.timeRange` 与 `state.setTimeRange` 供格式选项示例中的两个 TimeField 使用,并走同一个接受值协议。
|
||||
|
||||
| 字段 | 类型 | 描述 |
|
||||
| ----------------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
||||
| `value` | `{ start: DateValue; end: DateValue } \| null` | 当前接受范围;不完整草稿不会出现在这里。 |
|
||||
| `timeRange` | `{ start: DateRangePickerTimeValue \| null; end: DateRangePickerTimeValue \| null } \| null` | 两端当前时间;空值时来自未提交的时间草稿。 |
|
||||
| `isOpen` | `boolean` | popover 是否打开。 |
|
||||
| `isDisabled` | `boolean` | 是否禁用。 |
|
||||
| `isReadOnly` | `boolean` | 是否只读。 |
|
||||
| `isRequired` | `boolean` | 是否必填。 |
|
||||
| `isInvalid` | `boolean` | 当前是否无效。 |
|
||||
| `isFocusWithin` / `isFocused` | `boolean` | 字段是否聚焦。 |
|
||||
| `isFocusVisible` | `boolean` | 键盘焦点是否可见。 |
|
||||
| `validationErrors` | `string[]` | 当前可显示的校验错误。 |
|
||||
| `state` | `DateRangePickerState` | `value`、`timeRange`、`setValue`、`setTimeRange` 的响应式视图。 |
|
||||
| `open` / `close` / `toggle` | `() => void` | 打开、关闭或切换 popover。 |
|
||||
|
||||
`DateRangePickerState.setTimeRange` 接受 `{ start, end }`,两端可分别编辑;另一端已有值或草稿会保留。空值先改时间只保存草稿,不提交半个范围;随后完成两个日历端点时组合为完整值。
|
||||
|
||||
### DateRangePickerTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------------- | --------- | ---------- | ---------------------------------------- |
|
||||
| `as` | `string` | `'button'` | 触发元素标签;默认生成 `type="button"`。 |
|
||||
| `asChild` | `boolean` | `false` | 将行为合并到单个子元素。 |
|
||||
| `isDisabled` | `boolean` | - | 额外禁用触发器。 |
|
||||
| `class` / `style` | - | - | 与组件样式合并。 |
|
||||
|
||||
### DateRangePickerRangeSeparator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | -------- | -------- | ------------------------ |
|
||||
| `as` | `string` | `'span'` | 分隔符元素标签。 |
|
||||
| `children` | `string` | `' - '` | 默认文本;插槽内容优先。 |
|
||||
|
||||
### DateRangePickerPopover
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------------- | --------------------------------------------------- | ---------- | --------------------------------------------------------------- |
|
||||
| `placement` | `'top' \| 'bottom' \| 'left' \| 'right'` 及逻辑变体 | `'bottom'` | 优先定位方向。 |
|
||||
| `offset` | `number` | `8` | 与锚点间距。 |
|
||||
| `crossOffset` | `number` | `0` | 交叉轴偏移。 |
|
||||
| `shouldFlip` | `boolean` | `true` | 空间不足时翻转。 |
|
||||
| `containerPadding` | `number` | `12` | 视口碰撞内边距。 |
|
||||
| `to` | `string \| HTMLElement` | body | Portal 目标。 |
|
||||
| `isDismissable` | `boolean` | `true` | 是否允许外部点击关闭。 |
|
||||
| `isKeyboardDismissDisabled` | `boolean` | `false` | 是否禁止 Escape 关闭;分段、日历和弹层使用同一策略。 |
|
||||
| `@escape-key-down` | `(event: Event) => void` | - | Escape 关闭前的可取消回调;调用 `preventDefault()` 可保持打开。 |
|
||||
|
||||
### Variants
|
||||
|
||||
`dateRangePickerVariants` 提供 `base`、`trigger`、`triggerIndicator`、`rangeSeparator`、`popover` 五个 slot 类名;`DateRangePickerVariants` 为其 variants 类型。样式数值来自固定基线,仅命名空间改为 `hv-`。
|
||||
|
||||
### Related packages
|
||||
|
||||
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
||||
- 本库 `ConfigProvider` — 为子树覆盖 locale、书写方向与 Portal 目标
|
||||
|
||||
## 相关组件
|
||||
|
||||
[DateField 日期字段](./date-field) · [RangeCalendar 范围日历](./range-calendar) · [DatePicker 日期选择器](./date-picker) · [TimeField 时间字段](./time-field)
|
||||
|
||||
## Vue 公共契约与差异
|
||||
|
||||
- `DateRangePicker` 与 `DateRangePickerRoot` 是同一根组件;`DateRangePickerTrigger`、`DateRangePickerTriggerIndicator`、`DateRangePickerRangeSeparator`、`DateRangePickerPopover` 为独立具名导出,没有 React 对象式成员、Context、`PressEvent` 或 RenderFunction 类型。
|
||||
- 固定源 `slot="start"` / `slot="end"` 改为 `DateFieldInput endpoint="start" | "end"`;Vue 的 `slot` 保留为插槽语法,端点入口可类型检查。
|
||||
- 主值使用 `v-model`(`modelValue` / `update:modelValue`),`value` 为兼容别名;显式 `modelValue="null"` 是受控空值,不能按未传处理。`open` / `isOpen` 与 `defaultOpen` 的优先级相同,`open` 优先。
|
||||
- 起止分段、日历选择和时间编辑共用一个接受范围协议。只有两个端点都完整时才提交 `change`;只完成一端、第一下日历点击或空值先改时间都只是草稿。清空两个端点会提交 `null`;只清空一端在关闭 popover、外部替换或 reset 时回到接受状态。受控父组件拒绝提案时显示与提交值恢复接受状态,再次提出同一范围仍会触发事件。
|
||||
- 日历选择始终以有序范围提交;字段手动输入允许反向范围并显示校验错误,不会静默交换端点。日历跨过不可用内点由 `allowsNonContiguousRanges` 控制,禁用日期始终不能跨越。
|
||||
- 未显式绑定 `v-model`/`value`/`defaultValue` 的内嵌 RangeCalendar 继承范围值、min/max、禁用、只读、无效、locale/dir、`allowsNonContiguousRanges` 与不可用规则;显式值/约束覆盖对应继承项。独立 RangeCalendar 行为不变。
|
||||
- 日历修改日期时保留两端各自的日期类、时间、时区与历法;`setTimeRange` 修改时间时保留日期,并分别维护两端草稿。粒度、locale 与时区显示选项不会悄悄截断提交值。
|
||||
- Picker 负责 `startName` / `endName` 对应的两个日期原生命名输入、required/错误关联和 reset;不会额外提交第三个合并值。同名配置会产生两个同名字段条目。内嵌 RangeCalendar 不创建提交值;格式选项示例中独立 `startTime` / `endTime` 的 TimeField 保留各自提交语义。
|
||||
- 触发器为原生 `button`,`type="button"`;调用者取消其可取消 click 时不打开。触发器的可访问名称优先取显式 `aria-label`,其次由字段标签 id 组成;没有标签时提供 `日历` / `Calendar` 默认名。只读时触发器禁用。缺少 `DateRangePicker` 的部件会抛出明确错误;缺少端点的范围字段输入同样会报错。
|
||||
- 默认日历图标移植固定源 SVG,保留 Apache-2.0 来源;示例中的自定义图标使用 `@tabler/icons-vue`。`render` 改为 `as`、class/style 与原生属性;作用域插槽替代 React 渲染函数。
|
||||
- 固定中文页的 10 个预览按原次序迁移;`index.ts` 中额外的 `InputContainer` 导出未被页面引用,作为非页面示例记录,公开 `DateFieldInputContainer` 组合由格式选项示例验证。`format-options-no-ssr` 的客户端动态包装不迁移为服务端工程。
|
||||
- 不支持 SSR/水合/Nuxt 服务端专项;逐像素自动对比、完整读屏与真机矩阵不作为本轮门槛。Reka 无 React Aria 的 `data-entering`/`data-exiting` 自动等价标记,本库在 Popover 生命周期上显式生成。
|
||||
@@ -0,0 +1,73 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/basic.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker class="w-80" end-name="endDate" start-name="startDate">
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -0,0 +1,102 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/controlled.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Button,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { computed, shallowRef } from "vue";
|
||||
const start = today(getLocalTimeZone());
|
||||
const value = shallowRef<{ start: DateValue; end: DateValue } | null>({
|
||||
end: start.add({ days: 4 }),
|
||||
start,
|
||||
});
|
||||
const summary = computed(() =>
|
||||
value.value
|
||||
? value.value.start.toString() + " 至 " + value.value.end.toString()
|
||||
: "(空)",
|
||||
);
|
||||
function setWeek() {
|
||||
const nextStart = today(getLocalTimeZone());
|
||||
value.value = { end: nextStart.add({ days: 6 }), start: nextStart };
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex w-80 flex-col gap-4">
|
||||
<DateRangePicker v-model="value" end-name="endDate" start-name="startDate">
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
<Description>当前值:{{ summary }}</Description>
|
||||
<div class="flex gap-2">
|
||||
<Button variant="tertiary" @click="setWeek">设为一周</Button>
|
||||
<Button variant="tertiary" @click="value = null">清空</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/custom-styles.tsx, Apache-2.0.
|
||||
import {
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
Label,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarHeading,
|
||||
RangeCalendarNavButton,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker class="w-80" end-name="checkout" start-name="checkin">
|
||||
<Label>入住日期</Label>
|
||||
<DateFieldGroup
|
||||
full-width
|
||||
class="rounded-xl border border-border/80 bg-default shadow-sm"
|
||||
variant="secondary"
|
||||
>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator class="text-muted" />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger class="text-muted">
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover class="border border-border/80 shadow-sm">
|
||||
<RangeCalendar aria-label="入住日期" class="rounded-2xl bg-surface p-2">
|
||||
<RangeCalendarHeader>
|
||||
<RangeCalendarHeading class="font-medium text-foreground" />
|
||||
<RangeCalendarNavButton
|
||||
class="text-muted hover:bg-default"
|
||||
slot="previous"
|
||||
/>
|
||||
<RangeCalendarNavButton
|
||||
class="text-muted hover:bg-default"
|
||||
slot="next"
|
||||
/>
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell class="text-xs text-muted">
|
||||
{{ day }}
|
||||
</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/disabled.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||
const start = today(getLocalTimeZone());
|
||||
const value = { end: start.add({ days: 4 }), start };
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker
|
||||
class="w-80"
|
||||
is-disabled
|
||||
end-name="endDate"
|
||||
start-name="startDate"
|
||||
:value="value"
|
||||
>
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<Description>该日期范围选择器已禁用。</Description>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -0,0 +1,122 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/form-example.tsx, Apache-2.0.
|
||||
import {
|
||||
Button,
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
Description,
|
||||
FieldError,
|
||||
Form,
|
||||
Label,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { computed, onBeforeUnmount, shallowRef } from "vue";
|
||||
|
||||
const value = shallowRef<{ start: DateValue; end: DateValue } | null>(null);
|
||||
const isSubmitting = shallowRef(false);
|
||||
const currentDate = today(getLocalTimeZone());
|
||||
const isInvalid = computed(
|
||||
() =>
|
||||
value.value != null &&
|
||||
(value.value.start.compare(currentDate) < 0 ||
|
||||
value.value.end.compare(value.value.start) < 0),
|
||||
);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
function submit() {
|
||||
if (!value.value || isInvalid.value || isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
timer = setTimeout(() => {
|
||||
value.value = null;
|
||||
isSubmitting.value = false;
|
||||
}, 1200);
|
||||
}
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
</script>
|
||||
<template>
|
||||
<Form class="flex w-80 flex-col gap-3" @submit.prevent="submit">
|
||||
<DateRangePicker
|
||||
v-model="value"
|
||||
is-required
|
||||
end-name="tripEndDate"
|
||||
:is-invalid="isInvalid"
|
||||
:min-value="currentDate"
|
||||
start-name="tripStartDate"
|
||||
>
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<FieldError v-if="isInvalid">请选择从今天起的有效日期范围。</FieldError>
|
||||
<Description v-else>选择入住与退房日期。</Description>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
<Button
|
||||
class="w-full"
|
||||
:is-disabled="!value || isInvalid"
|
||||
:is-pending="isSubmitting"
|
||||
type="submit"
|
||||
>
|
||||
{{ isSubmitting ? "提交中…" : "提交" }}
|
||||
</Button>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,300 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/format-options.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldInputContainer,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Select,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
Separator,
|
||||
Switch,
|
||||
SwitchContent,
|
||||
SwitchControl,
|
||||
SwitchThumb,
|
||||
TimeField,
|
||||
TimeFieldGroup,
|
||||
TimeFieldInput,
|
||||
TimeFieldSegment,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
DateFormatter,
|
||||
getLocalTimeZone,
|
||||
parseDate,
|
||||
parseZonedDateTime,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
type Granularity = "day" | "hour" | "minute" | "second";
|
||||
type HourCycle = 12 | 24;
|
||||
type DateRange = { start: DateValue; end: DateValue };
|
||||
|
||||
const granularity = ref<Granularity>("minute");
|
||||
const hourCycle = ref<HourCycle>(12);
|
||||
const hideTimeZone = ref(false);
|
||||
const shouldForceLeadingZeros = ref(false);
|
||||
const cycle = computed(() => (hourCycle.value === 24 ? 24 : 12) as 12 | 24);
|
||||
const timeGranularity = computed(() =>
|
||||
granularity.value !== "day" ? granularity.value : undefined,
|
||||
);
|
||||
const showTimeField = computed(() => !!timeGranularity.value);
|
||||
const defaultValue = computed<DateRange>(() => {
|
||||
const localTimeZone = getLocalTimeZone();
|
||||
if (granularity.value === "day")
|
||||
return {
|
||||
end: parseDate("2025-02-10"),
|
||||
start: parseDate("2025-02-03"),
|
||||
};
|
||||
return {
|
||||
end: parseZonedDateTime(`2026-02-10T18:45:00[${localTimeZone}]`),
|
||||
start: parseZonedDateTime(`2026-02-03T08:45:00[${localTimeZone}]`),
|
||||
};
|
||||
});
|
||||
const dateFormatter = new DateFormatter("zh-CN", {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
});
|
||||
function formatDate(range: DateRange) {
|
||||
const localTimeZone = getLocalTimeZone();
|
||||
return dateFormatter.formatRange(
|
||||
range.start.toDate(localTimeZone),
|
||||
range.end.toDate(localTimeZone),
|
||||
);
|
||||
}
|
||||
const granularityOptions: { label: string; value: Granularity }[] = [
|
||||
{ label: "日", value: "day" },
|
||||
{ label: "时", value: "hour" },
|
||||
{ label: "分", value: "minute" },
|
||||
{ label: "秒", value: "second" },
|
||||
];
|
||||
const hourCycleOptions: { label: string; value: HourCycle }[] = [
|
||||
{ label: "12 小时制", value: 12 },
|
||||
{ label: "24 小时制", value: 24 },
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex w-full flex-col gap-4">
|
||||
<DateRangePicker
|
||||
:key="granularity"
|
||||
class="w-max min-w-80"
|
||||
:default-value="defaultValue"
|
||||
end-name="endDate"
|
||||
:granularity="granularity"
|
||||
:hide-time-zone="hideTimeZone"
|
||||
:hour-cycle="cycle"
|
||||
:should-force-leading-zeros="shouldForceLeadingZeros"
|
||||
start-name="startDate"
|
||||
>
|
||||
<template #default="{ state }">
|
||||
<Label>日期范围</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInputContainer>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldInputContainer>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<!-- Portaled content keeps an auto-sized wrapper; the pinned example's
|
||||
w-full maps to the 252px calendar plus the popover's 24px padding. -->
|
||||
<DateRangePickerPopover class="flex w-[276px] flex-col gap-3">
|
||||
<RangeCalendar aria-label="出行日期" class="w-full">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
<div v-if="showTimeField" class="flex flex-col gap-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<Label>开始时间</Label>
|
||||
<TimeField
|
||||
aria-label="开始时间"
|
||||
:granularity="timeGranularity"
|
||||
:hide-time-zone="hideTimeZone"
|
||||
:hour-cycle="cycle"
|
||||
name="startTime"
|
||||
:should-force-leading-zeros="shouldForceLeadingZeros"
|
||||
:value="state.timeRange?.start ?? null"
|
||||
@change="
|
||||
state.setTimeRange({
|
||||
end: state.timeRange?.end ?? null,
|
||||
start: $event,
|
||||
})
|
||||
"
|
||||
>
|
||||
<TimeFieldGroup variant="secondary">
|
||||
<TimeFieldInput v-slot="{ segment }">
|
||||
<TimeFieldSegment :segment="segment" />
|
||||
</TimeFieldInput>
|
||||
</TimeFieldGroup>
|
||||
</TimeField>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<Label>结束时间</Label>
|
||||
<TimeField
|
||||
aria-label="结束时间"
|
||||
:granularity="timeGranularity"
|
||||
:hide-time-zone="hideTimeZone"
|
||||
:hour-cycle="cycle"
|
||||
name="endTime"
|
||||
:should-force-leading-zeros="shouldForceLeadingZeros"
|
||||
:value="state.timeRange?.end ?? null"
|
||||
@change="
|
||||
state.setTimeRange({
|
||||
end: $event,
|
||||
start: state.timeRange?.start ?? null,
|
||||
})
|
||||
"
|
||||
>
|
||||
<TimeFieldGroup variant="secondary">
|
||||
<TimeFieldInput v-slot="{ segment }">
|
||||
<TimeFieldSegment :segment="segment" />
|
||||
</TimeFieldInput>
|
||||
</TimeFieldGroup>
|
||||
</TimeField>
|
||||
</div>
|
||||
</div>
|
||||
<span class="mt-1 text-xs text-muted">
|
||||
已选:
|
||||
{{
|
||||
state.value && state.value.start && state.value.end
|
||||
? formatDate({ end: state.value.end, start: state.value.start })
|
||||
: "未选择日期"
|
||||
}}
|
||||
</span>
|
||||
</DateRangePickerPopover>
|
||||
</template>
|
||||
</DateRangePicker>
|
||||
|
||||
<Separator class="my-5" />
|
||||
|
||||
<Label class="text-xs font-medium text-muted">格式选项</Label>
|
||||
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<div class="flex flex-col gap-1">
|
||||
<Select
|
||||
class="w-[120px]"
|
||||
:model-value="granularity"
|
||||
variant="secondary"
|
||||
@update:model-value="granularity = $event as Granularity"
|
||||
>
|
||||
<Label>粒度</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in granularityOptions"
|
||||
:id="option.value"
|
||||
:key="option.value"
|
||||
:text-value="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<Select
|
||||
class="w-[120px]"
|
||||
:model-value="hourCycle"
|
||||
variant="secondary"
|
||||
@update:model-value="hourCycle = Number($event) as HourCycle"
|
||||
>
|
||||
<Label>小时制</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in hourCycleOptions"
|
||||
:id="option.value"
|
||||
:key="option.value"
|
||||
:text-value="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex min-w-[529px] flex-col gap-2">
|
||||
<Switch v-model:checked="hideTimeZone">
|
||||
<SwitchContent>
|
||||
<SwitchControl><SwitchThumb /></SwitchControl>
|
||||
隐藏时区
|
||||
</SwitchContent>
|
||||
</Switch>
|
||||
<Switch v-model:checked="shouldForceLeadingZeros">
|
||||
<SwitchContent>
|
||||
<SwitchControl><SwitchThumb /></SwitchControl>
|
||||
强制前导零
|
||||
</SwitchContent>
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/international-calendar.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
ConfigProvider,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||
const start = today(getLocalTimeZone());
|
||||
const value = { end: start.add({ days: 7 }), start };
|
||||
</script>
|
||||
<template>
|
||||
<ConfigProvider locale="hi-IN-u-ca-indian">
|
||||
<DateRangePicker
|
||||
class="w-80"
|
||||
end-name="endDate"
|
||||
start-name="startDate"
|
||||
:default-value="value"
|
||||
>
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</ConfigProvider>
|
||||
</template>
|
||||
@@ -0,0 +1,100 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/render-function.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker
|
||||
class="w-80"
|
||||
as="section"
|
||||
data-custom="date-range-picker"
|
||||
end-name="endDate"
|
||||
start-name="startDate"
|
||||
>
|
||||
<Label data-custom="date-range-picker-label">出行日期</Label>
|
||||
<DateFieldGroup full-width as="div" data-custom="date-field-group">
|
||||
<DateFieldInput
|
||||
as="div"
|
||||
data-custom="date-field-input"
|
||||
endpoint="start"
|
||||
v-slot="{ segment }"
|
||||
>
|
||||
<DateFieldSegment
|
||||
as="span"
|
||||
data-custom="date-field-segment"
|
||||
:segment="segment"
|
||||
/>
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput
|
||||
as="div"
|
||||
data-custom="date-field-input"
|
||||
endpoint="end"
|
||||
v-slot="{ segment }"
|
||||
>
|
||||
<DateFieldSegment
|
||||
as="span"
|
||||
data-custom="date-field-segment"
|
||||
:segment="segment"
|
||||
/>
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger
|
||||
as="button"
|
||||
data-custom="date-range-picker-trigger"
|
||||
>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -0,0 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/with-custom-indicator.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconChevronDown } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker class="w-80" end-name="endDate" start-name="startDate">
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator>
|
||||
<IconChevronDown class="size-4" aria-hidden="true" />
|
||||
</DateRangePickerTriggerIndicator>
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<Description>通过传入自定义子元素替换默认日历图标。</Description>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -0,0 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 date-range-picker/with-validation.tsx, Apache-2.0.
|
||||
import {
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
FieldError,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { computed, shallowRef } from "vue";
|
||||
const value = shallowRef<{ start: DateValue; end: DateValue } | null>(null);
|
||||
const currentDate = today(getLocalTimeZone());
|
||||
const isInvalid = computed(
|
||||
() =>
|
||||
value.value != null &&
|
||||
(value.value.start.compare(currentDate) < 0 ||
|
||||
value.value.end.compare(value.value.start) < 0),
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<DateRangePicker
|
||||
v-model="value"
|
||||
is-required
|
||||
class="w-80"
|
||||
end-name="endDate"
|
||||
:is-invalid="isInvalid"
|
||||
:min-value="currentDate"
|
||||
start-name="startDate"
|
||||
>
|
||||
<Label>预订时段</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<FieldError>请选择从今天起的有效日期范围。</FieldError>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="预订时段">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>{{ day }}</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</template>
|
||||
@@ -58,6 +58,11 @@ const labs = [
|
||||
title: "DatePicker 嵌套弹层",
|
||||
component: defineAsyncComponent(() => import("./DatePickerLab.vue")),
|
||||
},
|
||||
{
|
||||
key: "date-range-picker-overlay",
|
||||
title: "DateRangePicker 嵌套弹层",
|
||||
component: defineAsyncComponent(() => import("./DateRangePickerLab.vue")),
|
||||
},
|
||||
{
|
||||
key: "overlay-components",
|
||||
title: "弹层公共组合",
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
CalendarYearPickerCell,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
Description,
|
||||
Label,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
RangeCalendar,
|
||||
RangeCalendarCell,
|
||||
RangeCalendarGrid,
|
||||
RangeCalendarGridBody,
|
||||
RangeCalendarGridHeader,
|
||||
RangeCalendarHeader,
|
||||
RangeCalendarHeaderCell,
|
||||
RangeCalendarNavButton,
|
||||
} from "@heroui-vue/components";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
const initial = {
|
||||
start: new CalendarDate(2024, 2, 10),
|
||||
end: new CalendarDate(2024, 2, 15),
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<main class="p-8">
|
||||
<Modal>
|
||||
<Button>打开嵌套弹层</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[460px]">
|
||||
<ModalCloseTrigger />
|
||||
<ModalHeader>
|
||||
<ModalHeading>嵌套日期范围选择器</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<DateRangePicker
|
||||
:default-value="initial"
|
||||
end-name="nested-end"
|
||||
start-name="nested-start"
|
||||
>
|
||||
<Label>出行日期</Label>
|
||||
<DateFieldGroup full-width>
|
||||
<DateFieldInput endpoint="start" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateRangePickerRangeSeparator />
|
||||
<DateFieldInput endpoint="end" v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<DateRangePickerTrigger>
|
||||
<DateRangePickerTriggerIndicator />
|
||||
</DateRangePickerTrigger>
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<Description>
|
||||
Escape 应先关闭范围日历,再关闭模态框。
|
||||
</Description>
|
||||
<DateRangePickerPopover>
|
||||
<RangeCalendar aria-label="嵌套出行日期">
|
||||
<RangeCalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<RangeCalendarNavButton slot="previous" />
|
||||
<RangeCalendarNavButton slot="next" />
|
||||
</RangeCalendarHeader>
|
||||
<RangeCalendarGrid>
|
||||
<RangeCalendarGridHeader v-slot="{ day }">
|
||||
<RangeCalendarHeaderCell>
|
||||
{{ day }}
|
||||
</RangeCalendarHeaderCell>
|
||||
</RangeCalendarGridHeader>
|
||||
<RangeCalendarGridBody v-slot="{ date }">
|
||||
<RangeCalendarCell :date="date" />
|
||||
</RangeCalendarGridBody>
|
||||
</RangeCalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody v-slot="{ year, date }">
|
||||
<CalendarYearPickerCell :year="year" :date="date" />
|
||||
</CalendarYearPickerGridBody>
|
||||
</CalendarYearPickerGrid>
|
||||
</RangeCalendar>
|
||||
</DateRangePickerPopover>
|
||||
</DateRangePicker>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">关闭</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</main>
|
||||
</template>
|
||||
+10
-4
@@ -29,7 +29,7 @@
|
||||
| combo-box | 已迁移(有已知差异) | ComboBox 五部件;24/24 基线例;可编辑输入 + 过滤 + 虚拟焦点、form-value key/text、menu-trigger 三态、多选 Value;见 B02 报告 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 已迁移(客户端,有已知差异) | DatePicker/Root、Trigger、TriggerIndicator、Popover;10/10 基线例;复用 DateField 字段、Calendar 视图/年份层与 Popover;唯一日期提交、受控拒绝/重试、时间草稿、locale/RTL、嵌套 Modal Escape;见 DATE-PICKER 结果。 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 已迁移(客户端,有已知差异) | DateRangePicker 五部件;10/10 基线例;复用双端点 DateField、RangeCalendar 与 Popover;完整范围/双命名提交/时间草稿/非连续策略;见 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 共用取值语义 |
|
||||
@@ -219,7 +219,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
|
||||
|
||||
## DATE-04 范围选择基建
|
||||
|
||||
共享日历视图已提取,私有范围选择与手势经过集成、SSR、水合和重点浏览器验证;这不代表 RangeCalendar 公共迁移完成。当前范围、触屏长按拖选与字段组合的待办见 [DATE-04](component-notes.md),公开收尾任务卡待实际前置核对后创建,旧DATE-05仅可从 [历史入口](history.md) 查询。
|
||||
共享日历视图已提取,私有范围选择与手势经过集成与重点浏览器验证;本轮之后 RangeCalendar 公共迁移已完成,见 [RANGE-CALENDAR 结果](tasks/results/RANGE-CALENDAR.md)。触屏长按拖选仍为已知缺口,旧DATE-05仅可从 [历史入口](history.md) 查询。
|
||||
|
||||
## COLOR-01 颜色基建
|
||||
|
||||
@@ -249,10 +249,16 @@ ComboBox/Autocomplete的正式组合、原30项返修和本轮定位/ref/ARIA/lo
|
||||
|
||||
公开 Root/九个具名部件、RangeCalendarOptions/Props/CalendarDateRange/CalendarRangeModel、Cell 状态与实例类型、rangeCalendarVariants;六个年份部件复用既有 CalendarYearPicker 具名导出。固定源中文 20 个预览、API/插槽/状态表与导航已接入,内核沿用既有范围接受值/锚点/手势与共享 Calendar view。公开组合、定向回归、真实浏览器和最终 tarball 验证见 [任务结果](tasks/results/RANGE-CALENDAR.md)。
|
||||
|
||||
两次点击、键盘、鼠标拖选及端点拖动可用;触屏长按拖选尚未实现。DOM 采用 td/gridcell + 原生 button + 内层样式 span;框架专属 render/Context/PressEvent 不移植,默认历法边界、属性和事件差异见组件文档。独立日历没有字段提交/reset;不代表 DatePicker/DateRangePicker 完成。
|
||||
两次点击、键盘、鼠标拖选及端点拖动可用;触屏长按拖选尚未实现。DOM 采用 td/gridcell + 原生 button + 内层样式 span;框架专属 render/Context/PressEvent 不移植,默认历法边界、属性和事件差异见组件文档。独立日历没有字段提交/reset;Picker 组合见 DatePicker 与 DateRangePicker 结果。
|
||||
|
||||
## DATE-PICKER 公共日期选择器(2026-10-26)
|
||||
|
||||
公开 DatePicker/Root、DatePickerTrigger、DatePickerTriggerIndicator、DatePickerPopover、datePickerVariants 及 Props/RenderProps/state 类型;字段输入复用 DateFieldGroup/Input/Segment/Suffix,日历复用 Calendar 与 CalendarYearPicker 具名部件。固定源中文 10 个预览、API/插槽/状态表与导航已接入;Picker 拥有唯一接受值、字段校验和原生命名提交,未显式绑定的内嵌 Calendar 继承值、上下界、不可用、禁用/只读/无效与 locale/dir。
|
||||
|
||||
分段编辑、日历选择和时间草稿走同一接受值协议;受控拒绝后可重试,日历修改保留日期类、时间、时区与历法,空值时间草稿在完成日期前不提交。触发器可访问名称取字段标签或显式 aria-label,只读时禁用;Escape 在分段内也关闭日历,嵌套 Modal 中先关闭 Picker 再关闭 Modal。范围选择、DateRangePicker 与颜色家族不在本项范围;完整证据和限制见 [任务结果](tasks/results/DATE-PICKER.md)。
|
||||
分段编辑、日历选择和时间草稿走同一接受值协议;受控拒绝后可重试,日历修改保留日期类、时间、时区与历法,空值时间草稿在完成日期前不提交。触发器可访问名称取字段标签或显式 aria-label,只读时禁用;Escape 在分段内也关闭日历,嵌套 Modal 中先关闭 Picker 再关闭 Modal。DateRangePicker 与颜色家族不在本项范围;完整证据和限制见 [任务结果](tasks/results/DATE-PICKER.md)。
|
||||
|
||||
## DATE-RANGE-PICKER 公共日期范围选择器(2026-10-26)
|
||||
|
||||
公开 DateRangePicker/Root、Trigger、TriggerIndicator、RangeSeparator、Popover、dateRangePickerVariants 及 Props/RenderProps/state/time 类型;起止输入复用 DateFieldGroup/Input/InputContainer/Segment/Suffix,端点为可类型检查的 `endpoint` prop;日历复用 RangeCalendar 与 CalendarYearPicker 具名部件。固定源中文 10 个预览、API/插槽/状态表与导航已接入;Picker 拥有唯一完整范围接受值、双端点字段校验、两个命名提交值和 reset,未显式绑定的内嵌 RangeCalendar 继承范围、上下界、不可用、禁用/只读/无效、locale/dir 与非连续策略。
|
||||
|
||||
不完整范围、第一下日历点击和空值时间草稿都不提交;清空两端提交 null,清空一端在关闭/外部替换/reset 时回到接受状态。受控拒绝后可重试,日历修改保留两端各自的日期类、时间、时区与历法,字段编辑保留不可显示精度。固定源 `slot="start"/"end"` 映射为 `endpoint` prop;格式选项的 `w-full` 弹层宽度映射为 252px 日历加 24px 内边距。真实浏览器、定向回归和最终 tarball 验证见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。
|
||||
|
||||
+5
-5
@@ -8,21 +8,21 @@
|
||||
|
||||
- 展示、按钮、导航、展开、反馈等主要家族已有公共组件与文档。
|
||||
- 字段/Form、Checkbox/Radio、数值/Slider/OTP、弹层/菜单、集合/ListBox/Select、ComboBox/Autocomplete、Tag、Toast/Table已集成。
|
||||
- DateField、TimeField、Calendar、CalendarYearPicker 与 DatePicker 已有公共组件;RangeCalendar 已完成公共客户端迁移(20 个基线预览),范围选择与 Calendar 共用视图/焦点/年份设施。DatePicker 复用 DateField 字段、Calendar 视图与 Popover 弹层,10 个基线预览已接入。
|
||||
- DateField、TimeField、Calendar、CalendarYearPicker、DatePicker 与 DateRangePicker 已有公共组件;RangeCalendar 已完成公共客户端迁移(20 个基线预览),范围选择与 Calendar 共用视图/焦点/年份设施。DatePicker 复用 DateField 字段、Calendar 视图与 Popover 弹层,10 个基线预览已接入。DateRangePicker 复用双端点 DateField、RangeCalendar 与 Popover,10 个基线预览已接入。
|
||||
- ColorSwatch/ColorSwatchRoot及Color/parseColor公共子集已公开;Area、Slider、Field/InputGroup、Picker组合协议仍有私有实现和回归夹具,尚未作为完整公共颜色家族发布。
|
||||
- 兼容矩阵目前84条(包含子部件与基础设施),文档有67个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
- 兼容矩阵目前84条(包含子部件与基础设施),文档有68个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
|
||||
## 尚未完成的公共家族
|
||||
|
||||
DateRangePicker,以及ColorArea、ColorField、ColorSlider、ColorSwatchPicker、ColorPicker,共6项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收。
|
||||
ColorArea、ColorField、ColorSlider、ColorSwatchPicker、ColorPicker,共5项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收。
|
||||
|
||||
TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md)。RANGE-CALENDAR 结果见 [任务结果](tasks/results/RANGE-CALENDAR.md)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。
|
||||
TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md)。RANGE-CALENDAR 结果见 [任务结果](tasks/results/RANGE-CALENDAR.md)。DATE-RANGE-PICKER 结果见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。
|
||||
|
||||
## 当前工程边界
|
||||
|
||||
唯一Vue工作目录heroui-vue,一任务一分支、会话串行。b01/b02/b03已删除并解除Git登记;core内容已整合,是否保留该目录不影响运行。开发默认文档5173,playground按实际脚本;服务只在任务需要时启动,结束按用户要求停止。
|
||||
|
||||
已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归95文件/1370项通过;本轮DatePicker新增2文件/32项,日期相关定向验收167项通过,增量复核通过并已合入 main,见任务结果;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。
|
||||
已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归97文件/1410项通过;本轮DateRangePicker新增2文件/40项,任务定向18文件/249项通过,尚未合入 main,见任务结果;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。
|
||||
|
||||
## 按需入口
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"base": "d30ef64a15c6c2d9bda90f968c989ae4f735404d",
|
||||
"upstream": "ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960",
|
||||
"status": "ready",
|
||||
"status": "review",
|
||||
"requires": [
|
||||
"packages/vue/src/components/date/model.ts",
|
||||
"packages/vue/src/components/date/value.ts",
|
||||
@@ -100,16 +100,16 @@ format-options 实际内容来自 format-options.tsx,保留两个 TimeField、
|
||||
|
||||
元数据 checks 是实施后须执行的命令;两个新增测试文件及 date-range-picker 产物契约需本任务建立,当前未存在不代表前置缺失。修改共享协议再按 tests/README.md 加相关消费者回归。
|
||||
|
||||
| 场景 | 用户可见通过条件 |
|
||||
| --- | --- |
|
||||
| 真实公开组合 | 起止分段编辑、清空、两次日历选择双向同步;年份切换与重新打开显示接受范围 |
|
||||
| 原子状态 | 不完整范围不提交;受控拒绝/延迟接受/重试、外部替换及 reset 无重复事件、旧锚点或时间草稿污染 |
|
||||
| 范围约束 | 同日/反向/时间逆序、min/max、不可用内点、非连续策略行为有明确断言;disabled/readOnly 不改变值 |
|
||||
| 日期/时间 | 三类 DateValue、时区/历法/秒精度保留;两个时间编辑彼此隔离,格式控件完整可操作 |
|
||||
| 表单 | 两个命名日期值且无额外提交;required/validate/错误关联、外部 form、动态 name、reset 可用 |
|
||||
| 浏览器 | 面板可见可点、定位/窄屏滚动、实际焦点/键盘/Escape/外部点击、嵌套 Modal、鼠标范围手势和退出无残留 |
|
||||
| 文档/视觉 | 10 例内容和次序、API 映射齐全;浅深、RTL、窄视口、焦点/错误/禁用重点检查有证据 |
|
||||
| 最终产物 | tarball 消费包根导出/样式/variants,bundler 与 NodeNext 类型正反例,浏览器打开/选范围/提交成功 |
|
||||
| 场景 | 用户可见通过条件 |
|
||||
| ------------ | ------------------------------------------------------------------------------------------------ |
|
||||
| 真实公开组合 | 起止分段编辑、清空、两次日历选择双向同步;年份切换与重新打开显示接受范围 |
|
||||
| 原子状态 | 不完整范围不提交;受控拒绝/延迟接受/重试、外部替换及 reset 无重复事件、旧锚点或时间草稿污染 |
|
||||
| 范围约束 | 同日/反向/时间逆序、min/max、不可用内点、非连续策略行为有明确断言;disabled/readOnly 不改变值 |
|
||||
| 日期/时间 | 三类 DateValue、时区/历法/秒精度保留;两个时间编辑彼此隔离,格式控件完整可操作 |
|
||||
| 表单 | 两个命名日期值且无额外提交;required/validate/错误关联、外部 form、动态 name、reset 可用 |
|
||||
| 浏览器 | 面板可见可点、定位/窄屏滚动、实际焦点/键盘/Escape/外部点击、嵌套 Modal、鼠标范围手势和退出无残留 |
|
||||
| 文档/视觉 | 10 例内容和次序、API 映射齐全;浅深、RTL、窄视口、焦点/错误/禁用重点检查有证据 |
|
||||
| 最终产物 | tarball 消费包根导出/样式/variants,bundler 与 NodeNext 类型正反例,浏览器打开/选范围/提交成功 |
|
||||
|
||||
- 新建 tests/date-range-picker.test.ts、tests/date-range-picker-demos.test.ts,断言实际公开组合;共享内核反例归入现有能力套件。不以文件/示例数量代替行为验收。
|
||||
- 增量扩展 tests/package/client-checks.json 与 date-range-picker-contract.ts,通过统一 check-package 脚本验证最终 tarball,不用源码 alias 替代。
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# DATE-RANGE-PICKER 交付 / 接续
|
||||
|
||||
- 分支:`feat/date-range-picker-public`
|
||||
- 起点 SHA:`89d2454f35a472e60861dbce2bf47bd892311ac9`(任务卡与入口变更;父提交 `d30ef64a15c6c2d9bda90f968c989ae4f735404d` 含全部前置实现)
|
||||
- 实施提交:本结果首版随实现提交保存;交付提交 SHA 在交付记录中补充。
|
||||
- 结果:客户端 DateRangePicker 公共迁移完成,固定源中文 10 个页面预览全部接入;未合 main、未 push。
|
||||
|
||||
## 改动
|
||||
|
||||
- 新增 `packages/vue/src/components/date-range-picker/`:`DateRangePicker.vue`、`DateRangePickerTrigger.vue`、`DateRangePickerTriggerIndicator.vue`、`DateRangePickerRangeSeparator.vue`、`DateRangePickerPopover.vue`、`context.ts`、`owner.ts`、私有 `DateRangeFieldBody.vue`、`EmptyRangeDateBridge.ts`。
|
||||
- 共享日期设施最小扩展:`date/model.ts` 增加接受范围模型,`date/range-selection.ts` 增加范围相等比较;`date-field/context.ts` 增加双端点字段标记,`DateInputGroupInput.vue` 增加 `endpoint` 入口并在端点内复用 Segment/Suffix/InputContainer,`DateInputGroupSegment.vue` 传递端点类型;`date-input-group.css` 将固定源 `slot="start"/"end"` 选择器适配为 `data-endpoint`。
|
||||
- `range-calendar/use-range-calendar.ts` 增加可选继承接口(值、请求、fallback、min/max、不可用、非连续、locale/dir、首日/翻页、禁用/只读/无效、默认焦点);`RangeCalendar.vue` 在 DateRangePicker 内继承并处理打开焦点,显式绑定仍独立。独立 RangeCalendar 行为不变。
|
||||
- 样式:新增 `packages/styles/components/date-range-picker.css`、`dateRangePickerVariants`/`DateRangePickerVariants`,源 CSS/tv 仅改 `hv-` 与 Reka 状态;样式入口导入新 CSS。
|
||||
- 公共导出:包根新增五个组件、Root 别名、variants 与 Props/RenderProps/state/time 类型;`types.ts`、`index.ts` 增量更新。
|
||||
- 文档:新增 `/components/date-range-picker` 页面、`navigation.ts` 条目和 `apps/docs/demos/date-range-picker-*.vue` 10 个 SFC,预览/复制/高亮共用同一 SFC;API/插槽/状态表与 Vue 差异完整记录。
|
||||
- 验证:新增 `tests/date-range-picker.test.ts`、`tests/date-range-picker-demos.test.ts`、`tests/package/date-range-picker-contract.ts` 与 `client-checks.json` 契约;playground 新增 `DateRangePickerLab.vue` 嵌套 Modal 回归入口。
|
||||
- 文档维护:`docs/status.md`、`docs/compatibility.md`、`docs/upstream.md`、`docs/verification.md`、`tests/README.md` 同步;`docs/tasks/ACTIVE.md` 更新交接。
|
||||
|
||||
## 固定源 API → Vue API → DOM/状态 → 验证
|
||||
|
||||
| 固定源 | Vue 公共 API | DOM/状态 | 验证 |
|
||||
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| `DateRangePicker` / `DateRangePickerRoot` | 同名根组件、`modelValue`/`defaultValue`、`open`/`isOpen`/`defaultOpen`、`startName`/`endName`、校验/格式/约束 props | `data-slot="date-range-picker"`,role=group,`data-disabled/readonly/invalid/required`,两个命名 `date-range-picker-start-value` / `-end-value` 输入 | 公开结构/提交、受控开关、必填/validate/reset、动态 name、外部 form |
|
||||
| `DateField.Input slot="start"/"end"` | `DateFieldInput endpoint="start" | "end"` | 两个 `date-input-group-input` 带 `data-endpoint`,共享 `DateFieldGroup`/`InputContainer`/`Segment`/`Suffix` | 两段编辑、Tab 跨端点、清空/部分草稿、时间与精度 |
|
||||
| `DateRangePicker.Trigger` | `DateRangePickerTrigger` | `data-slot="date-range-picker-trigger"`,原生 button/type=button、aria-haspopup/expanded/controls、data-open/disabled/focus-visible | 取消 click、受控 open、焦点恢复、默认/显式标签 |
|
||||
| `DateRangePicker.TriggerIndicator` | `DateRangePickerTriggerIndicator` | `aria-hidden` + 默认源 IconCalendar SVG 或插槽 | 默认 SVG/viewBox、Tabler 自定义图标 |
|
||||
| `DateRangePicker.RangeSeparator` | `DateRangePickerRangeSeparator`,`children` 默认 `" - "` | `aria-hidden`,`data-slot="date-range-picker-range-separator"` | 默认文本、插槽覆盖 |
|
||||
| `DateRangePicker.Popover` + RAC Popover | `DateRangePickerPopover`,`placement` 默认 bottom、offset/碰撞/Portal/`isDismissable`/Escape 回调 | Reka Popover 包装、`--reka-popper-transform-origin`、`data-entering/exiting`、role=dialog 标签 | 可见/可点、碰撞翻转、Escape/外部点击/取消回调、退出无拦截 |
|
||||
| `RangeCalendar`(组合内) | 既有 `RangeCalendar`/具名部件 | 继承值/约束/locale/dir/非连续;显式绑定覆盖 | 首点不提交、第二次有序提交、跨不可用内点、RTL/周首日 |
|
||||
| `state.value/timeRange`、`setValue/setTimeRange` | 默认插槽 `state`、顶层 `value/timeRange`、`open/close/toggle` | `timeRange` 两端独立;空值时间只存草稿 | 两 TimeField、时间保留、空值先时间后日历、reset 清草稿 |
|
||||
|
||||
## 验收场景与证据
|
||||
|
||||
| 验收场景 / 复核问题 | 断言或复现步骤 | 实际结果 / 限制 |
|
||||
| ------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 真实公开组合 | basic:打开面板 → 第一下选 20 日 → 第二下选 22 日;重新打开 | 第一下保持打开且 `change=[]`;第二下只发一次 change,两个命名值更新并关闭;重开高亮接受范围;通过 |
|
||||
| 原子状态 | 受控拒绝后连续两次 ArrowUp;清空一端后 Escape;外部替换/reset | 拒绝后显示与提交回接受值,同一提案可重试;半个范围不提交,关闭/外部替换/reset 清草稿;通过 |
|
||||
| 范围约束 | 反向/同日/时间逆序;min/max;不可用内点;`allowsNonContiguousRanges` | 反向与时间逆序提交但字段无效;日历选择自动排序;同日范围可用;内点不可用阻止连续选择,开启非连续后允许;通过 |
|
||||
| 日期/时间 | ZonedDateTime/CalendarDateTime/CalendarDate;两 TimeField;粒度/小时制/时区/前导零 | 两端各自保留类、时间、秒、时区与历法;字段编辑保留不可显示毫秒;时间编辑不改另一端;格式控件可操作;通过 |
|
||||
| 表单 | required/validate、同名/动态 name、外部 form、reset | 两个命名值且无第三个合并值;错误/描述关联;reset 回 defaultValue 或空;通过 |
|
||||
| 浏览器 | 800×655 文档;390×800 同源 iframe;playground 5174 | 面板 276×292 可见、碰撞翻转;390 下 `scrollWidth=390` 且面板在视口内;嵌套 Modal 先关日历后关 Modal,动画后无遮罩/层/滚动锁残留;通过 |
|
||||
| 文档/视觉 | 10 例次序、API 映射、浅深、RTL、窄视口、焦点/错误/禁用 | 10/10 预览与页面引用一致;800 浅深主题、RTL 输入顺序、390 几何、焦点环与禁用/错误状态检查;通过 |
|
||||
| 最终产物 | `check-package` 五个契约;tarball 消费 | 最终 tarball ESM/CSS/variants 与 strict NodeNext/bundler 正反类型通过;契约包含双输入/日历/范围类型反例 |
|
||||
|
||||
## 命令结果
|
||||
|
||||
- `pnpm test`:97 文件 / 1410 项通过。
|
||||
- 任务定向 18 文件 / 249 项通过(命令见任务卡元数据)。
|
||||
- `pnpm typecheck`:通过。
|
||||
- `pnpm build:docs`:通过(保留既有大 chunk 提示)。
|
||||
- `pnpm build:playground`:通过,DateRangePickerLab 产出。
|
||||
- `node scripts/check-package.mjs date-range-picker date-picker range-calendar date-field time-field`:五个契约通过。
|
||||
- `node scripts/task-check.mjs DATE-RANGE-PICKER`:前置文件、最低祖先与固定源检查通过。
|
||||
|
||||
## 已知差异与未完成
|
||||
|
||||
- Vue 保留 `slot` 作为插槽语法,固定源 `slot="start"/"end"` 映射为 `DateFieldInput endpoint`;缺少端点或根时抛出明确错误。
|
||||
- 格式选项固定源的 `w-full` 弹层在 Reka Portal 自动宽度包装下无法按预期撑开,演示映射为 252px RangeCalendar + 24px 内边距(276px);这是布局适配,不改变示例内容。
|
||||
- Reka 日期字段只显示到 second,毫秒不在分段中;字段编辑时按端点保留先前毫秒,空值首次输入使用 placeholder 精度。
|
||||
- 清空两个端点提交 `null`;只清空一端不提交,关闭/外部替换/reset 时恢复接受状态。反向/时间逆序由字段校验报告,不自动交换端点。
|
||||
- 触屏长按拖选仍是 RangeCalendar 已知缺口;本任务未扩建触屏专项。
|
||||
- 未开展 SSR/水合/Nuxt、逐像素自动对比、完整读屏/真机矩阵。真实浏览器窗口不可见时 CSS 退出动画暂停,嵌套 Modal 验证通过显式 `animationend` 完成退出清理,已如实记录。
|
||||
|
||||
## 复核入口
|
||||
|
||||
- 任务分支 `feat/date-range-picker-public`;`pnpm dev` 文档 5173 的 `/components/date-range-picker`;playground 5174 的 `?date-range-picker-overlay` 仅用于嵌套 Modal 回归,验证后已停止。
|
||||
- 结果表只记录实际证据;未生成或未执行的检查未标记为通过。
|
||||
@@ -276,3 +276,9 @@ Vue 模型、具名导出、原生事件/作用域插槽与共享日期 owner
|
||||
DatePicker CSS/variants 仅加 hv- 前缀,弹层 origin/placement 与进入退出状态映射到 Reka;默认日历图标取自上游 `icons.tsx` 的 IconCalendar,保留 Apache-2.0 来源,示例自定义图标改用 Tabler Vue。Vue 侧复用既有 DateField 接受值/字段校验/原生提交与 Calendar/RangeCalendar 视图、年份层、Popover 协议;从 DateField 抽取内部 owner,供独立 DateField 与 Picker 共用,未复制第二套字段状态。无新增依赖,构建不依赖相邻 React 仓库。
|
||||
|
||||
框架差异(`v-model`、`v-model:open`、具名导出、作用域插槽、默认 slot 的 `state.timeValue`/`setTimeValue`、`render` 映射到 `as`/原生 attrs)见 [组件文档](../apps/docs/components/date-picker.md) 与 [结果](tasks/results/DATE-PICKER.md)。
|
||||
|
||||
## DATE-RANGE-PICKER(2026-10-26)
|
||||
|
||||
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/date-range-picker/{index.ts,date-range-picker.tsx}`、`packages/styles/components/date-range-picker.css`、`packages/styles/src/components/date-range-picker/date-range-picker.styles.ts`、中文 `(date-and-time)/date-range-picker.mdx` 与 `apps/docs/src/demos/cn/date-range-picker/` 全部 10 个页面预览;`index.ts` 额外导出的 release-input-container 中文页未引用,按非页面示例核对。同时对照 React Aria Components 1.21.1 发布的 DateRangePicker/DateRangeField/useDateRangePickerState 声明确认完整范围、时间范围与 `shouldCloseOnSelect` 语义,未安装或执行 React。
|
||||
|
||||
CSS/variants 仅加 hv- 前缀并保留 Apache-2.0 来源;弹层 origin/placement 与进入退出状态映射到 Reka,默认日历图标取自上游 `icons.tsx` 的 IconCalendar。Vue 侧复用既有接受值/字段/范围选择/日历视图/弹层设施:从 DateField owner 抽取双端点字段适配,RangeCalendar 增加可选继承接口;没有复制第二套范围状态或另一个接受值。固定源 `slot="start"/"end"` 改为 `DateFieldInput endpoint`;格式选项的 `w-full` 弹层在 Portal 自动宽度下映射为日历宽度加内边距。无新增依赖,构建不依赖相邻 React 仓库;差异、宽度适配和验证见 [组件文档](../apps/docs/components/date-range-picker.md) 与 [结果](tasks/results/DATE-RANGE-PICKER.md)。
|
||||
|
||||
@@ -42,3 +42,18 @@
|
||||
未开展 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏/真机矩阵;触摸、IME 与完整本地化日期粘贴仍不在本项验收范围。
|
||||
|
||||
增量复核通过(补修70f8a09):修复运行中 trigger id 改变后 dialog 标签仍引用旧 id 的遗漏,补入动态 id 与 Escape 回调替换用例。DatePicker 行为28项、文档4项;全量95文件/1370项、任务定向14文件/167项、类型检查、文档构建、四个相关tarball契约通过。真实浏览器抽验默认标签解析、鼠标选日与焦点恢复通过;此轮没有重做产物浏览器或其他专项,完整证据与范围见同一任务结果。
|
||||
|
||||
## DATE-RANGE-PICKER(2026-10-26,客户端)
|
||||
|
||||
公开 DateRangePicker/Root、Trigger、TriggerIndicator、RangeSeparator、Popover、dateRangePickerVariants、RenderProps/state/time 类型;`DateFieldInput endpoint` 选择起止输入,未显式绑定的 RangeCalendar 继承完整范围与约束。固定源中文 10 例全部迁移;新增 28 项公共行为与 12 项文档/示例测试。
|
||||
|
||||
- `pnpm test`:97 文件/1410 项客户端回归通过。
|
||||
- 任务定向 18 文件/249 项(date-range-picker 两个新文件、date model/value/field/picker、range-calendar 三文件、calendar/view、time-field、popover/overlay/field foundation)通过。
|
||||
- `pnpm typecheck`、`pnpm build:docs`、`pnpm build:playground`:通过;文档构建保留已有大 chunk 提示。
|
||||
- `node scripts/check-package.mjs date-range-picker date-picker range-calendar date-field time-field`:最终 tarball 独立安装、ESM 导出/CSS/variants 及 strict NodeNext/bundler 类型正反例通过。
|
||||
|
||||
真实浏览器(OpenCode 2.1.4 / Chrome 152,800×655 CSS 视口,`http://127.0.0.1:5173/components/date-range-picker`):鼠标打开面板可见(276×292,碰撞向上翻转)、初始焦点为接受范围起点、第一下点击不关闭不提交、第二下提交单次并关闭、焦点回触发器;键盘 Arrow/Enter 两次确认、字段分段 ArrowUp、Tab 跨端点、Escape 从焦点格/分段关闭并恢复触发器;时间字段编辑保留另一端与时区,格式选项粒度/小时制/时区/前导零切换和两 TimeField 可操作;受控、表单两个命名值、提交加载/清空、浅深主题均检查。800px 页面无横向溢出;390×800 同源 iframe 实测 `scrollWidth=390`,320px 字段与 276px 面板均在视口内。控制台无新增 warn/error。
|
||||
|
||||
Playground 5174 嵌套 Modal 场景:面板在 Modal 上方可见/可操作,Escape 先关闭范围日历且 Modal 保持打开,随后关闭 Modal;退出动画完成后遮罩、dismissable layer 与 body 滚动锁均清理,焦点回到打开按钮。由于桌面窗口不可见时动画暂停,该轮在断言前显式派发 `animationend` 完成退出清理,不以残留节点判断组件失败。
|
||||
|
||||
差异与限制:固定源 `slot="start"/"end"` 改为 `endpoint` prop;格式选项的 `w-full` 弹层在 Portal 自动宽度下映射为 252px 日历 + 24px 内边距;字段编辑无法显示毫秒,保留端点先前精度。未开展 SSR/水合/Nuxt、逐像素、完整读屏/真机矩阵;触屏长按拖选仍是 RangeCalendar 已知缺口。详情见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。
|
||||
|
||||
@@ -71,11 +71,12 @@
|
||||
@apply rounded-e-none pe-2;
|
||||
}
|
||||
|
||||
/* The pinned slot="start"/"end" endpoint selector becomes data-endpoint. */
|
||||
.hv-date-input-group:has(.hv-date-range-picker__range-separator) & {
|
||||
&[slot="start"] {
|
||||
&[data-endpoint="start"] {
|
||||
@apply flex-none pe-0;
|
||||
}
|
||||
&[slot="end"] {
|
||||
&[data-endpoint="end"] {
|
||||
@apply ps-0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/* Adapted from HeroUI ce90ea3 date-range-picker.css. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace, Vue/Reka states. */
|
||||
|
||||
.hv-date-range-picker {
|
||||
@apply inline-flex flex-col gap-1;
|
||||
|
||||
.hv-date-input-group__suffix,
|
||||
.hv-date-input-group__prefix {
|
||||
@apply pointer-events-auto;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-range-picker__trigger {
|
||||
@apply inline-flex w-full items-center rounded-field p-1 text-sm no-highlight;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition: box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-range-picker__trigger-indicator {
|
||||
@apply inline-flex size-4 items-center justify-center text-field-placeholder;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__range-separator {
|
||||
@apply px-1 text-field-placeholder select-none;
|
||||
}
|
||||
|
||||
.hv-date-range-picker__popover {
|
||||
@apply w-fit origin-(--reka-popper-transform-origin) scrollbar-none overflow-y-auto overscroll-contain bg-overlay p-3;
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
box-shadow: var(--overlay-shadow);
|
||||
border-radius: min(32px, calc(var(--radius) * 2.5));
|
||||
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-95;
|
||||
|
||||
&[data-side^="top"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
|
||||
&[data-side^="bottom"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-side^="left"] {
|
||||
@apply slide-in-from-right-1;
|
||||
}
|
||||
|
||||
&[data-side^="right"] {
|
||||
@apply slide-in-from-left-1;
|
||||
}
|
||||
}
|
||||
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
|
||||
/* Stays non-interactive while closing, even if the exit animation is interrupted. */
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-range-picker__popover .hv-range-calendar__nav-button-icon,
|
||||
.hv-date-range-picker__popover .hv-calendar__nav-button-icon {
|
||||
@apply rotate-0;
|
||||
}
|
||||
@@ -164,6 +164,7 @@
|
||||
@import "./components/date-input-group.css" layer(components);
|
||||
@import "./components/date-field.css" layer(components);
|
||||
@import "./components/date-picker.css" layer(components);
|
||||
@import "./components/date-range-picker.css" layer(components);
|
||||
@import "./components/time-field.css" layer(components);
|
||||
|
||||
@import "./components/calendar.css" layer(components);
|
||||
|
||||
@@ -1469,6 +1469,19 @@ export const datePickerVariants = tv({
|
||||
},
|
||||
});
|
||||
export type DatePickerVariants = VariantProps<typeof datePickerVariants>;
|
||||
// Ported from HeroUI ce90ea3, Apache-2.0; hv namespace only.
|
||||
export const dateRangePickerVariants = tv({
|
||||
slots: {
|
||||
base: "hv-date-range-picker",
|
||||
popover: "hv-date-range-picker__popover",
|
||||
rangeSeparator: "hv-date-range-picker__range-separator",
|
||||
trigger: "hv-date-range-picker__trigger",
|
||||
triggerIndicator: "hv-date-range-picker__trigger-indicator",
|
||||
},
|
||||
});
|
||||
export type DateRangePickerVariants = VariantProps<
|
||||
typeof dateRangePickerVariants
|
||||
>;
|
||||
export const dateInputGroupVariants = tv({
|
||||
slots: {
|
||||
base: "hv-date-input-group",
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
mergeProps,
|
||||
provide,
|
||||
type ComputedRef,
|
||||
type PropType,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { DateRangeFieldInput } from "reka-ui";
|
||||
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
dateSegmentBaseKey,
|
||||
dateGroupKey,
|
||||
dateRangeFieldKey,
|
||||
dateSegmentsKey,
|
||||
useDateField,
|
||||
type DateSegment,
|
||||
@@ -20,34 +26,72 @@ import DateInputGroupSegment from "./DateInputGroupSegment.vue";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupInput",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "div" } },
|
||||
props: {
|
||||
as: { type: String, default: "div" },
|
||||
/** Range endpoint selector. Vue reserves `slot`, so the pinned source's
|
||||
* `slot="start"` / `slot="end"` becomes this typed prop. */
|
||||
endpoint: String as PropType<"start" | "end">,
|
||||
},
|
||||
slots: Object as SlotsType<{
|
||||
default?: (props: { segment: DateSegment; index: number }) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots }) {
|
||||
const field = useDateField();
|
||||
const adapter = inject(dateSegmentBaseKey)!;
|
||||
const base = adapter.base;
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
const segments = inject(dateSegmentsKey)!;
|
||||
const range = inject(dateRangeFieldKey, undefined);
|
||||
const singleAdapter = inject(dateSegmentBaseKey, undefined);
|
||||
const singleSegments = inject(dateSegmentsKey, undefined);
|
||||
let adapter: NonNullable<typeof singleAdapter>;
|
||||
let segments: ComputedRef<{ part: DateSegment["part"]; value: string }[]>;
|
||||
if (props.endpoint) {
|
||||
if (!range)
|
||||
throw new Error(
|
||||
"DateFieldInput endpoint requires a DateRangePicker root.",
|
||||
);
|
||||
const root = range.root;
|
||||
const endpoint = props.endpoint;
|
||||
adapter = {
|
||||
// Endpoint-specific segment values share the rest of the range field
|
||||
// context, so parts keep using one locale/formatter/disabled source.
|
||||
base: {
|
||||
...root,
|
||||
segmentValues: computed(() => root.segmentValues[endpoint].value),
|
||||
},
|
||||
input: DateRangeFieldInput,
|
||||
kind: "date",
|
||||
endpoint,
|
||||
} as unknown as NonNullable<typeof singleAdapter>;
|
||||
segments = computed(() => root.segmentContents.value[endpoint]);
|
||||
provide(dateSegmentBaseKey, adapter);
|
||||
} else {
|
||||
if (!singleAdapter || !singleSegments)
|
||||
throw new Error(
|
||||
'DateFieldInput requires a DateField or TimeField root, or endpoint="start"/"end" inside DateRangePicker.',
|
||||
);
|
||||
adapter = singleAdapter;
|
||||
segments = singleSegments;
|
||||
}
|
||||
const base = adapter.base;
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).input(),
|
||||
"data-slot": "date-input-group-input",
|
||||
"data-endpoint": props.endpoint || undefined,
|
||||
}),
|
||||
segments.value.map((part, index) => {
|
||||
const partName = part.part;
|
||||
const isPlaceholder =
|
||||
part.part in base.segmentValues.value &&
|
||||
partName in base.segmentValues.value &&
|
||||
base.segmentValues.value[
|
||||
part.part as keyof typeof base.segmentValues.value
|
||||
partName as keyof typeof base.segmentValues.value
|
||||
] === null;
|
||||
let text = part.value;
|
||||
if (
|
||||
!isPlaceholder &&
|
||||
(adapter.kind !== "time" || part.part === "hour") &&
|
||||
["month", "day", "hour", "minute", "second"].includes(part.part) &&
|
||||
(adapter.kind !== "time" || partName === "hour") &&
|
||||
["month", "day", "hour", "minute", "second"].includes(partName) &&
|
||||
/^\d+$/.test(text)
|
||||
) {
|
||||
if (field.leadingZeros() === true) text = text.padStart(2, "0");
|
||||
@@ -56,15 +100,16 @@ export default defineComponent({
|
||||
}
|
||||
const segment: DateSegment = {
|
||||
...part,
|
||||
type: part.part,
|
||||
part: partName,
|
||||
type: partName,
|
||||
text,
|
||||
value: text,
|
||||
isPlaceholder,
|
||||
isEditable: part.part !== "literal" && part.part !== "timeZoneName",
|
||||
isEditable: partName !== "literal" && partName !== "timeZoneName",
|
||||
};
|
||||
return h(
|
||||
"span",
|
||||
{ key: `${part.part}-${index}`, style: { display: "contents" } },
|
||||
{ key: `${partName}-${index}`, style: { display: "contents" } },
|
||||
slots.default?.({ segment, index }) ??
|
||||
h(DateInputGroupSegment, { segment }),
|
||||
);
|
||||
|
||||
@@ -47,7 +47,11 @@ export default defineComponent({
|
||||
return () =>
|
||||
h(
|
||||
adapter.input,
|
||||
{ part: props.segment.part, asChild: true },
|
||||
{
|
||||
part: props.segment.part,
|
||||
...(adapter.endpoint ? { type: adapter.endpoint } : {}),
|
||||
asChild: true,
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
|
||||
@@ -49,4 +49,14 @@ export const dateSegmentBaseKey: InjectionKey<{
|
||||
>;
|
||||
input: Component;
|
||||
kind: "date" | "time";
|
||||
/** Range endpoints reuse the same segment parts with an explicit start/end field. */
|
||||
endpoint?: "start" | "end";
|
||||
}> = Symbol("hv-date-segment-base");
|
||||
|
||||
/** Marker provided by the DateRangePicker private field body. Only inputs with
|
||||
* an explicit endpoint consume it; nested TimeFields keep their own segment base. */
|
||||
export const dateRangeFieldKey: InjectionKey<{
|
||||
root: NonNullable<
|
||||
ReturnType<typeof import("reka-ui").injectDateRangeFieldRootContext>
|
||||
>;
|
||||
}> = Symbol("hv-date-range-field");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { provide } from "vue";
|
||||
import { injectDateRangeFieldRootContext } from "reka-ui";
|
||||
import { dateRangeFieldKey } from "../date-field/context";
|
||||
defineOptions({ name: "DateRangeFieldBody" });
|
||||
const root = injectDateRangeFieldRootContext();
|
||||
provide(dateRangeFieldKey, { root });
|
||||
</script>
|
||||
<template>
|
||||
<slot />
|
||||
</template>
|
||||
@@ -0,0 +1,306 @@
|
||||
<script lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 DateRangePicker, Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
provide,
|
||||
shallowRef,
|
||||
watch,
|
||||
type PropType,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { PopoverRoot } from "reka-ui";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import { dateRangePickerVariants } from "@heroui-vue/styles";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { useOverlayState } from "../../composables/useOverlayState";
|
||||
import { createPopoverContext, popoverKey } from "../popover/context";
|
||||
import { overlayNodes } from "../overlay/OverlayAction";
|
||||
import type { ValidationBehavior, ValidateResult } from "../field/context";
|
||||
import type { CalendarWeekday } from "../date/calendar";
|
||||
import type { CalendarRangeModel } from "../date/range-selection";
|
||||
import { useDateRangePickerOwner } from "./owner";
|
||||
import {
|
||||
dateRangePickerKey,
|
||||
type DateRangePickerEscapeOptions,
|
||||
type DateRangePickerRenderProps,
|
||||
} from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DateRangePicker",
|
||||
inheritAttrs: false,
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: DateRangePickerRenderProps) => VNodeChild;
|
||||
}>,
|
||||
props: {
|
||||
modelValue: {
|
||||
type: Object as PropType<CalendarRangeModel>,
|
||||
default: undefined,
|
||||
},
|
||||
value: {
|
||||
type: Object as PropType<CalendarRangeModel>,
|
||||
default: undefined,
|
||||
},
|
||||
defaultValue: Object as PropType<CalendarRangeModel>,
|
||||
placeholderValue: [Object, null] as PropType<DateValue | null>,
|
||||
minValue: [Object, null] as PropType<DateValue | null>,
|
||||
maxValue: [Object, null] as PropType<DateValue | null>,
|
||||
isDateUnavailable: Function as PropType<(value: DateValue) => boolean>,
|
||||
allowsNonContiguousRanges: Boolean,
|
||||
granularity: String as PropType<"day" | "hour" | "minute" | "second">,
|
||||
hourCycle: Number as PropType<12 | 24>,
|
||||
hideTimeZone: Boolean,
|
||||
shouldForceLeadingZeros: { type: Boolean, default: undefined },
|
||||
locale: String,
|
||||
dir: String as PropType<"ltr" | "rtl">,
|
||||
firstDayOfWeek: String as PropType<CalendarWeekday>,
|
||||
pageBehavior: String as PropType<"visible" | "single">,
|
||||
as: { type: String, default: "div" },
|
||||
id: String,
|
||||
startName: String,
|
||||
endName: String,
|
||||
form: String,
|
||||
isDisabled: Boolean,
|
||||
disabled: Boolean,
|
||||
isReadOnly: Boolean,
|
||||
isRequired: Boolean,
|
||||
isInvalid: Boolean,
|
||||
autoFocus: Boolean,
|
||||
autoComplete: String,
|
||||
validationBehavior: String as PropType<ValidationBehavior>,
|
||||
validate: Function as PropType<
|
||||
(value: CalendarRangeModel) => ValidateResult
|
||||
>,
|
||||
open: { type: Boolean, default: undefined },
|
||||
isOpen: { type: Boolean, default: undefined },
|
||||
defaultOpen: Boolean,
|
||||
shouldCloseOnSelect: { type: Boolean, default: true },
|
||||
},
|
||||
emits: {
|
||||
"update:modelValue": (_value: CalendarRangeModel) => true,
|
||||
change: (_value: CalendarRangeModel) => true,
|
||||
"update:open": (_value: boolean) => true,
|
||||
"update:isOpen": (_value: boolean) => true,
|
||||
openChange: (_value: boolean) => true,
|
||||
},
|
||||
setup(props, { attrs, slots, emit, expose }) {
|
||||
const config = useConfig();
|
||||
const dir = computed<"ltr" | "rtl">(
|
||||
() => props.dir ?? config?.dir?.value ?? "ltr",
|
||||
);
|
||||
const state = useOverlayState({
|
||||
isOpen: () => props.open ?? props.isOpen,
|
||||
defaultOpen: props.defaultOpen,
|
||||
onOpenChange(value) {
|
||||
emit("update:open", value);
|
||||
emit("update:isOpen", value);
|
||||
emit("openChange", value);
|
||||
},
|
||||
});
|
||||
const owner = useDateRangePickerOwner(props, attrs, {
|
||||
onChange: (value) => {
|
||||
emit("update:modelValue", value);
|
||||
emit("change", value);
|
||||
},
|
||||
onReset: () => {},
|
||||
shouldCloseOnSelect: () => props.shouldCloseOnSelect,
|
||||
onSelectComplete: () => state.close(),
|
||||
});
|
||||
watch(state.isOpen, (open) => {
|
||||
if (!open) owner.settleField();
|
||||
});
|
||||
const trigger = shallowRef<HTMLElement>();
|
||||
const triggerId = shallowRef<string>();
|
||||
const escapeOptions = shallowRef<DateRangePickerEscapeOptions>({
|
||||
disabled: false,
|
||||
handlers: [],
|
||||
});
|
||||
const popover = createPopoverContext(state);
|
||||
provide(popoverKey, popover);
|
||||
provide(dateRangePickerKey, {
|
||||
state,
|
||||
trigger,
|
||||
triggerId,
|
||||
value: owner.accepted.value,
|
||||
dates: computed(() => {
|
||||
const value = owner.accepted.value.value;
|
||||
return value ? [value.start, value.end] : [];
|
||||
}),
|
||||
timeRange: owner.timeRange,
|
||||
setTimeRange: owner.setTimeRange,
|
||||
requestRange: owner.requestRange,
|
||||
minValue: computed(() => props.minValue ?? undefined),
|
||||
maxValue: computed(() => props.maxValue ?? undefined),
|
||||
isDateUnavailable: (value) => props.isDateUnavailable?.(value) ?? false,
|
||||
allowsNonContiguousRanges: () => !!props.allowsNonContiguousRanges,
|
||||
disabled: owner.field.field.disabled,
|
||||
readOnly: owner.field.field.readOnly,
|
||||
invalid: owner.field.field.invalid,
|
||||
locale: owner.locale,
|
||||
dir: owner.dir,
|
||||
labelledBy: owner.field.labelledBy,
|
||||
describedBy: owner.field.describedBy,
|
||||
firstDayOfWeek: () => props.firstDayOfWeek,
|
||||
pageBehavior: () => props.pageBehavior,
|
||||
placeholder: owner.placeholder,
|
||||
calendarFallback: owner.calendarFallback,
|
||||
escapeOptions,
|
||||
shouldCloseOnSelect: () => props.shouldCloseOnSelect,
|
||||
});
|
||||
let restoreFocus = false;
|
||||
const doc = typeof document === "undefined" ? undefined : document;
|
||||
function trackKeyboard(event: KeyboardEvent) {
|
||||
if (!event.metaKey && !event.ctrlKey && !event.altKey)
|
||||
restoreFocus = true;
|
||||
}
|
||||
function closeFromPicker(event: KeyboardEvent) {
|
||||
if (
|
||||
event.key !== "Escape" ||
|
||||
event.isComposing ||
|
||||
event.defaultPrevented ||
|
||||
!state.isOpen.value
|
||||
)
|
||||
return;
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (!target) return;
|
||||
const content = doc?.getElementById(popover.contentId.value) ?? null;
|
||||
const inField = !!owner.root.value?.contains(target);
|
||||
const inContent = !!content?.contains(target);
|
||||
if (!inField && !inContent) return;
|
||||
// An open year layer owns its own Escape and restores focus itself.
|
||||
if (
|
||||
content?.querySelector(
|
||||
'[data-slot="calendar-year-picker-grid"][data-open]',
|
||||
)
|
||||
)
|
||||
return;
|
||||
const options = escapeOptions.value;
|
||||
for (const handler of options.handlers) handler(event);
|
||||
const cancelled = event.defaultPrevented;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (options.disabled || cancelled) return;
|
||||
state.close();
|
||||
}
|
||||
function onDocumentKeydown(event: KeyboardEvent) {
|
||||
trackKeyboard(event);
|
||||
closeFromPicker(event);
|
||||
}
|
||||
watch(
|
||||
state.isOpen,
|
||||
(open) => {
|
||||
if (open) doc?.addEventListener("keydown", onDocumentKeydown, true);
|
||||
else {
|
||||
doc?.removeEventListener("keydown", onDocumentKeydown, true);
|
||||
if (restoreFocus) {
|
||||
const run = () => trigger.value?.focus({ preventScroll: true });
|
||||
if (typeof requestAnimationFrame === "function")
|
||||
requestAnimationFrame(run);
|
||||
else void nextTick(run);
|
||||
}
|
||||
restoreFocus = false;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
onMounted(() => {
|
||||
if (props.autoFocus) owner.focus();
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
doc?.removeEventListener("keydown", onDocumentKeydown, true);
|
||||
});
|
||||
expose({
|
||||
element: owner.root,
|
||||
focus: owner.focus,
|
||||
open: state.open,
|
||||
close: state.close,
|
||||
toggle: state.toggle,
|
||||
});
|
||||
function setValue(value: CalendarRangeModel) {
|
||||
owner.accepted.request(value);
|
||||
}
|
||||
return () => {
|
||||
const base = owner.state();
|
||||
const pickerState = {
|
||||
value: owner.accepted.value.value,
|
||||
timeRange: owner.timeRange.value,
|
||||
setValue,
|
||||
setTimeRange: owner.setTimeRange,
|
||||
};
|
||||
const renderState: DateRangePickerRenderProps = {
|
||||
...base,
|
||||
isOpen: state.isOpen.value,
|
||||
timeRange: owner.timeRange.value,
|
||||
state: pickerState,
|
||||
open: state.open,
|
||||
close: state.close,
|
||||
toggle: state.toggle,
|
||||
};
|
||||
const raw = slots.default?.(renderState);
|
||||
const children = owner.field.prepare(
|
||||
Array.isArray(raw) ? raw : raw ? [raw] : [],
|
||||
true,
|
||||
);
|
||||
const overrides = {
|
||||
id: owner.field.field.controlId.value,
|
||||
role: "group",
|
||||
class: dateRangePickerVariants().base(),
|
||||
"data-slot": "date-range-picker",
|
||||
"data-disabled": base.isDisabled || undefined,
|
||||
"data-readonly": base.isReadOnly || undefined,
|
||||
"data-invalid": base.isInvalid || undefined,
|
||||
"data-required": base.isRequired || undefined,
|
||||
"data-focus-within": owner.focused.value || undefined,
|
||||
"aria-label": attrs["aria-label"],
|
||||
"aria-labelledby": owner.field.labelledBy(),
|
||||
"aria-describedby": owner.field.describedBy(),
|
||||
"aria-invalid": base.isInvalid || undefined,
|
||||
"aria-required": base.isRequired || undefined,
|
||||
dir: dir.value,
|
||||
ref: (element: unknown) => {
|
||||
owner.root.value = element as HTMLElement;
|
||||
},
|
||||
onFocusin: (event: FocusEvent) => {
|
||||
owner.focused.value = true;
|
||||
owner.focusVisible.value = (event.target as HTMLElement).matches(
|
||||
":focus-visible",
|
||||
);
|
||||
},
|
||||
onFocusout: (event: FocusEvent) => {
|
||||
if (
|
||||
!(event.currentTarget as HTMLElement).contains(
|
||||
event.relatedTarget as Node | null,
|
||||
)
|
||||
) {
|
||||
owner.focused.value = false;
|
||||
owner.focusVisible.value = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
return h(
|
||||
PopoverRoot,
|
||||
{
|
||||
open: state.isOpen.value,
|
||||
modal: true,
|
||||
"onUpdate:open": state.setOpen,
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
owner.renderOwner(
|
||||
[
|
||||
...overlayNodes(children),
|
||||
...owner.inputNodes("date-range-picker"),
|
||||
],
|
||||
{ as: props.as, consumer: attrs, overrides },
|
||||
),
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, useAttrs, watchEffect } from "vue";
|
||||
import { dateRangePickerVariants } from "@heroui-vue/styles";
|
||||
import type { OverlayPlacement } from "../overlay/placement";
|
||||
import PopoverContent from "../popover/PopoverContent.vue";
|
||||
import { useDateRangePicker } from "./context";
|
||||
defineOptions({ name: "DateRangePickerPopover", inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
as?: string;
|
||||
placement?: OverlayPlacement;
|
||||
offset?: number;
|
||||
crossOffset?: number;
|
||||
shouldFlip?: boolean;
|
||||
containerPadding?: number;
|
||||
to?: string | HTMLElement;
|
||||
isNonModal?: boolean;
|
||||
isDismissable?: boolean;
|
||||
isKeyboardDismissDisabled?: boolean;
|
||||
}>(),
|
||||
{
|
||||
as: "div",
|
||||
placement: "bottom",
|
||||
offset: 8,
|
||||
crossOffset: 0,
|
||||
shouldFlip: true,
|
||||
containerPadding: 12,
|
||||
isNonModal: undefined,
|
||||
isDismissable: true,
|
||||
isKeyboardDismissDisabled: false,
|
||||
},
|
||||
);
|
||||
const picker = useDateRangePicker();
|
||||
const attrs = useAttrs();
|
||||
const escapeHandlers = computed<((event: Event) => void)[]>(() => {
|
||||
const value = attrs.onEscapeKeyDown;
|
||||
return (Array.isArray(value) ? value : [value]).filter(
|
||||
(handler): handler is (event: Event) => void =>
|
||||
typeof handler === "function",
|
||||
);
|
||||
});
|
||||
watchEffect(() => {
|
||||
picker.escapeOptions.value = {
|
||||
disabled: props.isKeyboardDismissDisabled,
|
||||
handlers: escapeHandlers.value,
|
||||
};
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
picker.escapeOptions.value = { disabled: false, handlers: [] };
|
||||
});
|
||||
const labelAttrs = computed(() => {
|
||||
const explicit = attrs["aria-labelledby"];
|
||||
const id = typeof explicit === "string" ? explicit : picker.triggerId.value;
|
||||
return id ? { "aria-labelledby": id } : {};
|
||||
});
|
||||
const contentAttrs = computed(() => ({ ...attrs, ...labelAttrs.value }));
|
||||
function openAutoFocus(event: Event) {
|
||||
// The calendar cell owns initial focus; the dialog surface must not steal it.
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<PopoverContent
|
||||
v-bind="contentAttrs"
|
||||
:as="as"
|
||||
:placement="placement"
|
||||
:offset="offset"
|
||||
:cross-offset="crossOffset"
|
||||
:should-flip="shouldFlip"
|
||||
:container-padding="containerPadding"
|
||||
:to="to"
|
||||
:is-non-modal="isNonModal"
|
||||
:is-dismissable="isDismissable"
|
||||
:is-keyboard-dismiss-disabled="isKeyboardDismissDisabled"
|
||||
:lang="(attrs.lang as string | undefined) ?? picker.locale.value"
|
||||
:class="dateRangePickerVariants().popover()"
|
||||
data-slot="date-range-picker-popover"
|
||||
@open-auto-focus="openAutoFocus"
|
||||
>
|
||||
<slot />
|
||||
</PopoverContent>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, mergeProps, type PropType } from "vue";
|
||||
import { dateRangePickerVariants } from "@heroui-vue/styles";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DateRangePickerRangeSeparator",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "span" },
|
||||
children: { type: String as PropType<string>, default: " - " },
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
"aria-hidden": "true",
|
||||
class: dateRangePickerVariants().rangeSeparator(),
|
||||
"data-slot": "date-range-picker-range-separator",
|
||||
}),
|
||||
slots.default?.() ?? props.children,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, useAttrs, watch } from "vue";
|
||||
import {
|
||||
injectPopoverRootContext,
|
||||
PopoverAnchor,
|
||||
useForwardExpose,
|
||||
} from "reka-ui";
|
||||
import { dateRangePickerVariants } from "@heroui-vue/styles";
|
||||
import OverlayAction from "../overlay/OverlayAction";
|
||||
import { usePopover } from "../popover/context";
|
||||
import { useDateRangePicker } from "./context";
|
||||
defineOptions({ name: "DateRangePickerTrigger", inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
|
||||
{ as: "button" },
|
||||
);
|
||||
const picker = useDateRangePicker();
|
||||
const popover = usePopover();
|
||||
const root = injectPopoverRootContext();
|
||||
const attrs = useAttrs();
|
||||
const { forwardRef, currentElement } = useForwardExpose();
|
||||
const focusVisible = ref(false);
|
||||
const triggerId = computed(
|
||||
() => (attrs.id as string | undefined) ?? popover.triggerId,
|
||||
);
|
||||
const disabled = computed(
|
||||
() => props.isDisabled || picker.disabled.value || picker.readOnly.value,
|
||||
);
|
||||
const defaultLabelledBy = computed(() => {
|
||||
if (attrs["aria-label"] || attrs["aria-labelledby"]) return undefined;
|
||||
const label = picker.labelledBy();
|
||||
return label ? [triggerId.value, label].join(" ") : undefined;
|
||||
});
|
||||
const defaultLabel = computed(() => {
|
||||
if (attrs["aria-label"] || attrs["aria-labelledby"]) return undefined;
|
||||
if (defaultLabelledBy.value) return undefined;
|
||||
return picker.locale.value.toLowerCase().startsWith("zh")
|
||||
? "日历"
|
||||
: "Calendar";
|
||||
});
|
||||
watch(
|
||||
[currentElement, triggerId],
|
||||
([element, id]) => {
|
||||
picker.trigger.value = element;
|
||||
picker.triggerId.value = id;
|
||||
root.triggerElement.value = element;
|
||||
root.triggerId = id;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<PopoverAnchor as-child>
|
||||
<OverlayAction
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:id="triggerId"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:is-disabled="disabled"
|
||||
:activate="popover.state.toggle"
|
||||
:class="dateRangePickerVariants().trigger()"
|
||||
data-slot="date-range-picker-trigger"
|
||||
aria-haspopup="dialog"
|
||||
:aria-expanded="popover.state.isOpen.value"
|
||||
:aria-controls="
|
||||
popover.state.isOpen.value ? popover.contentId.value : undefined
|
||||
"
|
||||
:aria-label="($attrs['aria-label'] as string | undefined) ?? defaultLabel"
|
||||
:aria-labelledby="
|
||||
($attrs['aria-labelledby'] as string | undefined) ?? defaultLabelledBy
|
||||
"
|
||||
:aria-describedby="
|
||||
($attrs['aria-describedby'] as string | undefined) ??
|
||||
picker.describedBy()
|
||||
"
|
||||
:data-open="popover.state.isOpen.value || undefined"
|
||||
:data-disabled="disabled || undefined"
|
||||
:data-focus-visible="focusVisible || undefined"
|
||||
@focus="focusVisible = true"
|
||||
@blur="focusVisible = false"
|
||||
>
|
||||
<slot />
|
||||
</OverlayAction>
|
||||
</PopoverAnchor>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import { dateRangePickerVariants } from "@heroui-vue/styles";
|
||||
defineOptions({ name: "DateRangePickerTriggerIndicator", inheritAttrs: false });
|
||||
withDefaults(defineProps<{ as?: string }>(), { as: "span" });
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
aria-hidden="true"
|
||||
:class="dateRangePickerVariants().triggerIndicator()"
|
||||
data-slot="date-range-picker-trigger-indicator"
|
||||
>
|
||||
<slot>
|
||||
<!-- Adapted from HeroUI ce90ea3 IconCalendar; Apache-2.0. -->
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
fill="none"
|
||||
height="1em"
|
||||
role="presentation"
|
||||
viewBox="0 0 13 14"
|
||||
width="1em"
|
||||
>
|
||||
<path
|
||||
clip-rule="evenodd"
|
||||
d="M3.75 4.5A.75.75 0 0 1 3 3.75v-.748a1.5 1.5 0 0 0-1.5 1.5v1h10v-1a1.5 1.5 0 0 0-1.5-1.5v.75a.75.75 0 1 1-1.5 0v-.75h-4v.747a.75.75 0 0 1-.75.75ZM8.5 1.501h-4V.75a.75.75 0 0 0-1.5 0v.752a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h7a3 3 0 0 0 3-3v-6a3 3 0 0 0-3-3v-.75a.75.75 0 0 0-1.5 0v.75Zm-7 5.5v3.5a1.5 1.5 0 0 0 1.5 1.5h7a1.5 1.5 0 0 0 1.5-1.5v-3.5h-10Z"
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</slot>
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
import { defineComponent, inject, watch } from "vue";
|
||||
import { dateRangeFieldKey } from "../date-field/context";
|
||||
|
||||
/** Reka keeps partially typed endpoint segments after an accepted empty range.
|
||||
* Clear both endpoint drafts on reset/external empty without replacing DOM,
|
||||
* focus or element ids. */
|
||||
export default defineComponent({
|
||||
name: "EmptyRangeDateBridge",
|
||||
props: { revision: { type: Number, required: true } },
|
||||
setup(props) {
|
||||
const field = inject(dateRangeFieldKey)!;
|
||||
watch(
|
||||
() => props.revision,
|
||||
() => {
|
||||
const segments = field.root.segmentValues;
|
||||
for (const endpoint of ["start", "end"] as const) {
|
||||
const values = segments[endpoint].value;
|
||||
segments[endpoint].value = Object.fromEntries(
|
||||
Object.keys(values).map((part) => [
|
||||
part,
|
||||
part === "dayPeriod" ? "AM" : null,
|
||||
]),
|
||||
) as typeof values;
|
||||
}
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
return () => null;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
inject,
|
||||
type ComputedRef,
|
||||
type InjectionKey,
|
||||
type ShallowRef,
|
||||
} from "vue";
|
||||
import type {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
DateValue,
|
||||
Time,
|
||||
ZonedDateTime,
|
||||
} from "@internationalized/date";
|
||||
import type { OverlayState } from "../../composables/useOverlayState";
|
||||
import type { CalendarRangeModel } from "../date/range-selection";
|
||||
import type { CalendarWeekday } from "../date/calendar";
|
||||
|
||||
export type DateRangePickerTimeValue = Time | CalendarDateTime | ZonedDateTime;
|
||||
|
||||
/** Both endpoints stay independently editable; a missing endpoint is an
|
||||
* uncommitted time draft while the accepted range is empty. */
|
||||
export interface DateRangePickerTimeRange {
|
||||
start: DateRangePickerTimeValue | null;
|
||||
end: DateRangePickerTimeValue | null;
|
||||
}
|
||||
|
||||
export interface DateRangePickerState {
|
||||
value: CalendarRangeModel;
|
||||
timeRange: DateRangePickerTimeRange | null;
|
||||
setValue: (value: CalendarRangeModel) => void;
|
||||
setTimeRange: (value: DateRangePickerTimeRange | null) => void;
|
||||
}
|
||||
|
||||
export interface DateRangePickerRenderProps {
|
||||
value: CalendarRangeModel;
|
||||
isOpen: boolean;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
isRequired: boolean;
|
||||
isInvalid: boolean;
|
||||
isFocusWithin: boolean;
|
||||
isFocused: boolean;
|
||||
isFocusVisible: boolean;
|
||||
validationErrors: string[];
|
||||
timeRange: DateRangePickerTimeRange | null;
|
||||
state: DateRangePickerState;
|
||||
open: () => void;
|
||||
close: () => void;
|
||||
toggle: () => void;
|
||||
}
|
||||
|
||||
export interface DateRangePickerEscapeOptions {
|
||||
disabled: boolean;
|
||||
handlers: ((event: Event) => void)[];
|
||||
}
|
||||
|
||||
/** One accepted range owner shared by the two field endpoints, an unbound
|
||||
* RangeCalendar and the native submission layer. */
|
||||
export interface DateRangePickerContext {
|
||||
state: OverlayState;
|
||||
trigger: ShallowRef<HTMLElement | undefined>;
|
||||
triggerId: ShallowRef<string | undefined>;
|
||||
value: ComputedRef<CalendarRangeModel>;
|
||||
dates: ComputedRef<DateValue[]>;
|
||||
timeRange: ComputedRef<DateRangePickerTimeRange | null>;
|
||||
setTimeRange: (value: DateRangePickerTimeRange | null) => void;
|
||||
requestRange: (value: CalendarRangeModel) => void;
|
||||
minValue: ComputedRef<DateValue | undefined>;
|
||||
maxValue: ComputedRef<DateValue | undefined>;
|
||||
isDateUnavailable: (
|
||||
value: DateValue,
|
||||
anchorDate?: CalendarDate | null,
|
||||
) => boolean;
|
||||
allowsNonContiguousRanges: () => boolean;
|
||||
disabled: ComputedRef<boolean>;
|
||||
readOnly: ComputedRef<boolean>;
|
||||
invalid: ComputedRef<boolean>;
|
||||
locale: ComputedRef<string>;
|
||||
dir: ComputedRef<"ltr" | "rtl">;
|
||||
labelledBy: () => string | undefined;
|
||||
describedBy: () => string | undefined;
|
||||
firstDayOfWeek: () => CalendarWeekday | undefined;
|
||||
pageBehavior: () => "visible" | "single" | undefined;
|
||||
placeholder: ComputedRef<DateValue>;
|
||||
calendarFallback: () => CalendarRangeModel;
|
||||
escapeOptions: ShallowRef<DateRangePickerEscapeOptions>;
|
||||
shouldCloseOnSelect: () => boolean;
|
||||
}
|
||||
|
||||
export const dateRangePickerKey: InjectionKey<DateRangePickerContext> = Symbol(
|
||||
"hv-date-range-picker",
|
||||
);
|
||||
|
||||
export function useDateRangePicker() {
|
||||
const value = inject(dateRangePickerKey, undefined);
|
||||
if (!value) throw new Error("DateRangePicker parts require DateRangePicker.");
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,500 @@
|
||||
import {
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
h,
|
||||
nextTick,
|
||||
provide,
|
||||
ref,
|
||||
shallowRef,
|
||||
watch,
|
||||
watchEffect,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { DateRangeFieldRoot } from "reka-ui";
|
||||
import {
|
||||
getLocalTimeZone,
|
||||
Time,
|
||||
toCalendarDate,
|
||||
toCalendarDateTime,
|
||||
today,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import {
|
||||
useChoiceField,
|
||||
useChoiceForm,
|
||||
validationInput,
|
||||
type ChoiceFieldProps,
|
||||
} from "../choice/shared";
|
||||
import type { ValidateResult } from "../field/context";
|
||||
import { dateFieldKey } from "../date-field/context";
|
||||
import { disabledContextKey } from "../field/disabled";
|
||||
import { useAcceptedCalendarRange } from "../date/model";
|
||||
import {
|
||||
copyCalendarRange,
|
||||
type CalendarRangeModel,
|
||||
} from "../date/range-selection";
|
||||
import {
|
||||
copyDateValue,
|
||||
dateForLocale,
|
||||
serializeDateValue,
|
||||
} from "../date/value";
|
||||
import PrimitiveNode from "../date-field/PrimitiveNode";
|
||||
import DateRangeFieldBody from "./DateRangeFieldBody.vue";
|
||||
import EmptyRangeDateBridge from "./EmptyRangeDateBridge";
|
||||
import type {
|
||||
DateRangePickerTimeRange,
|
||||
DateRangePickerTimeValue,
|
||||
} from "./context";
|
||||
|
||||
export interface DateRangePickerOwnerProps extends ChoiceFieldProps {
|
||||
modelValue?: CalendarRangeModel;
|
||||
value?: CalendarRangeModel;
|
||||
defaultValue?: CalendarRangeModel;
|
||||
placeholderValue?: DateValue | null;
|
||||
minValue?: DateValue | null;
|
||||
maxValue?: DateValue | null;
|
||||
isDateUnavailable?: (value: DateValue) => boolean;
|
||||
granularity?: "day" | "hour" | "minute" | "second";
|
||||
hourCycle?: 12 | 24;
|
||||
hideTimeZone?: boolean;
|
||||
shouldForceLeadingZeros?: boolean;
|
||||
allowsNonContiguousRanges?: boolean;
|
||||
locale?: string;
|
||||
dir?: "ltr" | "rtl";
|
||||
autoComplete?: string;
|
||||
startName?: string;
|
||||
endName?: string;
|
||||
validate?: (value: CalendarRangeModel) => ValidateResult;
|
||||
}
|
||||
|
||||
export interface DateRangePickerOwnerRoot {
|
||||
as: string;
|
||||
consumer?: Record<string, unknown>;
|
||||
overrides: Record<string, unknown>;
|
||||
}
|
||||
|
||||
const EMPTY_FIELD_RANGE: { start?: DateValue; end?: DateValue } = {
|
||||
start: undefined,
|
||||
end: undefined,
|
||||
};
|
||||
|
||||
function timeOf(
|
||||
value: DateValue | null | undefined,
|
||||
): DateRangePickerTimeValue | null {
|
||||
if (!value || !("hour" in value)) return null;
|
||||
return new Time(value.hour, value.minute, value.second, value.millisecond);
|
||||
}
|
||||
|
||||
function applyTime(
|
||||
value: DateValue,
|
||||
time: DateRangePickerTimeValue | null | undefined,
|
||||
): DateValue {
|
||||
if (!time) return value;
|
||||
const base: DateValue = "hour" in value ? value : toCalendarDateTime(value);
|
||||
return copyDateValue(
|
||||
base.set({
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
second: time.second,
|
||||
millisecond: time.millisecond,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function copyTime(value: DateRangePickerTimeValue): DateRangePickerTimeValue {
|
||||
return new Time(value.hour, value.minute, value.second, value.millisecond);
|
||||
}
|
||||
|
||||
/** One accepted range, one field/validation/native submission layer and one
|
||||
* partial-endpoint draft. The accepted model never holds half a range. */
|
||||
export function useDateRangePickerOwner(
|
||||
props: DateRangePickerOwnerProps,
|
||||
attrs: Record<string, unknown>,
|
||||
options: {
|
||||
onChange: (value: CalendarRangeModel) => void;
|
||||
onReset?: () => void;
|
||||
onSelectComplete?: () => void;
|
||||
shouldCloseOnSelect?: () => boolean;
|
||||
},
|
||||
) {
|
||||
const config = useConfig();
|
||||
const instance = getCurrentInstance()!;
|
||||
const accepted = useAcceptedCalendarRange({
|
||||
value: () =>
|
||||
["modelValue", "model-value"].some((key) =>
|
||||
Object.hasOwn(instance.vnode.props ?? {}, key),
|
||||
)
|
||||
? props.modelValue
|
||||
: props.value,
|
||||
defaultValue: () => props.defaultValue,
|
||||
onChange: (value) => {
|
||||
field.edit();
|
||||
options.onChange(value);
|
||||
},
|
||||
disabled: () => field.field.disabled.value,
|
||||
readOnly: () => field.field.readOnly.value,
|
||||
});
|
||||
const field = useChoiceField<CalendarRangeModel>(props, attrs, {
|
||||
kind: "group",
|
||||
value: accepted.value,
|
||||
satisfied: () => accepted.value.value !== null,
|
||||
requiredMessage: "请填写此字段。",
|
||||
validate: (value) => {
|
||||
if (value) {
|
||||
if (props.minValue) {
|
||||
if (value.start.compare(props.minValue) < 0)
|
||||
return "开始日期不能早于最早日期。";
|
||||
if (value.end.compare(props.minValue) < 0)
|
||||
return "结束日期不能早于最早日期。";
|
||||
}
|
||||
if (props.maxValue) {
|
||||
if (value.start.compare(props.maxValue) > 0)
|
||||
return "开始日期不能晚于最晚日期。";
|
||||
if (value.end.compare(props.maxValue) > 0)
|
||||
return "结束日期不能晚于最晚日期。";
|
||||
}
|
||||
if (value.end.compare(value.start) < 0)
|
||||
return "结束日期不能早于开始日期。";
|
||||
if (props.isDateUnavailable?.(value.start)) return "此日期不可用。";
|
||||
if (props.isDateUnavailable?.(value.end)) return "此日期不可用。";
|
||||
if (!props.allowsNonContiguousRanges && props.isDateUnavailable) {
|
||||
// An interior unavailable day invalidates a contiguous range, while
|
||||
// the calendar still keeps the explicit non-contiguous policy.
|
||||
let day = toCalendarDate(value.start).add({ days: 1 });
|
||||
const end = toCalendarDate(value.end);
|
||||
while (day.compare(end) <= 0) {
|
||||
if (props.isDateUnavailable(day.copy())) return "此日期不可用。";
|
||||
const next = day.add({ days: 1 });
|
||||
if (next.compare(day) === 0) break;
|
||||
day = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return props.validate?.(value);
|
||||
},
|
||||
});
|
||||
provide(disabledContextKey, field.field.disabled);
|
||||
provide(dateFieldKey, {
|
||||
value: computed(() => accepted.value.value?.start ?? null),
|
||||
disabled: field.field.disabled,
|
||||
readOnly: field.field.readOnly,
|
||||
required: field.field.required,
|
||||
invalid: field.field.invalid,
|
||||
leadingZeros: () => props.shouldForceLeadingZeros,
|
||||
labelledBy: field.labelledBy,
|
||||
describedBy: field.describedBy,
|
||||
ariaLabel: () => attrs["aria-label"],
|
||||
});
|
||||
const locale = computed(
|
||||
() => props.locale ?? config?.locale.value ?? "en-US",
|
||||
);
|
||||
const dir = computed<"ltr" | "rtl">(
|
||||
() => props.dir ?? config?.dir?.value ?? "ltr",
|
||||
);
|
||||
const initialPlaceholder = (
|
||||
props.placeholderValue ??
|
||||
props.defaultValue?.start ??
|
||||
accepted.value.value?.start ??
|
||||
today(getLocalTimeZone())
|
||||
).copy();
|
||||
const lastPlaceholder = shallowRef(initialPlaceholder);
|
||||
const placeholder = computed(() => {
|
||||
let value = dateForLocale(
|
||||
props.placeholderValue ??
|
||||
accepted.value.value?.start ??
|
||||
lastPlaceholder.value,
|
||||
locale.value,
|
||||
);
|
||||
if (props.granularity && props.granularity !== "day" && !("hour" in value))
|
||||
value = toCalendarDateTime(value);
|
||||
return value;
|
||||
});
|
||||
const fieldRange = computed<{ start?: DateValue; end?: DateValue }>(() => {
|
||||
const value = accepted.wire.value;
|
||||
return value ? { start: value.start, end: value.end } : EMPTY_FIELD_RANGE;
|
||||
});
|
||||
const fieldRevision = ref(0);
|
||||
let incompleteDraft = false;
|
||||
const pendingTime = shallowRef<DateRangePickerTimeRange | null>(null);
|
||||
const timeRange = computed<DateRangePickerTimeRange | null>(() => {
|
||||
const value = accepted.value.value;
|
||||
if (value) return { start: timeOf(value.start), end: timeOf(value.end) };
|
||||
const pending = pendingTime.value;
|
||||
return pending
|
||||
? {
|
||||
start: pending.start ? copyTime(pending.start) : null,
|
||||
end: pending.end ? copyTime(pending.end) : null,
|
||||
}
|
||||
: null;
|
||||
});
|
||||
function setTimeRange(value: DateRangePickerTimeRange | null) {
|
||||
if (!value) {
|
||||
pendingTime.value = null;
|
||||
return;
|
||||
}
|
||||
const current = accepted.value.value;
|
||||
if (!current) {
|
||||
pendingTime.value = {
|
||||
start: value.start ? copyTime(value.start) : null,
|
||||
end: value.end ? copyTime(value.end) : null,
|
||||
};
|
||||
return;
|
||||
}
|
||||
const next = {
|
||||
start: applyTime(current.start, value.start),
|
||||
end: applyTime(current.end, value.end),
|
||||
};
|
||||
accepted.request(copyCalendarRange(next));
|
||||
}
|
||||
function calendarFallback(): CalendarRangeModel {
|
||||
const current = accepted.value.value;
|
||||
if (current) return current;
|
||||
const pending = pendingTime.value;
|
||||
if (!pending) return null;
|
||||
const base = placeholder.value;
|
||||
return {
|
||||
start: applyTime(base, pending.start),
|
||||
end: applyTime(base, pending.end),
|
||||
};
|
||||
}
|
||||
function requestRange(value: CalendarRangeModel) {
|
||||
if (!value) return;
|
||||
accepted.request(copyCalendarRange(value));
|
||||
if (options.shouldCloseOnSelect?.()) options.onSelectComplete?.();
|
||||
}
|
||||
watch(accepted.value, (value, previous) => {
|
||||
if (value) {
|
||||
lastPlaceholder.value = value.start.copy();
|
||||
pendingTime.value = null;
|
||||
} else if (previous) {
|
||||
pendingTime.value = null;
|
||||
incompleteDraft = false;
|
||||
fieldRevision.value++;
|
||||
}
|
||||
});
|
||||
/** Segment editing only exposes fields up to the visible granularity. Reka
|
||||
* builds the edited endpoint from one shared placeholder, so restore the
|
||||
* precision that the endpoint itself owned and could not display. */
|
||||
function preservePrecision(next: DateValue, previous?: DateValue | null) {
|
||||
if (!previous || !("hour" in previous) || !("hour" in next)) return next;
|
||||
const granularity = props.granularity ?? "minute";
|
||||
const patch: Record<string, number> = {
|
||||
millisecond: previous.millisecond,
|
||||
};
|
||||
if (granularity === "day") {
|
||||
patch.hour = previous.hour;
|
||||
patch.minute = previous.minute;
|
||||
patch.second = previous.second;
|
||||
} else if (granularity === "hour") {
|
||||
patch.minute = previous.minute;
|
||||
patch.second = previous.second;
|
||||
} else if (granularity !== "second") {
|
||||
patch.second = previous.second;
|
||||
}
|
||||
return copyDateValue(next.set(patch));
|
||||
}
|
||||
function onFieldRange(next: { start?: DateValue; end?: DateValue }) {
|
||||
if (field.field.disabled.value || field.field.readOnly.value) return;
|
||||
const previous = accepted.value.value;
|
||||
const start = next.start
|
||||
? preservePrecision(next.start, previous?.start)
|
||||
: null,
|
||||
end = next.end ? preservePrecision(next.end, previous?.end) : null;
|
||||
if (!start && !end) {
|
||||
incompleteDraft = false;
|
||||
accepted.request(null);
|
||||
return;
|
||||
}
|
||||
if (!start || !end) {
|
||||
incompleteDraft = true;
|
||||
return;
|
||||
}
|
||||
incompleteDraft = false;
|
||||
accepted.request(copyCalendarRange({ start, end }));
|
||||
}
|
||||
/** A half-edited endpoint must not survive closing or an external reset. */
|
||||
function settleField() {
|
||||
if (!incompleteDraft) return;
|
||||
incompleteDraft = false;
|
||||
accepted.restore();
|
||||
if (!accepted.value.value) fieldRevision.value++;
|
||||
}
|
||||
const proxy = ref<HTMLInputElement>();
|
||||
const nativeStart = ref<HTMLInputElement>();
|
||||
const nativeEnd = ref<HTMLInputElement>();
|
||||
const root = ref<HTMLElement>();
|
||||
const focused = ref(false);
|
||||
const focusVisible = ref(false);
|
||||
const focus = () =>
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
'[data-slot="date-input-group-segment"][tabindex="0"]',
|
||||
)
|
||||
?.focus();
|
||||
useChoiceForm(
|
||||
proxy,
|
||||
() => {
|
||||
accepted.reset();
|
||||
field.reset();
|
||||
pendingTime.value = null;
|
||||
incompleteDraft = false;
|
||||
options.onReset?.();
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
watchEffect(() => field.validity(proxy.value), { flush: "post" });
|
||||
const signature = computed(
|
||||
() =>
|
||||
`${props.granularity ?? "auto"}|${props.hourCycle ?? "auto"}|${placeholder.value.calendar.identifier}|${"hour" in placeholder.value}`,
|
||||
);
|
||||
watch(signature, () => {
|
||||
const ownerDocument = root.value?.ownerDocument;
|
||||
const old = ownerDocument?.activeElement as HTMLElement | null;
|
||||
const endpoint =
|
||||
old && root.value?.contains(old)
|
||||
? (old.closest("[data-range-endpoint]") as HTMLElement | null)?.dataset
|
||||
.rangeEndpoint
|
||||
: undefined;
|
||||
const part =
|
||||
old && root.value?.contains(old)
|
||||
? old.dataset.rekaDateFieldSegment
|
||||
: undefined;
|
||||
if (endpoint && part)
|
||||
void nextTick(() => {
|
||||
const current = ownerDocument?.activeElement;
|
||||
if (current === old || current === ownerDocument?.body)
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-range-endpoint="${endpoint}"] [data-reka-date-field-segment="${part}"]`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
});
|
||||
function state() {
|
||||
return {
|
||||
value: accepted.value.value,
|
||||
isDisabled: field.field.disabled.value,
|
||||
isReadOnly: field.field.readOnly.value,
|
||||
isRequired: field.field.required.value,
|
||||
isInvalid: field.field.invalid.value,
|
||||
isFocusWithin: focused.value,
|
||||
isFocused: focused.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
validationErrors: field.field.errors.value,
|
||||
};
|
||||
}
|
||||
function valueInput(
|
||||
part: "start" | "end",
|
||||
name: string | undefined,
|
||||
slot: string,
|
||||
refTarget: typeof nativeStart,
|
||||
) {
|
||||
return h("input", {
|
||||
ref: refTarget,
|
||||
type: "text",
|
||||
class: "hv-choice-input",
|
||||
tabindex: -1,
|
||||
"aria-hidden": "true",
|
||||
autoComplete: props.autoComplete ?? "off",
|
||||
readonly: field.field.readOnly.value,
|
||||
name,
|
||||
form: props.form,
|
||||
value: serializeDateValue(
|
||||
part === "start"
|
||||
? (accepted.value.value?.start ?? null)
|
||||
: (accepted.value.value?.end ?? null),
|
||||
),
|
||||
disabled: field.field.disabled.value,
|
||||
"data-slot": `${slot}-${part}-value`,
|
||||
"data-part": part,
|
||||
});
|
||||
}
|
||||
function inputNodes(slot = "date-range-picker") {
|
||||
return [
|
||||
valueInput("start", props.startName, slot, nativeStart),
|
||||
valueInput("end", props.endName, slot, nativeEnd),
|
||||
validationInput(
|
||||
proxy,
|
||||
props,
|
||||
field.field.disabled.value || field.field.readOnly.value,
|
||||
field.behavior.value,
|
||||
(event) => field.invalidEvent(event, focus),
|
||||
),
|
||||
];
|
||||
}
|
||||
function renderOwner(
|
||||
children: VNodeChild[],
|
||||
rootConfig: DateRangePickerOwnerRoot,
|
||||
) {
|
||||
return h(
|
||||
DateRangeFieldRoot,
|
||||
{
|
||||
key: signature.value,
|
||||
asChild: true,
|
||||
modelValue: fieldRange.value as never,
|
||||
placeholder: placeholder.value,
|
||||
granularity: props.granularity,
|
||||
hourCycle: props.hourCycle,
|
||||
hideTimeZone: props.hideTimeZone,
|
||||
locale: locale.value,
|
||||
dir: props.dir ?? config?.dir?.value,
|
||||
minValue: props.minValue ?? undefined,
|
||||
maxValue: props.maxValue ?? undefined,
|
||||
isDateUnavailable: (date: DateValue) =>
|
||||
!!props.isDateUnavailable?.(date),
|
||||
disabled: field.field.disabled.value,
|
||||
readonly: field.field.readOnly.value,
|
||||
// Submission stays in this owner: the base field must not add a third
|
||||
// combined name/value next to the two public endpoint names.
|
||||
"onUpdate:modelValue": onFieldRange,
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
h(DateRangeFieldBody, null, {
|
||||
default: () =>
|
||||
h(
|
||||
PrimitiveNode,
|
||||
{
|
||||
as: rootConfig.as,
|
||||
consumer: rootConfig.consumer,
|
||||
overrides: rootConfig.overrides,
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(EmptyRangeDateBridge, {
|
||||
revision:
|
||||
accepted.emptyRevision.value + fieldRevision.value,
|
||||
}),
|
||||
...children,
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
return {
|
||||
accepted,
|
||||
field,
|
||||
locale,
|
||||
dir,
|
||||
placeholder,
|
||||
root,
|
||||
nativeStart,
|
||||
proxy,
|
||||
focused,
|
||||
focusVisible,
|
||||
focus,
|
||||
timeRange,
|
||||
setTimeRange,
|
||||
calendarFallback,
|
||||
requestRange,
|
||||
onFieldRange,
|
||||
settleField,
|
||||
signature,
|
||||
state,
|
||||
inputNodes,
|
||||
renderOwner,
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,11 @@ import { computed, nextTick, ref } from "vue";
|
||||
import type { DateValue, Time } from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import { copyDateValue, sameDateValue } from "./value";
|
||||
import {
|
||||
copyCalendarRange,
|
||||
sameCalendarRange,
|
||||
type CalendarRangeModel,
|
||||
} from "./range-selection";
|
||||
|
||||
/** One accepted model, with a copied wire value to resynchronize editable
|
||||
* Reka segments after a completed proposal. Partial drafts stay in the base. */
|
||||
@@ -60,3 +65,59 @@ export function useAcceptedDateValue<
|
||||
}
|
||||
return { value, wire, emptyRevision, request, reset };
|
||||
}
|
||||
|
||||
/** One accepted range, with copied wire endpoints so an endpoint editor can
|
||||
* resynchronize after a completed or rejected proposal. Partial endpoint drafts
|
||||
* live in that editor, never in this accepted model. */
|
||||
export function useAcceptedCalendarRange(options: {
|
||||
value: () => CalendarRangeModel | undefined;
|
||||
defaultValue: () => CalendarRangeModel | undefined;
|
||||
onChange: (value: CalendarRangeModel) => void;
|
||||
disabled?: () => boolean;
|
||||
readOnly?: () => boolean;
|
||||
}) {
|
||||
const model = useChoiceValue<CalendarRangeModel>(
|
||||
() => copyCalendarRange(options.value()),
|
||||
() => copyCalendarRange(options.defaultValue()),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => options.onChange(copyCalendarRange(value)),
|
||||
);
|
||||
const revision = ref(0);
|
||||
const emptyRevision = ref(0);
|
||||
let requestId = 0;
|
||||
const value = computed(() => {
|
||||
const copy = copyCalendarRange(model.value.value);
|
||||
return copy ? Object.freeze(copy) : null;
|
||||
});
|
||||
const wire = computed(() => {
|
||||
void revision.value;
|
||||
return copyCalendarRange(value.value);
|
||||
});
|
||||
function restore() {
|
||||
revision.value++;
|
||||
void nextTick(() => {
|
||||
revision.value++;
|
||||
});
|
||||
}
|
||||
function request(next: CalendarRangeModel) {
|
||||
if (
|
||||
!options.disabled?.() &&
|
||||
!options.readOnly?.() &&
|
||||
!sameCalendarRange(value.value, next)
|
||||
)
|
||||
model.request(copyCalendarRange(next));
|
||||
restore();
|
||||
const id = ++requestId;
|
||||
if (next)
|
||||
void nextTick(() => {
|
||||
if (id === requestId && value.value === null) emptyRevision.value++;
|
||||
});
|
||||
}
|
||||
function reset() {
|
||||
requestId++;
|
||||
model.reset();
|
||||
restore();
|
||||
if (value.value === null) emptyRevision.value++;
|
||||
}
|
||||
return { value, wire, emptyRevision, request, reset, restore };
|
||||
}
|
||||
|
||||
@@ -21,6 +21,15 @@ export const copyCalendarRange = (
|
||||
: null;
|
||||
export const calendarRangeKey = (value: CalendarRangeModel) =>
|
||||
value ? `${dateValueKey(value.start)}|${dateValueKey(value.end)}` : "empty";
|
||||
export const sameCalendarRange = (
|
||||
a: CalendarRangeModel | undefined,
|
||||
b: CalendarRangeModel | undefined,
|
||||
) =>
|
||||
(!a && !b) ||
|
||||
(!!a &&
|
||||
!!b &&
|
||||
dateValueKey(a.start) === dateValueKey(b.start) &&
|
||||
dateValueKey(a.end) === dateValueKey(b.end));
|
||||
export function orderedCalendarRange(
|
||||
a: DateValue,
|
||||
b: DateValue,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
import { useAttrs } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import { inject, nextTick, onMounted, useAttrs, watch } from "vue";
|
||||
import { toCalendar, type DateValue } from "@internationalized/date";
|
||||
import {
|
||||
useRangeCalendar,
|
||||
type RangeCalendarOptions,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
type CalendarRangeModel,
|
||||
} from "../date/range-selection";
|
||||
import { calendarHeading } from "../date/calendar";
|
||||
import { dateRangePickerKey } from "../date-range-picker/context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<RangeCalendarOptions>();
|
||||
const emit = defineEmits<{
|
||||
@@ -35,7 +36,31 @@ defineSlots<{
|
||||
}) => unknown;
|
||||
}>();
|
||||
const attrs = useAttrs();
|
||||
const view = useRangeCalendar(props, emit);
|
||||
const picker = inject(dateRangePickerKey, undefined);
|
||||
const view = useRangeCalendar(
|
||||
props,
|
||||
emit,
|
||||
picker
|
||||
? {
|
||||
value: picker.value,
|
||||
request: picker.requestRange,
|
||||
fallback: picker.calendarFallback,
|
||||
minValue: () => picker.minValue.value,
|
||||
maxValue: () => picker.maxValue.value,
|
||||
isDateUnavailable: picker.isDateUnavailable,
|
||||
allowsNonContiguousRanges: picker.allowsNonContiguousRanges,
|
||||
locale: () => picker.locale.value,
|
||||
dir: () => picker.dir.value,
|
||||
firstDayOfWeek: () => picker.firstDayOfWeek(),
|
||||
pageBehavior: () => picker.pageBehavior(),
|
||||
isDisabled: () => picker.disabled.value,
|
||||
isReadOnly: () => picker.readOnly.value,
|
||||
isInvalid: () => picker.invalid.value,
|
||||
defaultFocusedValue: () =>
|
||||
picker.value.value?.start ?? picker.placeholder.value,
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
const {
|
||||
root,
|
||||
focus,
|
||||
@@ -53,6 +78,20 @@ const {
|
||||
anchorDate,
|
||||
highlightedRange,
|
||||
} = view;
|
||||
function focusForPicker(open: boolean) {
|
||||
if (!picker || !open || !view.inherits.value) return;
|
||||
void nextTick(() => {
|
||||
if (!picker.state.isOpen.value) return;
|
||||
const target = picker.value.value?.start ?? picker.placeholder.value;
|
||||
focusDate(toCalendar(target, focus.value.calendar), true);
|
||||
});
|
||||
}
|
||||
onMounted(() => focusForPicker(!!picker?.state.isOpen.value));
|
||||
watch(
|
||||
() => picker?.state.isOpen.value,
|
||||
(open) => focusForPicker(!!open),
|
||||
{ flush: "post" },
|
||||
);
|
||||
defineExpose({
|
||||
get element() {
|
||||
return root.value;
|
||||
|
||||
@@ -41,6 +41,28 @@ export interface RangeCalendarOptions extends Omit<
|
||||
anchorDate: CalendarDate | null,
|
||||
) => boolean;
|
||||
}
|
||||
/** Constraints a DateRangePicker owner passes to an otherwise unbound calendar.
|
||||
* An explicitly bound RangeCalendar keeps its own accepted value and rules. */
|
||||
export interface RangeCalendarInherited {
|
||||
value: ComputedRef<CalendarRangeModel>;
|
||||
request: (value: CalendarRangeModel) => void;
|
||||
fallback?: () => CalendarRangeModel;
|
||||
minValue?: () => DateValue | undefined;
|
||||
maxValue?: () => DateValue | undefined;
|
||||
isDateUnavailable?: (
|
||||
date: DateValue,
|
||||
anchorDate: CalendarDate | null,
|
||||
) => boolean;
|
||||
allowsNonContiguousRanges?: () => boolean;
|
||||
locale?: () => string;
|
||||
dir?: () => "ltr" | "rtl";
|
||||
firstDayOfWeek?: () => import("../date/calendar").CalendarWeekday | undefined;
|
||||
pageBehavior?: () => "visible" | "single" | undefined;
|
||||
isDisabled?: () => boolean;
|
||||
isReadOnly?: () => boolean;
|
||||
isInvalid?: () => boolean;
|
||||
defaultFocusedValue?: () => DateValue | undefined;
|
||||
}
|
||||
interface RangeEmit {
|
||||
(event: "update:modelValue", value: CalendarRangeModel): void;
|
||||
(event: "change", value: CalendarRangeModel): void;
|
||||
@@ -59,45 +81,79 @@ interface Gesture {
|
||||
}
|
||||
/** Range selection owns only the accepted value and an uncommitted anchor.
|
||||
* All calendar geometry, focus, paging and year navigation have one shared owner. */
|
||||
export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
export function useRangeCalendar(
|
||||
props: RangeCalendarOptions,
|
||||
emit: RangeEmit,
|
||||
inherited?: RangeCalendarInherited,
|
||||
) {
|
||||
const instance = getCurrentInstance()!;
|
||||
const has = (key: string) => Object.hasOwn(instance.vnode.props ?? {}, key);
|
||||
const fallback = copyCalendarRange(props.defaultValue);
|
||||
const model = useChoiceValue<CalendarRangeModel>(
|
||||
const inheritsValue = computed(
|
||||
() =>
|
||||
copyCalendarRange(
|
||||
has("modelValue") || has("model-value")
|
||||
? props.modelValue
|
||||
: props.value,
|
||||
),
|
||||
() => copyCalendarRange(fallback),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => {
|
||||
emit("update:modelValue", copyCalendarRange(value));
|
||||
emit("change", copyCalendarRange(value));
|
||||
},
|
||||
!!inherited &&
|
||||
!has("modelValue") &&
|
||||
!has("model-value") &&
|
||||
!has("value") &&
|
||||
!has("defaultValue") &&
|
||||
!has("default-value"),
|
||||
);
|
||||
const fallback = (): CalendarRangeModel =>
|
||||
copyCalendarRange(
|
||||
inheritsValue.value ? inherited?.fallback?.() : props.defaultValue,
|
||||
);
|
||||
const model = inheritsValue.value
|
||||
? {
|
||||
value: computed(() => copyCalendarRange(inherited!.value.value)),
|
||||
request: (value: CalendarRangeModel) =>
|
||||
inherited!.request(copyCalendarRange(value)),
|
||||
reset: () => {},
|
||||
}
|
||||
: useChoiceValue<CalendarRangeModel>(
|
||||
() =>
|
||||
copyCalendarRange(
|
||||
has("modelValue") || has("model-value")
|
||||
? props.modelValue
|
||||
: props.value,
|
||||
),
|
||||
() => fallback(),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => {
|
||||
emit("update:modelValue", copyCalendarRange(value));
|
||||
emit("change", copyCalendarRange(value));
|
||||
},
|
||||
);
|
||||
const anchorDate = shallowRef<CalendarDate | null>(null);
|
||||
const draftEnd = shallowRef<CalendarDate | null>(null);
|
||||
const dates = computed(() =>
|
||||
model.value.value ? [model.value.value.start, model.value.value.end] : [],
|
||||
);
|
||||
const unavailable = (date: DateValue) =>
|
||||
!!props.isDateUnavailable?.(date.copy(), anchorDate.value?.copy() ?? null);
|
||||
!!(props.isDateUnavailable ?? inherited?.isDateUnavailable)?.(
|
||||
date.copy(),
|
||||
anchorDate.value?.copy() ?? null,
|
||||
);
|
||||
const baseDisabled = (date: DateValue) =>
|
||||
calendarDayState(date, {
|
||||
isDateDisabled: props.isDateDisabled,
|
||||
minValue: props.minValue ?? view.min.value,
|
||||
maxValue: props.maxValue ?? view.max.value,
|
||||
minValue: props.minValue ?? inherited?.minValue?.() ?? view.min.value,
|
||||
maxValue: props.maxValue ?? inherited?.maxValue?.() ?? view.max.value,
|
||||
isDisabled: view.disabled.value,
|
||||
}).isDisabled;
|
||||
// Vue gives boolean props a false default, so an unset prop must not shadow
|
||||
// the inherited policy. Only an explicitly bound prop overrides it.
|
||||
const nonContiguous = () =>
|
||||
has("allowsNonContiguousRanges") || has("allows-non-contiguous-ranges")
|
||||
? !!props.allowsNonContiguousRanges
|
||||
: (inherited?.allowsNonContiguousRanges?.() ?? false);
|
||||
// Only an active draft constrains cross-barrier navigation. Cache by semantics,
|
||||
// not mutable DateValue identity; invalidated by reactive rules/bounds below.
|
||||
let barriers = new Map<string, ComputedRef<DateValue | undefined>>();
|
||||
function barrier(date: DateValue) {
|
||||
if (
|
||||
!anchorDate.value ||
|
||||
(!props.isDateUnavailable && !props.isDateDisabled)
|
||||
(!props.isDateUnavailable &&
|
||||
!props.isDateDisabled &&
|
||||
!inherited?.isDateUnavailable)
|
||||
)
|
||||
return undefined;
|
||||
const key = dateValueKey(date);
|
||||
@@ -111,7 +167,7 @@ export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
date,
|
||||
baseDisabled,
|
||||
unavailable,
|
||||
!!props.allowsNonContiguousRanges,
|
||||
nonContiguous(),
|
||||
)
|
||||
: undefined,
|
||||
),
|
||||
@@ -169,7 +225,7 @@ export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
return false;
|
||||
}
|
||||
const range = orderedCalendarRange(anchorDate.value, date);
|
||||
const value = convertCalendarRange(range, model.value.value ?? fallback);
|
||||
const value = convertCalendarRange(range, model.value.value ?? fallback());
|
||||
anchorDate.value = null;
|
||||
draftEnd.value = null;
|
||||
barriers.clear();
|
||||
@@ -398,6 +454,21 @@ export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
},
|
||||
emit,
|
||||
"range-calendar",
|
||||
inherited
|
||||
? {
|
||||
minValue: () => props.minValue ?? inherited.minValue?.(),
|
||||
maxValue: () => props.maxValue ?? inherited.maxValue?.(),
|
||||
defaultFocusedValue: () => inherited.defaultFocusedValue?.(),
|
||||
locale: () => props.locale ?? inherited.locale?.() ?? "en-US",
|
||||
dir: () => props.dir ?? inherited.dir?.() ?? "ltr",
|
||||
firstDayOfWeek: () =>
|
||||
props.firstDayOfWeek ?? inherited.firstDayOfWeek?.(),
|
||||
pageBehavior: () => props.pageBehavior ?? inherited.pageBehavior?.(),
|
||||
isDisabled: () => !!inherited.isDisabled?.(),
|
||||
isReadOnly: () => !!inherited.isReadOnly?.(),
|
||||
isInvalid: () => !!inherited.isInvalid?.(),
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
watch(
|
||||
() => dateValueKey(view.focus.value),
|
||||
@@ -420,6 +491,8 @@ export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
() => props.isDateUnavailable,
|
||||
() => props.isDateDisabled,
|
||||
() => props.allowsNonContiguousRanges,
|
||||
() => !!inherited?.isDateUnavailable,
|
||||
() => inherited?.allowsNonContiguousRanges?.(),
|
||||
() => dateValueKey(props.minValue),
|
||||
() => dateValueKey(props.maxValue),
|
||||
() => view.options.value.locale,
|
||||
@@ -449,5 +522,12 @@ export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
stopGesture();
|
||||
resetClick();
|
||||
});
|
||||
return { ...view, model, anchorDate, highlightedRange, cancel };
|
||||
return {
|
||||
...view,
|
||||
model,
|
||||
anchorDate,
|
||||
highlightedRange,
|
||||
cancel,
|
||||
inherits: inheritsValue,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -805,6 +805,33 @@ export type {
|
||||
DatePickerPopoverProps,
|
||||
} from "./types";
|
||||
|
||||
export {
|
||||
default as DateRangePicker,
|
||||
default as DateRangePickerRoot,
|
||||
} from "./components/date-range-picker/DateRangePicker.vue";
|
||||
export { default as DateRangePickerTrigger } from "./components/date-range-picker/DateRangePickerTrigger.vue";
|
||||
export { default as DateRangePickerTriggerIndicator } from "./components/date-range-picker/DateRangePickerTriggerIndicator.vue";
|
||||
export { default as DateRangePickerRangeSeparator } from "./components/date-range-picker/DateRangePickerRangeSeparator.vue";
|
||||
export { default as DateRangePickerPopover } from "./components/date-range-picker/DateRangePickerPopover.vue";
|
||||
export type {
|
||||
DateRangePickerRenderProps,
|
||||
DateRangePickerState,
|
||||
DateRangePickerTimeRange,
|
||||
DateRangePickerTimeValue,
|
||||
} from "./components/date-range-picker/context";
|
||||
export {
|
||||
dateRangePickerVariants,
|
||||
type DateRangePickerVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
DateRangePickerProps,
|
||||
DateRangePickerRootProps,
|
||||
DateRangePickerTriggerProps,
|
||||
DateRangePickerTriggerIndicatorProps,
|
||||
DateRangePickerRangeSeparatorProps,
|
||||
DateRangePickerPopoverProps,
|
||||
} from "./types";
|
||||
|
||||
export {
|
||||
dateFieldVariants,
|
||||
dateInputGroupVariants,
|
||||
|
||||
@@ -662,6 +662,28 @@ export type DatePickerPopoverProps = InstanceType<
|
||||
typeof DatePickerPopover
|
||||
>["$props"];
|
||||
|
||||
import type DateRangePicker from "./components/date-range-picker/DateRangePicker.vue";
|
||||
import type DateRangePickerTrigger from "./components/date-range-picker/DateRangePickerTrigger.vue";
|
||||
import type DateRangePickerTriggerIndicator from "./components/date-range-picker/DateRangePickerTriggerIndicator.vue";
|
||||
import type DateRangePickerRangeSeparator from "./components/date-range-picker/DateRangePickerRangeSeparator.vue";
|
||||
import type DateRangePickerPopover from "./components/date-range-picker/DateRangePickerPopover.vue";
|
||||
export type DateRangePickerProps = InstanceType<
|
||||
typeof DateRangePicker
|
||||
>["$props"];
|
||||
export type DateRangePickerRootProps = DateRangePickerProps;
|
||||
export type DateRangePickerTriggerProps = InstanceType<
|
||||
typeof DateRangePickerTrigger
|
||||
>["$props"];
|
||||
export type DateRangePickerTriggerIndicatorProps = InstanceType<
|
||||
typeof DateRangePickerTriggerIndicator
|
||||
>["$props"];
|
||||
export type DateRangePickerRangeSeparatorProps = InstanceType<
|
||||
typeof DateRangePickerRangeSeparator
|
||||
>["$props"];
|
||||
export type DateRangePickerPopoverProps = InstanceType<
|
||||
typeof DateRangePickerPopover
|
||||
>["$props"];
|
||||
|
||||
import type ToastProvider from "./components/toast/ToastProvider.vue";
|
||||
import type Toast from "./components/toast/Toast.vue";
|
||||
import type ToastContent from "./components/toast/ToastContent.vue";
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ pnpm test:related packages/vue/src/components/combo-box/ComboBox.vue
|
||||
| pnpm build:docs | 库、样式与文档站静态构建,保留文档渲染要求,不视为组件SSR支持 |
|
||||
| pnpm build:playground | 浏览器验证入口生产构建 |
|
||||
|
||||
现有91个测试文件包含1322项客户端用例,默认全部运行;不再维护SSR排除规则或相关命令。逐像素自动对比、完整读屏矩阵、真机矩阵、Nuxt集成暂不投入。
|
||||
现有97个测试文件包含1410项客户端用例,默认全部运行;不再维护SSR排除规则或相关命令。逐像素自动对比、完整读屏矩阵、真机矩阵、Nuxt集成暂不投入。
|
||||
|
||||
不新增普遍服务端、无document运行、ID水合稳定、Teleport服务端、Nuxt服务端适配等验收要求。NodeNext是发布类型解析模式,不代表要求SSR支持。
|
||||
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||
const demos = import.meta.glob("../apps/docs/demos/date-range-picker-*.vue", {
|
||||
eager: true,
|
||||
import: "default",
|
||||
});
|
||||
const expected = [
|
||||
"basic",
|
||||
"disabled",
|
||||
"controlled",
|
||||
"with-validation",
|
||||
"format-options",
|
||||
"form-example",
|
||||
"with-custom-indicator",
|
||||
"render-function",
|
||||
"international-calendar",
|
||||
"custom-styles",
|
||||
];
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
},
|
||||
);
|
||||
});
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
await flushPromises();
|
||||
vi.useRealTimers();
|
||||
vi.unstubAllGlobals();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
function mountDemo(name: string) {
|
||||
const demo = demos[`../apps/docs/demos/date-range-picker-${name}.vue`];
|
||||
const w = mount(demo as never, { attachTo: document.body });
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
async function open(w: ReturnType<typeof mount>) {
|
||||
await w.get('[data-slot="date-range-picker-trigger"]').trigger("click");
|
||||
await flushPromises();
|
||||
}
|
||||
function cell(date: string) {
|
||||
return document.querySelector<HTMLElement>(
|
||||
`[data-slot="range-calendar-cell"][data-date="${date}"]:not([data-outside-month])`,
|
||||
);
|
||||
}
|
||||
async function pick(date: string) {
|
||||
const target = cell(date);
|
||||
expect(target).not.toBeNull();
|
||||
target!.click();
|
||||
await flushPromises();
|
||||
}
|
||||
function input(
|
||||
w: ReturnType<typeof mount>,
|
||||
slot: "start" | "end",
|
||||
): HTMLInputElement {
|
||||
return w.get(`[data-slot="date-range-picker-${slot}-value"]`)
|
||||
.element as HTMLInputElement;
|
||||
}
|
||||
|
||||
describe("DateRangePicker documentation", () => {
|
||||
it("includes every pinned preview and uses the displayed SFC as its implementation", () => {
|
||||
const md = readFileSync(
|
||||
"apps/docs/components/date-range-picker.md",
|
||||
"utf8",
|
||||
);
|
||||
expect(
|
||||
[
|
||||
...md.matchAll(/<ComponentPreview name="date-range-picker-([^"]+)"/g),
|
||||
].map((match) => match[1]),
|
||||
).toEqual(expected);
|
||||
expect(md).not.toContain("[!toc]");
|
||||
expect(Object.keys(demos)).toHaveLength(10);
|
||||
});
|
||||
|
||||
it("mounts all ten examples without warnings or missing range controls", async () => {
|
||||
const warnings: string[] = [];
|
||||
for (const demo of Object.values(demos)) {
|
||||
const w = mount(demo as never, {
|
||||
global: {
|
||||
config: { warnHandler: (message) => warnings.push(message) },
|
||||
},
|
||||
});
|
||||
wrappers.push(w);
|
||||
await flushPromises();
|
||||
expect(w.find('[data-slot="date-range-picker"]').exists()).toBe(true);
|
||||
expect(w.findAll('[data-slot="date-input-group-input"]')).toHaveLength(2);
|
||||
expect(w.find('[data-slot="date-range-picker-trigger"]').exists()).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
w.findAll('[data-slot="date-input-group-segment"]').length,
|
||||
).toBeGreaterThanOrEqual(6);
|
||||
expect(w.findAll('input[data-part="start"]')).toHaveLength(1);
|
||||
expect(w.findAll('input[data-part="end"]')).toHaveLength(1);
|
||||
}
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
|
||||
it("the controlled example updates and clears the real range", async () => {
|
||||
const w = mountDemo("controlled");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(w.get('[data-slot="description"]').text()).not.toContain("(空)");
|
||||
await w
|
||||
.findAll("button")
|
||||
.find((button) => button.text() === "清空")!
|
||||
.trigger("click");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toBe("");
|
||||
expect(input(w, "end").value).toBe("");
|
||||
expect(w.get('[data-slot="description"]').text()).toContain("(空)");
|
||||
await w
|
||||
.findAll("button")
|
||||
.find((button) => button.text() === "设为一周")!
|
||||
.trigger("click");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(w.get('[data-slot="description"]').text()).not.toContain("(空)");
|
||||
});
|
||||
|
||||
it("the disabled example keeps values visible and non-editable", async () => {
|
||||
const w = mountDemo("disabled");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").disabled).toBe(true);
|
||||
expect(input(w, "end").disabled).toBe(true);
|
||||
expect(input(w, "start").value).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(
|
||||
w.get('[data-slot="date-range-picker-trigger"]').attributes("disabled"),
|
||||
).toBeDefined();
|
||||
expect(w.get('[data-slot="description"]').text()).toContain("已禁用");
|
||||
});
|
||||
|
||||
it("format options keeps one range value while both TimeFields edit independently", async () => {
|
||||
const w = mountDemo("format-options");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toContain("T08:45:00");
|
||||
expect(input(w, "end").value).toContain("T18:45:00");
|
||||
await open(w);
|
||||
const timeFields = document.querySelectorAll('[data-slot="time-field"]');
|
||||
expect(timeFields).toHaveLength(2);
|
||||
expect(document.querySelectorAll('[name="startTime"]')).toHaveLength(1);
|
||||
expect(document.querySelectorAll('[name="endTime"]')).toHaveLength(1);
|
||||
const hour =
|
||||
timeFields[0]!.querySelector<HTMLElement>('[data-type="hour"]')!;
|
||||
hour.focus();
|
||||
hour.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowUp",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toContain("T09:45:00");
|
||||
expect(input(w, "end").value).toContain("T18:45:00");
|
||||
expect(document.body.textContent).toContain("已选:");
|
||||
expect(document.body.textContent).toContain("2026");
|
||||
expect(document.querySelectorAll('[name="startDate"]')).toHaveLength(1);
|
||||
expect(document.querySelectorAll('[name="endDate"]')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("format options switches to day granularity without losing the picker", async () => {
|
||||
const w = mountDemo("format-options");
|
||||
await flushPromises();
|
||||
const trigger = w.get('[data-slot="select-trigger"]');
|
||||
await trigger.trigger("click");
|
||||
await flushPromises();
|
||||
const option = [
|
||||
...document.querySelectorAll<HTMLElement>("[role=option]"),
|
||||
].find((node) => node.textContent?.trim() === "日")!;
|
||||
expect(option).toBeTruthy();
|
||||
option.click();
|
||||
await flushPromises();
|
||||
expect(document.querySelectorAll('[data-slot="time-field"]')).toHaveLength(
|
||||
0,
|
||||
);
|
||||
expect(input(w, "start").value).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(input(w, "end").value).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(document.querySelectorAll('[name="startDate"]')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("the form example submits a complete range and clears after success", async () => {
|
||||
vi.useFakeTimers();
|
||||
const w = mountDemo("form-example");
|
||||
await flushPromises();
|
||||
const submit = () =>
|
||||
w.findAll("button").find((button) => button.text().includes("提交"))!;
|
||||
expect(submit().attributes("disabled")).toBeDefined();
|
||||
expect(w.findAll('[name="tripStartDate"]')).toHaveLength(1);
|
||||
expect(w.findAll('[name="tripEndDate"]')).toHaveLength(1);
|
||||
const start = today(getLocalTimeZone());
|
||||
await open(w);
|
||||
await pick(start.toString());
|
||||
await pick(start.toString());
|
||||
expect(submit().attributes("disabled")).toBeUndefined();
|
||||
await w.get("form").trigger("submit");
|
||||
await flushPromises();
|
||||
expect(submit().text()).toContain("提交中");
|
||||
vi.advanceTimersByTime(1300);
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).toBe("");
|
||||
expect(input(w, "end").value).toBe("");
|
||||
expect(submit().text()).toBe("提交");
|
||||
});
|
||||
|
||||
it("the custom indicator uses the Tabler icon instead of the default SVG", async () => {
|
||||
const w = mountDemo("with-custom-indicator");
|
||||
await flushPromises();
|
||||
const icon = w.get('[data-slot="date-range-picker-trigger-indicator"] svg');
|
||||
expect(icon.attributes("viewBox")).toBe("0 0 24 24");
|
||||
expect(
|
||||
w
|
||||
.find(
|
||||
'[data-slot="date-range-picker-trigger-indicator"] svg[viewBox="0 0 13 14"]',
|
||||
)
|
||||
.exists(),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("the render-function example keeps consumer elements and attributes", async () => {
|
||||
const w = mountDemo("render-function");
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="date-range-picker"]').element.tagName).toBe(
|
||||
"SECTION",
|
||||
);
|
||||
expect(
|
||||
w.get('[data-slot="date-range-picker"]').attributes("data-custom"),
|
||||
).toBe("date-range-picker");
|
||||
expect(
|
||||
w.get('[data-slot="date-input-group"]').attributes("data-custom"),
|
||||
).toBe("date-field-group");
|
||||
expect(
|
||||
w
|
||||
.get('[data-slot="date-range-picker-trigger"]')
|
||||
.attributes("data-custom"),
|
||||
).toBe("date-range-picker-trigger");
|
||||
});
|
||||
|
||||
it("the international calendar displays its locale calendar and keeps values", async () => {
|
||||
const w = mountDemo("international-calendar");
|
||||
await flushPromises();
|
||||
expect(input(w, "start").value).not.toBe("");
|
||||
await open(w);
|
||||
const header = document.querySelector(
|
||||
'[data-slot="range-calendar-header-cell"]',
|
||||
)?.textContent;
|
||||
expect(header).toBeTruthy();
|
||||
expect(header).not.toMatch(/^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)$/);
|
||||
const selected = document.querySelector(
|
||||
'[data-slot="range-calendar-cell"][data-selection-start="true"]',
|
||||
);
|
||||
expect(selected).not.toBeNull();
|
||||
});
|
||||
|
||||
it("the custom styles example applies consumer classes without component patches", async () => {
|
||||
const w = mountDemo("custom-styles");
|
||||
await flushPromises();
|
||||
const group = w.get('[data-slot="date-input-group"]');
|
||||
expect(group.classes()).toContain("rounded-xl");
|
||||
expect(group.classes()).toContain("border");
|
||||
expect(group.classes()).toContain("hv-date-input-group--secondary");
|
||||
expect(
|
||||
w.get('[data-slot="date-range-picker-range-separator"]').classes(),
|
||||
).toContain("text-muted");
|
||||
expect(
|
||||
w.get('[data-slot="date-range-picker-trigger"]').classes(),
|
||||
).toContain("text-muted");
|
||||
await open(w);
|
||||
expect(
|
||||
document.querySelector('[data-slot="date-range-picker-popover"]')
|
||||
?.className,
|
||||
).toContain("border");
|
||||
expect(
|
||||
document.querySelector('[data-slot="range-calendar"]')?.className,
|
||||
).toContain("bg-surface");
|
||||
});
|
||||
|
||||
it("the validation example exposes required and invalid state through the form", async () => {
|
||||
const w = mountDemo("with-validation");
|
||||
await flushPromises();
|
||||
const validation = w.get(".hv-choice-validation")
|
||||
.element as HTMLInputElement;
|
||||
expect(validation.checkValidity()).toBe(false);
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="field-error"]').text()).toContain(
|
||||
"请选择从今天起的有效日期范围",
|
||||
);
|
||||
const start = today(getLocalTimeZone());
|
||||
await open(w);
|
||||
await pick(start.toString());
|
||||
await pick(start.toString());
|
||||
expect(validation.checkValidity()).toBe(true);
|
||||
expect(w.find('[data-slot="field-error"]').exists()).toBe(false);
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -54,6 +54,27 @@ for (const id of process.argv.slice(2)) {
|
||||
.includes("hv-time-field--full-width"),
|
||||
);
|
||||
}
|
||||
if (id === "date-range-picker") {
|
||||
assert(lib.DateRangePicker === lib.DateRangePickerRoot);
|
||||
assert(lib.dateRangePickerVariants().base() === "hv-date-range-picker");
|
||||
assert(
|
||||
lib.dateRangePickerVariants().trigger() ===
|
||||
"hv-date-range-picker__trigger",
|
||||
);
|
||||
assert(
|
||||
lib.dateRangePickerVariants().rangeSeparator() ===
|
||||
"hv-date-range-picker__range-separator",
|
||||
);
|
||||
assert(
|
||||
lib.dateRangePickerVariants().popover() ===
|
||||
"hv-date-range-picker__popover",
|
||||
);
|
||||
assert(
|
||||
lib.dateRangePickerVariants().triggerIndicator() ===
|
||||
"hv-date-range-picker__trigger-indicator",
|
||||
);
|
||||
assert(lib.DateFieldInput);
|
||||
}
|
||||
if (id === "date-picker") {
|
||||
assert(lib.DatePicker === lib.DatePickerRoot);
|
||||
assert(lib.datePickerVariants().base() === "hv-date-picker");
|
||||
|
||||
@@ -421,5 +421,33 @@
|
||||
"data-selection-start",
|
||||
"data-selection-end"
|
||||
]
|
||||
},
|
||||
"date-range-picker": {
|
||||
"exports": [
|
||||
"DateRangePicker",
|
||||
"DateRangePickerRoot",
|
||||
"DateRangePickerTrigger",
|
||||
"DateRangePickerTriggerIndicator",
|
||||
"DateRangePickerRangeSeparator",
|
||||
"DateRangePickerPopover",
|
||||
"dateRangePickerVariants",
|
||||
"DateFieldGroup",
|
||||
"DateFieldInput",
|
||||
"DateFieldInputContainer",
|
||||
"DateFieldSegment",
|
||||
"DateFieldSuffix",
|
||||
"RangeCalendar",
|
||||
"RangeCalendarCell"
|
||||
],
|
||||
"css": [
|
||||
".hv-date-range-picker",
|
||||
".hv-date-range-picker__trigger",
|
||||
".hv-date-range-picker__trigger-indicator",
|
||||
".hv-date-range-picker__range-separator",
|
||||
".hv-date-range-picker__popover",
|
||||
"--reka-popper-transform-origin",
|
||||
"data-exiting",
|
||||
"data-endpoint"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
parseZonedDateTime,
|
||||
Time,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldInputContainer,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
DateRangePicker,
|
||||
DateRangePickerPopover,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerRoot,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
RangeCalendar,
|
||||
dateRangePickerVariants,
|
||||
type DateFieldInputProps,
|
||||
type DateRangePickerPopoverProps,
|
||||
type DateRangePickerProps,
|
||||
type DateRangePickerRangeSeparatorProps,
|
||||
type DateRangePickerRenderProps,
|
||||
type DateRangePickerRootProps,
|
||||
type DateRangePickerState,
|
||||
type DateRangePickerTimeRange,
|
||||
type DateRangePickerTimeValue,
|
||||
type DateRangePickerTriggerIndicatorProps,
|
||||
type DateRangePickerTriggerProps,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
type DateRange = { start: DateValue; end: DateValue };
|
||||
const day = new CalendarDate(2024, 2, 10);
|
||||
const range: DateRange = {
|
||||
start: day,
|
||||
end: new CalendarDate(2024, 2, 15),
|
||||
};
|
||||
const dateTime = new CalendarDateTime(2024, 2, 10, 9, 30);
|
||||
const zoned = parseZonedDateTime("2024-01-01T09:30+08:00[Asia/Shanghai]");
|
||||
const time: DateRangePickerTimeValue = new Time(9, 30);
|
||||
const timeRange: DateRangePickerTimeRange = {
|
||||
start: time,
|
||||
end: new CalendarDateTime(2024, 1, 1, 18, 30),
|
||||
};
|
||||
const values: DateRangePickerProps[] = [
|
||||
{
|
||||
modelValue: range,
|
||||
value: null,
|
||||
defaultValue: { start: dateTime, end: zoned },
|
||||
placeholderValue: day,
|
||||
minValue: day,
|
||||
maxValue: day.add({ years: 1 }),
|
||||
isDateUnavailable: (value) => value.day === 20,
|
||||
allowsNonContiguousRanges: true,
|
||||
granularity: "second",
|
||||
hourCycle: 24,
|
||||
hideTimeZone: true,
|
||||
shouldForceLeadingZeros: true,
|
||||
locale: "zh-CN",
|
||||
firstDayOfWeek: "mon",
|
||||
pageBehavior: "single",
|
||||
dir: "rtl",
|
||||
startName: "startDate",
|
||||
endName: "endDate",
|
||||
form: "trip",
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isRequired: true,
|
||||
isInvalid: false,
|
||||
shouldCloseOnSelect: false,
|
||||
validate: (value) =>
|
||||
value ? (value.end.compare(value.start) < 0 ? "Reversed" : null) : null,
|
||||
"onUpdate:modelValue": (value) => {
|
||||
const accepted: DateRange | null = value;
|
||||
void accepted;
|
||||
},
|
||||
onChange: (value) => {
|
||||
const accepted: DateRange | null = value;
|
||||
void accepted;
|
||||
},
|
||||
"onUpdate:open": (value) => {
|
||||
const open: boolean = value;
|
||||
void open;
|
||||
},
|
||||
onOpenChange: (value) => {
|
||||
const open: boolean = value;
|
||||
void open;
|
||||
},
|
||||
},
|
||||
];
|
||||
const root: DateRangePickerRootProps = { as: "section" };
|
||||
const trigger: DateRangePickerTriggerProps = {
|
||||
as: "button",
|
||||
asChild: false,
|
||||
isDisabled: true,
|
||||
};
|
||||
const indicator: DateRangePickerTriggerIndicatorProps = { as: "span" };
|
||||
const separator: DateRangePickerRangeSeparatorProps = {
|
||||
as: "span",
|
||||
children: " to ",
|
||||
};
|
||||
const popover: DateRangePickerPopoverProps = {
|
||||
placement: "bottom",
|
||||
offset: 12,
|
||||
crossOffset: 4,
|
||||
shouldFlip: true,
|
||||
containerPadding: 16,
|
||||
isDismissable: false,
|
||||
isKeyboardDismissDisabled: true,
|
||||
};
|
||||
const state: DateRangePickerState = {
|
||||
value: range,
|
||||
timeRange,
|
||||
setValue: (value) => {
|
||||
const next: DateRange | null = value;
|
||||
void next;
|
||||
},
|
||||
setTimeRange: (value) => {
|
||||
const next: DateRangePickerTimeRange | null = value;
|
||||
void next;
|
||||
},
|
||||
};
|
||||
const rendered: DateRangePickerRenderProps = {
|
||||
value: range,
|
||||
isOpen: true,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isRequired: false,
|
||||
isInvalid: false,
|
||||
isFocusWithin: false,
|
||||
isFocused: false,
|
||||
isFocusVisible: false,
|
||||
validationErrors: [],
|
||||
timeRange,
|
||||
state,
|
||||
open: () => {},
|
||||
close: () => {},
|
||||
toggle: () => {},
|
||||
};
|
||||
const endpoint: DateFieldInputProps = {
|
||||
endpoint: "start",
|
||||
as: "div",
|
||||
};
|
||||
const endEndpoint: DateFieldInputProps = { endpoint: "end" };
|
||||
// @ts-expect-error a range is required, not a single date
|
||||
const singleDate: DateRangePickerProps = { modelValue: day };
|
||||
// @ts-expect-error visible granularity has a fixed set
|
||||
const wrongGranularity: DateRangePickerProps = { granularity: "week" };
|
||||
// @ts-expect-error hour cycles are 12 or 24
|
||||
const wrongCycle: DateRangePickerProps = { hourCycle: 23 };
|
||||
// @ts-expect-error open state is boolean
|
||||
const wrongOpen: DateRangePickerProps = { open: "yes" };
|
||||
// @ts-expect-error names are strings
|
||||
const wrongName: DateRangePickerProps = { startName: 1 };
|
||||
// @ts-expect-error the non-contiguous policy is boolean
|
||||
const wrongPolicy: DateRangePickerProps = { allowsNonContiguousRanges: "yes" };
|
||||
// @ts-expect-error placement is a known logical value
|
||||
const wrongPlacement: DateRangePickerPopoverProps = { placement: "diagonal" };
|
||||
// @ts-expect-error endpoints are start or end
|
||||
const wrongEndpoint: DateFieldInputProps = { endpoint: "middle" };
|
||||
type Slot = Parameters<
|
||||
NonNullable<InstanceType<typeof DateRangePicker>["$slots"]["default"]>
|
||||
>[0];
|
||||
const slot: Slot = rendered;
|
||||
const slotTime: DateRangePickerTimeRange | null = slot.state.timeRange;
|
||||
// @ts-expect-error slot time is not a number
|
||||
const wrongSlotTime: number = slot.timeRange;
|
||||
void [
|
||||
DateRangePicker,
|
||||
DateRangePickerRoot,
|
||||
DateRangePickerTrigger,
|
||||
DateRangePickerTriggerIndicator,
|
||||
DateRangePickerRangeSeparator,
|
||||
DateRangePickerPopover,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldInputContainer,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
RangeCalendar,
|
||||
dateRangePickerVariants().base(),
|
||||
dateRangePickerVariants().trigger(),
|
||||
dateRangePickerVariants().triggerIndicator(),
|
||||
dateRangePickerVariants().rangeSeparator(),
|
||||
dateRangePickerVariants().popover(),
|
||||
values,
|
||||
root,
|
||||
trigger,
|
||||
indicator,
|
||||
separator,
|
||||
popover,
|
||||
state,
|
||||
rendered,
|
||||
endpoint,
|
||||
endEndpoint,
|
||||
singleDate,
|
||||
wrongGranularity,
|
||||
wrongCycle,
|
||||
wrongOpen,
|
||||
wrongName,
|
||||
wrongPolicy,
|
||||
wrongPlacement,
|
||||
wrongEndpoint,
|
||||
slotTime,
|
||||
wrongSlotTime,
|
||||
];
|
||||
h(DateRangePickerPopover, popover);
|
||||
Reference in New Issue
Block a user