diff --git a/apps/docs/.vitepress/theme/navigation.ts b/apps/docs/.vitepress/theme/navigation.ts index 035ab1e..7cb6346 100644 --- a/apps/docs/.vitepress/theme/navigation.ts +++ b/apps/docs/.vitepress/theme/navigation.ts @@ -95,6 +95,11 @@ export const componentItems: DocsItem[] = [ url: "/components/color-area", category: "colors", }, + { + title: "ColorSlider 颜色滑块", + url: "/components/color-slider", + category: "colors", + }, { title: "ColorSwatch 颜色色块", url: "/components/color-swatch", diff --git a/apps/docs/components/color-slider.md b/apps/docs/components/color-slider.md new file mode 100644 index 0000000..a6d3678 --- /dev/null +++ b/apps/docs/components/color-slider.md @@ -0,0 +1,284 @@ +--- +title: ColorSlider 颜色滑块 +description: 颜色滑块允许用户调整颜色值的单个通道 +component: color-slider +group: 组件 +--- + +## 用法 + +```vue + + + + + 色相 + + + + + + +``` + + + +## 组件结构 + +Vue 版使用具名部件:`ColorSlider` 负责共享颜色状态、通道解析与指针/键盘事务,`ColorSliderOutput` 显示格式化后的通道值,`ColorSliderTrack` 绘制渐变并在轨道上捕获指针,`ColorSliderThumb` 负责滑块定位和一个真正提交的原生 `range` 输入。`ColorSliderRoot` 是 `ColorSlider` 的别名。 + +```vue + + + + + 色相 + + + + + + +``` + +`Label` 通过字段上下文把可访问名称关联到原生输入;`ColorSliderOutput` 使用 `` 指向同一个输入。`ColorSliderTrack` 和 `ColorSliderThumb` 必须位于 `ColorSlider` 内,`ColorSliderThumb` 必须位于 `ColorSliderTrack` 内,否则会抛出明确的上下文错误。省略 `ColorSliderThumb` 时没有原生输入;省略 `ColorSliderTrack` 时没有指针轨道,但输出和标签仍会渲染。 + +## 示例 + +### 禁用 + + + +### 垂直方向 + + + +### 受控组件 + +使用 `v-model` 绑定本库 `Color` 或颜色字符串;色块与滑块共享同一个接受值。 + + + +### HSL 通道 + +使用多个 ColorSlider 控制颜色值的不同通道。滑块可共享同一颜色值以构建完整颜色选择器。 + + + +### 透明度通道 + +Alpha 通道滑块显示透明棋盘格图案,帮助可视化透明度级别。 + + + +### RGB 通道 + +也可使用 RGB 颜色空间的红、绿、蓝通道。 + + + +### 渲染函数 + +上游 `render` 用于替换根元素:Vue 版使用 `as` 更换标签,或用 `asChild` 把滑块属性合并到默认插槽中唯一的自定义根元素。`ColorSliderOutput`、`ColorSliderTrack` 与 `ColorSliderThumb` 使用 `as` 更换标签;`data-*`、ARIA、事件、`class` 与 `style` 直接透传。 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 ColorSlider 组件类。 +[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。 + +```css +@layer components { + .hv-color-slider { + @apply flex flex-col gap-2; + } + + .hv-color-slider__output { + @apply text-muted text-sm; + } + + .hv-color-slider__track { + @apply relative h-5 w-full rounded-full; + } + + .hv-color-slider__thumb { + @apply size-4 rounded-full border-3 border-white shadow-overlay; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +ColorSlider 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/color-slider.css)): + +#### 基础类 [!toc] + +- `.hv-color-slider` - 基础滑块容器 +- `.hv-color-slider__output` - 显示当前值的输出元素 +- `.hv-color-slider__track` - 带颜色渐变的轨道元素 +- `.hv-color-slider__thumb` - 显示当前颜色的滑块元素 + +#### 状态类 [!toc] + +- `.hv-color-slider[data-disabled="true"]` - 禁用滑块状态 +- `.hv-color-slider[data-orientation="vertical"]` - 垂直方向 +- `.hv-color-slider__thumb[data-dragging="true"]` - 滑块正在拖拽 +- `.hv-color-slider__thumb[data-focus-visible="true"]` - 滑块键盘聚焦 +- `.hv-color-slider__thumb[data-disabled="true"]` - 禁用滑块状态 +- `.hv-color-slider[data-readonly="true"]` / `.hv-color-slider__thumb[data-readonly="true"]` - 本库扩展的只读状态 + +轨道通过行内自定义属性提供两端颜色:`--track-start-color` 与 `--track-end-color`,供 `::before`/`::after` 端帽使用;轨道背景同时包含渐变和透明棋盘格。传入的 `style` 与 `styleFn` 在基础样式之后合并,可覆盖冲突属性。 + +### 交互状态 + +组件同时支持 CSS 伪类与 data 属性: + +- **Hover**:滑块上的 `:hover` 或 `[data-hovered="true"]` +- **Focus**:滑块上的 `:focus-visible` 或 `[data-focus-visible="true"]` +- **Dragging**:滑块上的 `[data-dragging="true"]` +- **Disabled**:滑块或 thumb 上的 `:disabled` 或 `[data-disabled="true"]` + +## API 参考 + +### ColorSlider + +| Prop / 事件 | 类型 | 默认值 | 描述 | +| ------------------------- | --------------------------------------------- | -------------------------- | ----------------------------------------------------------------------------------- | +| `channel` | `ColorChannel` | -(必填) | 滑块操作的颜色通道:hue、saturation、lightness、brightness、alpha、red、green、blue | +| `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | 接受值自身的颜色空间 | 通道使用的颜色空间;与 `channel` 组成受约束的联合类型 | +| `v-model` (`modelValue`) | `string \| Color \| null` | - | 当前颜色(受控);更新时触发 `update:modelValue` | +| `value` | `string \| Color \| null` | - | `modelValue` 的低优先级别名;与共享颜色模型一致 | +| `defaultValue` | `string \| Color \| null` | - | 非受控初始值 | +| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | 滑块方向 | +| `name` | `string` | - | 原生输入的表单名称;提交该通道的数值 | +| `form` | `string` | - | 关联的外部 `form` id | +| `isDisabled` / `disabled` | `boolean` | `false` | 是否禁用;`disabled` 为别名 | +| `isReadOnly` | `boolean` | `false` | 本库扩展:阻止编辑但保留焦点和 Tab 顺序 | +| `locale` | `string` | `ConfigProvider` / `en-US` | 输出与原生输入值文本的格式化语言 | +| `dir` | `"ltr" \| "rtl"` | `ConfigProvider` / `ltr` | 布局方向;影响水平坐标、渐变方向与方向键 | +| `id` | `string` | 自动生成 | 赋给真实原生 `range` 输入的 id | +| `as` | `string` | `"div"` | 自定义根元素标签;对应上游 `render` 的元素替换 | +| `asChild` | `boolean` | `false` | 将滑块属性合并到默认插槽中唯一的自定义根元素 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| `style` | `StyleValue \| ((renderProps) => StyleValue)` | - | 行内样式或上游 style render prop;在组件基础样式之后合并 | +| `styleFn` | `(renderProps) => StyleValue` | - | 模板中的 style 函数别名;在基础样式和 `style` 之后合并 | +| `@update:modelValue` | `(color: Color \| null) => void` | - | 提出颜色更新;供 `v-model` 使用 | +| `@change` | `(color: Color \| null) => void` | - | 提出不同于当前接受值的颜色时触发;受控父级可拒绝 | +| `@changeEnd` | `(color: Color \| null) => void` | - | 手势、键盘交互或失焦结束时触发一次;参数是最后一次提案 | +| 默认插槽 | `(renderProps) => VNodeChild` | - | 滑块内容;插槽参数为 `ColorSliderRenderProps` | + +`ColorSlider` 需要一个可用的颜色:提供 `modelValue`/`value` 或 `defaultValue`,或者省略全部自身值属性并置于最近的公共颜色 owner 内。固定源在没有值或默认值时会报错,本库沿用该要求并补充 owner 继承;显式 `null` 不是“清空颜色”,而是按缺少值处理,有 `defaultValue` 时使用默认值。空字符串和无效颜色按 `parseColor` 边界抛出 `RangeError`。 + +`channel` 与 `colorSpace` 应按固定源组成合法组合:`red`/`green`/`blue` 要求 `rgb`,`lightness` 要求 `hsl`,`brightness` 要求 `hsb`,`hue`/`saturation` 不适用于 `rgb`,`alpha` 可用于任意空间。发布的 `ColorSliderProps` 联合类型会拒绝非法组合;SFC 运行时对显式冲突的空间发出开发期警告并自动纠正,`hue`/`saturation` + `rgb` 会转为 `hsl`。 + +`changeEnd` 只在本次事务确有颜色更新提案时触发(不要求受控父级接受),回调参数是最后一次提案。受控父级拒绝提案时,原生值、输出、滑块位置和梯度保持接受值,同一手势可以再次提案;取消指针、`lostpointercapture`、窗口失焦、禁用/只读切换、通道/空间/方向变化、外部颜色替换和卸载只终止本控件事务,不取消兄弟控件的拖动。 + +### ColorSliderOutput + +Vue 版写作 `ColorSliderOutput`(对应上游 `ColorSlider.Output`)。 + +| Prop / 插槽 | 类型 | 默认值 | 描述 | +| --------------- | --------------------------------------------- | ---------- | ---------------------------------------------------- | +| `as` | `string` | `"output"` | 自定义输出标签;对应上游 `render` 的元素替换 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| `style` | `StyleValue \| ((renderProps) => StyleValue)` | - | 行内样式或上游 style render prop;在基础样式之后合并 | +| `styleFn` | `(renderProps) => StyleValue` | - | 模板中的 style 函数别名 | +| `data-*` / ARIA | 原生属性 | - | 透传到输出根元素 | +| 默认插槽 | `(renderProps) => VNodeChild` | - | 自定义输出;参数为 `ColorSliderOutputRenderProps` | + +未提供插槽时显示默认通道值(例如 `200°`、`50%`、`255`)。输出元素通过 `for` 关联真实原生输入;数值格式与 `aria-valuetext` 使用同一 locale。 + +### ColorSliderTrack + +Vue 版写作 `ColorSliderTrack`(对应上游 `ColorSlider.Track`)。 + +| Prop / 插槽 | 类型 | 默认值 | 描述 | +| --------------- | --------------------------------------------- | ------- | ---------------------------------------------------- | +| `as` | `string` | `"div"` | 自定义轨道标签;对应上游 `render` 的元素替换 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| `style` | `StyleValue \| ((renderProps) => StyleValue)` | - | 行内样式或上游 style render prop;在基础样式之后合并 | +| `styleFn` | `(renderProps) => StyleValue` | - | 模板中的 style 函数别名 | +| `data-*` / ARIA | 原生属性 | - | 透传到轨道根元素 | +| 默认插槽 | `(renderProps) => VNodeChild` | - | 轨道内容;参数为 `ColorSliderTrackRenderProps` | + +轨道是稳定捕获指针的节点:点击轨道立即定位,拖动滑块时保留抓取偏移,越界拖动按通道范围夹限。`percent` 是接受值在 0–1 内容盒中的位置,已排除边框并按祖先缩放换算;RTL 只翻转水平方向。 + +### ColorSliderThumb + +Vue 版写作 `ColorSliderThumb`(对应上游 `ColorSlider.Thumb`)。 + +| Prop / 插槽 | 类型 | 默认值 | 描述 | +| --------------- | --------------------------------------------- | ------- | ---------------------------------------------------- | +| `as` | `string` | `"div"` | 自定义滑块标签;对应上游 `render` 的元素替换 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | +| `style` | `StyleValue \| ((renderProps) => StyleValue)` | - | 行内样式或上游 style render prop;在基础样式之后合并 | +| `styleFn` | `(renderProps) => StyleValue` | - | 模板中的 style 函数别名 | +| `data-*` / ARIA | 原生属性 | - | 透传到滑块根元素 | +| 默认插槽 | `(renderProps) => VNodeChild` | - | 滑块内容;参数为 `ColorSliderThumbRenderProps` | + +滑块内包含真正的原生 `range` 输入:它进入 Tab 顺序、承担焦点与表单提交,并提供本地化名称、范围、方向和值文本。组件不使用一个虚构的 `aria-valuenow` 包装替代它。滑块的 `data-focus-visible` 与实际原生输入焦点同步,禁用时使用默认背景色而不绘制通道颜色。 + +### Render Props + +使用插槽参数或 style 函数时,提供以下值: + +| Prop | 类型 | 描述 | +| ------------- | ---------------------------- | ---------------------------------------------- | +| `color` | `Color` | 当前通道所在空间的显示颜色 | +| `channel` | `ColorChannel` | 当前颜色通道 | +| `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | 实际用于解释通道的颜色空间(已按合法组合纠正) | +| `orientation` | `"horizontal" \| "vertical"` | 滑块方向 | +| `isDisabled` | `boolean` | 是否禁用 | +| `isReadOnly` | `boolean` | 是否只读(本库扩展) | +| `value` | `number` | 输出部件的接受通道值;alpha 为 0–1 | +| `label` | `string` | 输出部件的本地化格式化值 | +| `percent` | `number` | 轨道/滑块的 0–1 接受位置 | +| `isDragging` | `boolean` | 滑块部件是否正在拖动 | + +`ColorSliderRenderProps` 是根插槽与根 style 函数的基础类型;输出、轨道与滑块分别扩展为 `ColorSliderOutputRenderProps`、`ColorSliderTrackRenderProps` 与 `ColorSliderThumbRenderProps`。根实例通过 `defineExpose` 公开 `element`(实际根 DOM)、`color`(当前接受值)与 `focus()`。 + +### 包根导出 + +`ColorSlider`、`ColorSliderRoot`、`ColorSliderOutput`、`ColorSliderTrack`、`ColorSliderThumb`、`colorSliderVariants`、`ColorSliderVariants`,以及上述 Props/插槽/样式/实例类型与通道别名(`HSLChannel` 等)均从 `@heroui-vue/components` 导出。`ColorSlider` 与 `ColorSliderRoot` 是同一个组件。 + +## 无障碍 + +ColorSlider 实现 ARIA slider 模式,提供: + +- 完整键盘导航:方向键、Shift + 方向键、Home、End、Page Up/Down;水平方向遵循 RTL +- 值变化的屏幕阅读器播报(原生 `range` 与 `aria-valuetext`) +- 焦点通过真实原生输入进入,滑块显示可见焦点环 +- 禁用状态与只读状态 +- 通过原生输入集成 HTML 表单提交与 reset +- locale 感知的值格式化;`ConfigProvider` 的 `locale`/`dir` 生效 + +## 相关组件 + +本批次公开 ColorArea、ColorSwatch 与 ColorSlider。ColorField、ColorInputGroup、ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。 diff --git a/apps/docs/demos/color-slider-alpha-channel.vue b/apps/docs/demos/color-slider-alpha-channel.vue new file mode 100644 index 0000000..0b9151a --- /dev/null +++ b/apps/docs/demos/color-slider-alpha-channel.vue @@ -0,0 +1,23 @@ + + + + + 透明度 + + + + + + diff --git a/apps/docs/demos/color-slider-basic.vue b/apps/docs/demos/color-slider-basic.vue new file mode 100644 index 0000000..e2a9546 --- /dev/null +++ b/apps/docs/demos/color-slider-basic.vue @@ -0,0 +1,23 @@ + + + + + 色相 + + + + + + diff --git a/apps/docs/demos/color-slider-channels.vue b/apps/docs/demos/color-slider-channels.vue new file mode 100644 index 0000000..6a7f1b5 --- /dev/null +++ b/apps/docs/demos/color-slider-channels.vue @@ -0,0 +1,50 @@ + + + + + + 色相 + + + + + + + 饱和度 + + + + + + + 明度 + + + + + + + + + 当前颜色: + + {{ color ? color.toString("hsl") : "(empty)" }} + + + + + diff --git a/apps/docs/demos/color-slider-controlled.vue b/apps/docs/demos/color-slider-controlled.vue new file mode 100644 index 0000000..52addb3 --- /dev/null +++ b/apps/docs/demos/color-slider-controlled.vue @@ -0,0 +1,36 @@ + + + + + + 色相 + + + + + + + + + 当前颜色: + + {{ color ? color.toString("hsl") : "(empty)" }} + + + + + diff --git a/apps/docs/demos/color-slider-custom-styles.vue b/apps/docs/demos/color-slider-custom-styles.vue new file mode 100644 index 0000000..f2fb4f7 --- /dev/null +++ b/apps/docs/demos/color-slider-custom-styles.vue @@ -0,0 +1,27 @@ + + + + + 色相 + + + + + + diff --git a/apps/docs/demos/color-slider-disabled.vue b/apps/docs/demos/color-slider-disabled.vue new file mode 100644 index 0000000..0c00f6d --- /dev/null +++ b/apps/docs/demos/color-slider-disabled.vue @@ -0,0 +1,24 @@ + + + + + 色相 + + + + + + diff --git a/apps/docs/demos/color-slider-render-function.vue b/apps/docs/demos/color-slider-render-function.vue new file mode 100644 index 0000000..4cb7555 --- /dev/null +++ b/apps/docs/demos/color-slider-render-function.vue @@ -0,0 +1,26 @@ + + + + + + 色相 + + + + + + + diff --git a/apps/docs/demos/color-slider-rgb-channels.vue b/apps/docs/demos/color-slider-rgb-channels.vue new file mode 100644 index 0000000..f2530bb --- /dev/null +++ b/apps/docs/demos/color-slider-rgb-channels.vue @@ -0,0 +1,50 @@ + + + + + + 红 + + + + + + + 绿 + + + + + + + 蓝 + + + + + + + + + 当前颜色: + + {{ color ? color.toString("rgb") : "(empty)" }} + + + + + diff --git a/apps/docs/demos/color-slider-vertical.vue b/apps/docs/demos/color-slider-vertical.vue new file mode 100644 index 0000000..07b1679 --- /dev/null +++ b/apps/docs/demos/color-slider-vertical.vue @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/compatibility.md b/docs/compatibility.md index 4d63e05..19049d0 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -4,91 +4,91 @@ 固定上游公共组件清单;状态、差异和验证范围逐组件记录,不以单项测试通过声明整库完整兼容。 -| 组件 | 状态 | 当前能力 / 差异 | -| -------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 | -| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 | -| autocomplete | 已迁移(有已知差异) | Autocomplete 七部件;24/24 基线例;触发器单一 Tab 入口 + 弹层内搜索框虚拟焦点、受控开关/文本、多选 Value 用作用域插槽;见 B02 报告 | -| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 | -| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group | -| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 | -| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link | -| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 | -| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 | -| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 | -| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 | -| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 | -| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 | -| color-area | 已迁移(客户端) | ColorArea/ColorAreaRoot、ColorAreaThumb;showDots、colorSpace/RGB/HSL/HSB 与 18 个有序轴组合、共享 owner、受控拒绝、原生两轴提交/reset、locale/RTL、readOnly;7/7 基线例;Root render 映射 as/asChild,Thumb 映射 as,style 函数映射 styleFn;见 COLOR-AREA 结果 | -| color-field | 私有组合协议已验证 | Root/Input及InputGroup前后缀、校验/关联、locale/草稿/IME/reset已验证;未公开包根、variants或正式13例,见COLOR-06。 | -| color-picker | 私有组合协议已验证 | Picker/Trigger/Popover共享owner、字段/轨道联动与单一提交/reset已验证;未公开包根、variants或正式6例,见COLOR-08。 | -| color-slider | 私有轨道已验证 | 自定义轨道、指针捕获/取消、键盘/方向/渐变及共享owner已验证;未公开Slider家族及正式文档,见COLOR-04。 | -| color-swatch | 已迁移(客户端) | ColorSwatch/ColorSwatchRoot、circle/square、xs–xl、透明棋盘;7/7 基线例;省略 color 继承最近共享 owner,显式值覆盖;公开 Color/parseColor 子集;render 映射 as/asChild,style 函数映射 styleFn;见 COLOR-SWATCH 结果 | -| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 | -| 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 | 已迁移(客户端,有已知差异) | 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 共用取值语义 | -| time-field | 已迁移(客户端) | TimeField/Root及六个共享输入部件;15/15基线例;Time/CalendarDateTime/ZonedDateTime、完整精度、受控拒绝、键盘/Enter、校验/提交/reset;框架差异见 TIME-FIELD 结果。 | -| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 | -| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 | -| error-message | 已迁移(有已知差异) | ErrorMessage 单部件;2/2 基线例;复用字段错误 id 与样式变量,`slot="errorMessage"` 仅为 DOM 标记,不做校验也不改 aria-invalid;见 B03 报告 | -| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap | -| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 | -| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 | -| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 | -| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator | -| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 | -| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 | -| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface | -| toast | 验证中(M35 + 保真返修) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;role=alertdialog + 标题/描述关联 + content role=alert;indicator data-swapped;自有计时(无双倒计时);getQueue 不提供,见文档差异 | -| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 | -| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 | -| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS | -| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 | -| tag | 已迁移(有已知差异) | Tag/TagRemoveButton;与 TagGroup 同页 12 例;textValue 决定文字与移除按钮名称 `Remove tag {文本}`;移除由行统一处理;见 B03 报告 | -| tag-group | 已迁移(有已知差异) | TagGroup/TagGroupList 两部件;role=grid/row、single/multiple、disabledKeys、移除与焦点恢复、aria-labelledby/describedby;12/12 基线例;见 B03 报告 | -| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set | -| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 | -| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 | -| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 | -| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 | -| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl | -| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) | -| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 | -| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as | -| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 | -| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 | -| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 | -| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) | -| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 | -| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 | -| header | 验证中(M31) | Header/HeaderRoot;原生 `` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model | -| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 | -| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 | -| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 | -| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default | -| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 | -| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 | -| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 | -| dropdown | 验证中(B01) | Root/Trigger/Popover/Menu/Section/Item/ItemIndicator/SubmenuIndicator/SubmenuTrigger;17/17 基线例;Reka DropdownMenu;数组选择模型 | -| menu | 验证中(B01) | MenuRoot/Menu 列表与选择/动作上下文;无独立官方文档页,契约折叠于 Dropdown;见 B01 | -| menu-item | 验证中(B01) | MenuItem/Indicator/SubmenuIndicator;variant default/danger、checkmark/dot;见 B01 | -| menu-section | 验证中(B01) | MenuSection 分组与分组级选择;见 B01 | -| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot | -| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 | -| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 | -| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 | -| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress | -| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 | -| table | 验证中(M36 + 保真返修) | 15 部件;选择/排序/原生语义;13 演示;TableBody `#empty` 空状态;全选半选;defaultWidth 的 1fr 按原生 auto 弹性适配,不承诺 fr 比例;虚拟化固定 42px 窗口、TanStack 分页行模型;RAC TableLayout 不导出,见 M36 | -| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 | -| range-calendar | 已迁移(客户端,有已知差异) | RangeCalendar/Root、九个具名日历部件、共享六个 CalendarYearPicker 部件;20/20 基线例;点击/键盘/鼠标拖选、受控拒绝、跨月/RTL;触屏长按拖选未实现,见 RANGE-CALENDAR 结果。 | -| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 | +| 组件 | 状态 | 当前能力 / 差异 | +| -------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 | +| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 | +| autocomplete | 已迁移(有已知差异) | Autocomplete 七部件;24/24 基线例;触发器单一 Tab 入口 + 弹层内搜索框虚拟焦点、受控开关/文本、多选 Value 用作用域插槽;见 B02 报告 | +| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 | +| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group | +| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 | +| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link | +| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 | +| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 | +| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 | +| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 | +| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 | +| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 | +| color-area | 已迁移(客户端) | ColorArea/ColorAreaRoot、ColorAreaThumb;showDots、colorSpace/RGB/HSL/HSB 与 18 个有序轴组合、共享 owner、受控拒绝、原生两轴提交/reset、locale/RTL、readOnly;7/7 基线例;Root render 映射 as/asChild,Thumb 映射 as,style 函数映射 styleFn;见 COLOR-AREA 结果 | +| color-field | 私有组合协议已验证 | Root/Input及InputGroup前后缀、校验/关联、locale/草稿/IME/reset已验证;未公开包根、variants或正式13例,见COLOR-06。 | +| color-picker | 私有组合协议已验证 | Picker/Trigger/Popover共享owner、字段/轨道联动与单一提交/reset已验证;未公开包根、variants或正式6例,见COLOR-08。 | +| color-slider | 已迁移(客户端) | ColorSlider/ColorSliderRoot、ColorSliderOutput/Track/Thumb;channel×colorSpace 联合类型与运行时纠正、共享 owner/受控拒绝、原生 range 提交/reset、键盘/RTL/垂直、alpha/RGB/HSL/HSB;9/9 基线例;Root render 映射 as/asChild,部件映射 as,style 函数映射 styleFn;见 COLOR-SLIDER 结果 | +| color-swatch | 已迁移(客户端) | ColorSwatch/ColorSwatchRoot、circle/square、xs–xl、透明棋盘;7/7 基线例;省略 color 继承最近共享 owner,显式值覆盖;公开 Color/parseColor 子集;render 映射 as/asChild,style 函数映射 styleFn;见 COLOR-SWATCH 结果 | +| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 | +| 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 | 已迁移(客户端,有已知差异) | 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 共用取值语义 | +| time-field | 已迁移(客户端) | TimeField/Root及六个共享输入部件;15/15基线例;Time/CalendarDateTime/ZonedDateTime、完整精度、受控拒绝、键盘/Enter、校验/提交/reset;框架差异见 TIME-FIELD 结果。 | +| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 | +| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 | +| error-message | 已迁移(有已知差异) | ErrorMessage 单部件;2/2 基线例;复用字段错误 id 与样式变量,`slot="errorMessage"` 仅为 DOM 标记,不做校验也不改 aria-invalid;见 B03 报告 | +| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap | +| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 | +| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 | +| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 | +| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator | +| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 | +| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 | +| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface | +| toast | 验证中(M35 + 保真返修) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;role=alertdialog + 标题/描述关联 + content role=alert;indicator data-swapped;自有计时(无双倒计时);getQueue 不提供,见文档差异 | +| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 | +| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 | +| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS | +| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 | +| tag | 已迁移(有已知差异) | Tag/TagRemoveButton;与 TagGroup 同页 12 例;textValue 决定文字与移除按钮名称 `Remove tag {文本}`;移除由行统一处理;见 B03 报告 | +| tag-group | 已迁移(有已知差异) | TagGroup/TagGroupList 两部件;role=grid/row、single/multiple、disabledKeys、移除与焦点恢复、aria-labelledby/describedby;12/12 基线例;见 B03 报告 | +| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set | +| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 | +| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 | +| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 | +| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 | +| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl | +| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) | +| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 | +| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as | +| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 | +| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 | +| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 | +| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) | +| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 | +| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 | +| header | 验证中(M31) | Header/HeaderRoot;原生 `` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model | +| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 | +| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 | +| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 | +| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default | +| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 | +| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 | +| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 | +| dropdown | 验证中(B01) | Root/Trigger/Popover/Menu/Section/Item/ItemIndicator/SubmenuIndicator/SubmenuTrigger;17/17 基线例;Reka DropdownMenu;数组选择模型 | +| menu | 验证中(B01) | MenuRoot/Menu 列表与选择/动作上下文;无独立官方文档页,契约折叠于 Dropdown;见 B01 | +| menu-item | 验证中(B01) | MenuItem/Indicator/SubmenuIndicator;variant default/danger、checkmark/dot;见 B01 | +| menu-section | 验证中(B01) | MenuSection 分组与分组级选择;见 B01 | +| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot | +| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 | +| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 | +| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 | +| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress | +| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 | +| table | 验证中(M36 + 保真返修) | 15 部件;选择/排序/原生语义;13 演示;TableBody `#empty` 空状态;全选半选;defaultWidth 的 1fr 按原生 auto 弹性适配,不承诺 fr 比例;虚拟化固定 42px 窗口、TanStack 分页行模型;RAC TableLayout 不导出,见 M36 | +| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 | +| range-calendar | 已迁移(客户端,有已知差异) | RangeCalendar/Root、九个具名日历部件、共享六个 CalendarYearPicker 部件;20/20 基线例;点击/键盘/鼠标拖选、受控拒绝、跨月/RTL;触屏长按拖选未实现,见 RANGE-CALENDAR 结果。 | +| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 | ## 公共导出差异 @@ -227,7 +227,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式 ## COLOR-03 颜色输入基建 -共享通道解析、原生 range 事务及文本草稿/IME/locale/校验/reset 已由私有夹具验证,没有公开 ColorSlider/Field/InputGroup/Picker。自定义轨道、正式字段提交格式和 Picker 组合仍待接续;准确范围见 [COLOR-03](component-notes.md)。 +共享通道解析、原生 range 事务及文本草稿/IME/locale/校验/reset 已由私有夹具验证,没有公开 ColorSlider/Field/InputGroup/Picker。自定义轨道、正式字段提交格式和 Picker 组合仍待接续;准确范围见 [COLOR-03](component-notes.md)。其中 ColorSlider 已由 [COLOR-SLIDER 结果](tasks/results/COLOR-SLIDER.md) 公开,Field/InputGroup/Picker 仍为私有。 ## COLOR-04 颜色轨道与 Picker 组合 @@ -247,6 +247,12 @@ ColorPicker/Trigger/Popover 正式组合内部已接入,共享非空 owner、 上游 render 映射为 `as`/`asChild` 与 attrs,style 函数在模板中使用 `styleFn`;`xName`/`yName`/`form` 只提交两个轴,继承 owner 时不重复完整颜色提交。固定源默认 `#ffffff`、按接受值空间推断轴;默认指针捕获与 mouse/touch 手势、受控拒绝/重试、动态 owner、表单/reset、浅深主题和最终 tarball 的验证边界见 [任务结果](tasks/results/COLOR-AREA.md)。 +## COLOR-SLIDER 公共颜色滑块(2026-10-27) + +公开 ColorSlider/ColorSliderRoot、ColorSliderOutput、ColorSliderTrack、ColorSliderThumb、Props/RenderProps/插槽/样式/实例类型与 colorSliderVariants;固定源中文 9 例、API/样式参考与导航已接入。复用共享 Color/model 接受值、私有通道解析、原生 range 事务、轨道几何与既有 hv-color-slider CSS;发布 Props 以 channel×colorSpace 联合类型拒绝非法组合,运行时对显式冲突发出开发期警告并纠正。 + +固定源在没有值或默认值时报错;本库沿用该要求,并允许省略全部自身值属性时继承最近颜色 owner。原生 range 提交通道数值(alpha 为 0–1)并支持 reset;受控拒绝保持原生值/输出/滑块/梯度,取消、禁用、卸载与外部替换不伪造 `changeEnd`。Root render 映射 `as`/`asChild`,部件映射 `as`,style 函数映射 `styleFn`。指针/键盘、动态 owner、表单/reset、浅深主题与最终 tarball 证据见 [任务结果](tasks/results/COLOR-SLIDER.md)。 + ## B02 公开组合接手验收 ComboBox/Autocomplete的正式组合、原30项返修和本轮定位/ref/ARIA/locale修复已集成,独立浏览器消费已补验。精确范围与未验证项以 [B02-REVIEW结果](tasks/results/B02-REVIEW.md) 为准;历史“not actionable/未做浏览器产物”不再是当前结果。后续迁移从docs/tasks统一入口开始,不重复派发旧清单中的日期/颜色基建。 diff --git a/docs/component-notes.md b/docs/component-notes.md index 9dcd5d9..e4538f7 100644 --- a/docs/component-notes.md +++ b/docs/component-notes.md @@ -15,7 +15,7 @@ DateField/TimeField/Calendar/CalendarYearPicker已公开;RangeCalendar只有私有内核,DatePicker/DateRangePicker尚未迁移。保留DateValue、历法/时区与精度边界,不强制JS Date;本地化整日期粘贴、13月/era编辑等尚有待办。见 [日期决策](decisions/date-calendar-foundation.md)、[DateField文档](../apps/docs/components/date-field.md)、[Calendar文档](../apps/docs/components/calendar.md)。 -颜色共享 value/model、二维 Area、Slider、Field/InputGroup、Picker 私有协议与既有夹具已验证;ColorSwatch 与 ColorArea 已作为公共组件迁移,ColorField/ColorSlider/ColorPicker/ColorSwatchPicker 仍未公开。不能把内核/夹具通过写成整族完成。共享 owner、归一化通道、接受值与草稿保持同一状态源。ColorArea 按固定源运行时默认 `#ffffff` 与空间首通道推断轴,见 [颜色决策](decisions/color-foundation.md) 与 [COLOR-AREA 结果](tasks/results/COLOR-AREA.md)。 +颜色共享 value/model、二维 Area、Slider、Field/InputGroup、Picker 私有协议与既有夹具已验证;ColorSwatch、ColorArea 与 ColorSlider 已作为公共组件迁移,ColorField/ColorPicker/ColorSwatchPicker 仍未公开。不能把内核/夹具通过写成整族完成。共享 owner、归一化通道、接受值与草稿保持同一状态源。ColorArea 按固定源运行时默认 `#ffffff` 与空间首通道推断轴,见 [颜色决策](decisions/color-foundation.md) 与 [COLOR-AREA 结果](tasks/results/COLOR-AREA.md)。 ## COLOR-AREA(2026-10-26) @@ -23,6 +23,14 @@ ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复 上游 render 改 `as`/`asChild` 与 attrs;style 函数在模板中用 `styleFn`,Thumb 仅支持 `as`(无 asChild,避免把两个原生轴移出滑块)。`isReadOnly` 与 `disabled` 是保留的库扩展;`null` 清空接受值并按默认白绘制,空字符串按 parseColor 边界抛错。固定源 1.21.1 默认 `#ffffff`,默认轴取空间首两个通道(RGB red/green,HSL/HSB hue/saturation),与中文 API 简表标注的 saturation/brightness 不同;实现与文档以运行时行为为准。触屏拖出边界、lostcapture/pointercancel 清理真实浏览器已验证;CDP 合成鼠标不保持 pointer capture,鼠标捕获仅由单元夹具覆盖,未把它误记为浏览器通过。完整证据与限制见 [任务结果](tasks/results/COLOR-AREA.md)。 +## COLOR-SLIDER(2026-10-27) + +ColorSlider/ColorSliderRoot、ColorSliderOutput、ColorSliderTrack、ColorSliderThumb 与 colorSliderVariants 已公开,复用 hv-color-slider CSS 和共享通道/轨道内核;固定源中文 9 例全部迁移。Root 持有接受值与事务,Output 显示 locale 值并以 `for` 关联输入,Track 绘制渐变、棋盘和端帽并捕获指针,Thumb 定位并包含真实原生 `range`。 + +发布 `ColorSliderProps` 为 channel×colorSpace 判别联合;SFC 运行时对显式冲突发出开发期警告并纠正。固定源 `useColorSliderState` 在无值/默认值时抛错,本库沿用并补充“省略全部自身值属性时继承最近 owner”;显式 `null` 按缺少值处理,有 `defaultValue` 时使用它。`isReadOnly`、`disabled` 别名与 `data-readonly` 是保留扩展;显式 null 不是“清空颜色”。原生 input 提交 channel 数值(alpha 0–1)并支持 reset;继承子项不重复 owner 的完整颜色提交。根插槽/部件 style 函数的 render props、`as`/`asChild` 与 `styleFn` 映射、实际指针/键盘/表单/主题验证见 [任务结果](tasks/results/COLOR-SLIDER.md)。 + +Output 的动态默认值使用自身的 render 函数渲染,而不是组件 children 插槽,避免父级 slot 缓存导致接受值更新后文本滞留;自定义输出仍通过具名/作用域插槽提供相同的 render props。 + ## 当前不投入 SSR/水合/Nuxt集成不支持;逐像素自动对比、完整读屏矩阵、真机矩阵暂不投入,不开发相应工程或设为每次迁移门槛。仍保留固定基线的样式/布局/API/主题一致性,重点浏览器操作、键盘与基础可访问性检查。具体统一约定见根AGENTS.md。 diff --git a/docs/status.md b/docs/status.md index e49358f..3dfe34d 100644 --- a/docs/status.md +++ b/docs/status.md @@ -9,20 +9,20 @@ - 展示、按钮、导航、展开、反馈等主要家族已有公共组件与文档。 - 字段/Form、Checkbox/Radio、数值/Slider/OTP、弹层/菜单、集合/ListBox/Select、ComboBox/Autocomplete、Tag、Toast/Table已集成。 - DateField、TimeField、Calendar、CalendarYearPicker、DatePicker 与 DateRangePicker 已有公共组件;RangeCalendar 已完成公共客户端迁移(20 个基线预览),范围选择与 Calendar 共用视图/焦点/年份设施。DatePicker 复用 DateField 字段、Calendar 视图与 Popover 弹层,10 个基线预览已接入。DateRangePicker 复用双端点 DateField、RangeCalendar 与 Popover,10 个基线预览已接入。 -- ColorSwatch/ColorSwatchRoot及Color/parseColor公共子集已公开;ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复用共享颜色 owner、二维交互与固定源 7 例。Area、Slider、Field/InputGroup、Picker组合协议仍有私有实现和回归夹具;ColorField/ColorSlider/ColorPicker/ColorSwatchPicker尚未作为完整公共颜色家族发布。 -- 兼容矩阵目前85条(包含子部件与基础设施),文档有69个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。 +- ColorSwatch/ColorSwatchRoot及Color/parseColor公共子集已公开;ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复用共享颜色 owner、二维交互与固定源 7 例;ColorSlider/ColorSliderRoot、ColorSliderOutput/Track/Thumb 与 colorSliderVariants 已公开,复用共享通道/轨道内核与固定源 9 例。Field/InputGroup、Picker 组合协议仍有私有实现和回归夹具;ColorField/ColorPicker/ColorSwatchPicker尚未作为完整公共颜色家族发布。 +- 兼容矩阵目前85条(包含子部件与基础设施),文档有70个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。 ## 尚未完成的公共家族 -ColorField、ColorSlider、ColorSwatchPicker、ColorPicker,共4项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收。 +ColorField、ColorSwatchPicker、ColorPicker,共3项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收,ColorSlider 已随 COLOR-SLIDER 验收。 -TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md),COLOR-AREA 见 [结果](tasks/results/COLOR-AREA.md)。RANGE-CALENDAR 结果见 [任务结果](tasks/results/RANGE-CALENDAR.md)。DATE-RANGE-PICKER 结果见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。 +TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md),COLOR-AREA 见 [结果](tasks/results/COLOR-AREA.md),COLOR-SLIDER 见 [结果](tasks/results/COLOR-SLIDER.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)。当前客户端全量回归99文件/1445项通过;本轮ColorArea新增2文件/30项,任务定向12文件/173项通过;已通过独立复核并合入 main,结果见任务文件;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。 +已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归101文件/1485项通过;本轮ColorSlider新增2文件/40项,任务定向13文件/203项通过;待复核,结果见任务文件。ColorArea 已通过独立复核并合入 main;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。 ## 按需入口 diff --git a/docs/upstream.md b/docs/upstream.md index 6d25af1..a68268c 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -261,6 +261,14 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`showDots`、`hv-color-area`/` ColorArea 的 `xName`/`yName`/`form` 只生成两个原生 range 输入;共享 owner 的完整颜色提交仍归 owner,未在子项增加重复隐藏颜色或 reset 所有权。默认值、受控拒绝/重试、动态 owner、locale/RTL、readOnly 扩展、真实浏览器和 tarball 证据见 [任务结果](tasks/results/COLOR-AREA.md)。 +## COLOR-SLIDER ColorSlider(2026-10-27) + +固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/color-slider/{index.ts,color-slider.tsx}`、`packages/styles/components/color-slider.css`、`packages/styles/src/components/color-slider/color-slider.styles.ts`,中文 `(colors)/color-slider.mdx` 与 `demos/cn/color-slider` 全部 9 例(basic/disabled/vertical/controlled/channels/alpha-channel/rgb-channels/render-function/custom-styles)。 + +CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;既有端帽适配(合法双色标 + 透明棋盘)沿用 COLOR-04,未再次移植。Vue 侧复用 `components/color/{value,model,channel,native-channel,slider,slider-gradient,labels}.ts` 的不可变 Color、共享 owner、通道解析、原生 range 事务与轨道几何,不包装 React Aria。审计安装版 `react-stately@3.50.0` 的 `useColorSliderState`:无 `value`/`defaultValue` 时抛错,`getDisplayColor` 对 hue 使用全饱和显示色、alpha 保留透明度;未指定颜色空间时按通道推断。上游 `render` 映射为 `as`/`asChild`(Root)与 `as`(Output/Track/Thumb),style 函数在模板中使用 `styleFn`。 + +发布 `ColorSliderProps` 使用固定源的 channel/colorSpace 判别联合;SFC 对显式非法组合发出开发期警告并自动纠正(red/green/blue→rgb、lightness→hsl、brightness→hsb、hue/saturation+rgb→hsl)。单个原生 range 承担名称、范围、方向、值文本、表单提交与 reset;继承子项不重复 owner 的完整颜色提交。证据与差异见 [任务结果](tasks/results/COLOR-SLIDER.md)。 + ## TIME-FIELD(2026-10-26) 固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/time-field/{index.ts,time-field.tsx}`、共享 date-input-group、`packages/styles/components/time-field.css` 与 `packages/styles/src/components/time-field/time-field.styles.ts`,中文 `(date-and-time)/time-field.mdx` 和 `demos/cn/time-field` 全部15例。 diff --git a/docs/verification.md b/docs/verification.md index 6ea0dab..37bb316 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -72,3 +72,16 @@ Playground 5174 嵌套 Modal 场景:面板在 Modal 上方可见/可操作,E 真实文档 5173(Chrome,1280×900 CSS 视口):7 个预览顺序正确;基础/定位点/禁用 224×224,自定义 176×176、圆角 24px,Thumb 16px(拖动/自定义 20px);RGB screen 混合与 HSL/HSB 图层、showDots、当前色变量、浅深主题和焦点环均实际检查;实际点击色彩空间 Select 切到 RGB 后轴名称、255 上限与代码值同步。8px 边框 + `scale(1.2)` 的内容盒 249.6×249.6 点击映射与 Thumb 中心误差 <0.02px。触屏拖拽在区内/拖出边界均保持 pointer capture,pointerup 提交并清理;releasePointerCapture 后下一次指针事件取消拖动且不回写旧手势;pointercancel 清理且保留接受值;禁用区域触摸不改变值。键盘 ArrowRight/ArrowUp 更新对应轴、切换单 Tab 入口并显示 3px 焦点轮廓与焦点阴影;控制台无新增 warn/error。 CDP 合成鼠标事件本身不保持 pointer capture(中性 div 复现),因此鼠标区外拖动未作为浏览器通过证据,鼠标捕获仍由单元夹具的 `setPointerCapture` 断言覆盖;未开展 SSR/水合/Nuxt、逐像素、完整读屏或真机矩阵。详情见 [任务结果](tasks/results/COLOR-AREA.md)。 + +## COLOR-SLIDER(2026-10-27,客户端) + +公开 ColorSlider/ColorSliderRoot、ColorSliderOutput、ColorSliderTrack、ColorSliderThumb、colorSliderVariants、Props/RenderProps/插槽/样式/实例类型及通道别名;固定源中文 9 例全部迁移,预览/复制/高亮共用同一 SFC。新增 28 项公共行为测试与 12 项文档/示例测试;发布 Props 的 channel×colorSpace 判别联合、运行时纠正、共享 owner、原生 range 提交/reset、Output 自渲染与指针焦点抑制均有定向断言。 + +- `pnpm test`:101 文件/1485 项客户端回归通过。 +- 任务定向 13 文件/203 项通过:color-slider 两个新文件、color-slider-foundation、color-foundation、color-area、color-swatch、picker composition/protocol、input/field 基础及 regressions/color。 +- `pnpm typecheck`、`pnpm build:docs`:通过;文档构建保留已有大 chunk 提示,不是组件 SSR 验收。 +- `node scripts/check-package.mjs color-slider color-area color-swatch color-slider-foundation`:最终 tarball 独立安装、ESM/CSS/variants 与 strict NodeNext/bundler 类型正反例通过;声明不泄漏 Reka 类型;旧契约仅移除 ColorSlider 的“暂不公开”断言。 + +真实文档 5173(Chrome 155 headless,1280×900 CSS 视口,CDP 真实鼠标/触屏/键盘):9 个预览顺序正确;基础轨道 300×20、Thumb 16×16、3px 白边与 16px 圆角,标签/输出 14px,Output `for` 与 Label `for` 均指向真实 input,`aria-valuetext=0°`。鼠标点击轨道 25% 得到 90°、Thumb 25%、输入获得焦点;ArrowRight 91、Shift+ArrowRight 106(+15)、Home 0、End 360、PageDown 345;Escape 取消后保留 344。触屏按下时 pointerType=touch、capture=true、`data-dragging`,拖到 75% 得 270°,拖出右边界夹限 360°/100%,touchEnd 释放 capture,touchCancel 保留 216 并清理。禁用示例保持 200 且 input disabled、Thumb 使用默认背景。受控示例点击后 Output 90°、文本 `hsl(90, 100%, 50%)` 与色块同步;HSL 通道把饱和度降到 50% 后 `0°/50%/50%` 与 `hsl(0, 50%, 50%)` 同步;Alpha 轨道含棋盘、0.5→0.25 与 50%→25%;RGB 红色通道点击中点得到 128 与 `rgb(128, 100, 50)`。渲染函数根为自定义 DIV/`data-custom=foo` 且交互有效;自定义样式轨道 16px、Thumb 16px/4px 圆角、输出与标签类名合并。Tab 精确进入原生 input,`data-focus-visible=true` 且 Thumb 计算 outline 3px;浅/深主题标签、输出与背景色实际切换;页面 1280 无横向溢出;控制台无 warn/error。 + +临时 RTL/受控拒绝/表单页面(同一开发服务器,验后删除)实测:RTL 初始 Thumb `left:100%`、背景 `to left`,点击 25% 得 270°、ArrowRight 降至 269°;垂直 RTL 初始 `top:100%`,点击顶部 25% 得 270°/`top:25%`;受控父级忽略两次提案后 input/Output/Thumb 均保持 0;表单提交 `hue=90`,reset 后 input 与 Output 恢复 30°/30°。未开展 SSR/水合/Nuxt、逐像素、完整读屏或真机矩阵;详情见 [任务结果](tasks/results/COLOR-SLIDER.md)。 diff --git a/packages/styles/src/index.ts b/packages/styles/src/index.ts index 95d96b3..ab31fcb 100644 --- a/packages/styles/src/index.ts +++ b/packages/styles/src/index.ts @@ -1849,6 +1849,18 @@ export const colorAreaVariants = tv({ export type ColorAreaVariants = VariantProps; +/** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */ +export const colorSliderVariants = tv({ + slots: { + base: "hv-color-slider", + output: "hv-color-slider__output", + thumb: "hv-color-slider__thumb", + track: "hv-color-slider__track", + }, +}); + +export type ColorSliderVariants = VariantProps; + /** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */ export const timeFieldVariants = tv({ base: "hv-time-field", diff --git a/packages/vue/src/components/color-area/labels.ts b/packages/vue/src/components/color-area/labels.ts index fa25a05..9b733ee 100644 --- a/packages/vue/src/components/color-area/labels.ts +++ b/packages/vue/src/components/color-area/labels.ts @@ -1,34 +1,9 @@ -import type { ColorAxisChannel } from "../color/value"; - -const english: Record = { - red: "Red", - green: "Green", - blue: "Blue", - hue: "Hue", - saturation: "Saturation", - lightness: "Lightness", - brightness: "Brightness", -}; - -const chinese: Record = { - red: "红色", - green: "绿色", - blue: "蓝色", - hue: "色相", - saturation: "饱和度", - lightness: "亮度", - brightness: "明度", -}; +export { colorChannelLabel } from "../color/labels"; function isChinese(locale: string) { return locale.toLowerCase().startsWith("zh"); } -/** Localized native axis name; other locales fall back to the English term. */ -export function colorChannelLabel(channel: ColorAxisChannel, locale: string) { - return (isChinese(locale) ? chinese : english)[channel]; -} - /** Default group name used when the consumer does not supply a label. */ export function colorAreaLabel(locale: string) { return isChinese(locale) ? "颜色区域" : "Color area"; diff --git a/packages/vue/src/components/color-slider/ColorSlider.vue b/packages/vue/src/components/color-slider/ColorSlider.vue new file mode 100644 index 0000000..dd3d818 --- /dev/null +++ b/packages/vue/src/components/color-slider/ColorSlider.vue @@ -0,0 +1,340 @@ + + + + + + + diff --git a/packages/vue/src/components/color-slider/ColorSliderOutput.vue b/packages/vue/src/components/color-slider/ColorSliderOutput.vue new file mode 100644 index 0000000..64897e5 --- /dev/null +++ b/packages/vue/src/components/color-slider/ColorSliderOutput.vue @@ -0,0 +1,81 @@ + diff --git a/packages/vue/src/components/color-slider/ColorSliderThumb.vue b/packages/vue/src/components/color-slider/ColorSliderThumb.vue new file mode 100644 index 0000000..022a816 --- /dev/null +++ b/packages/vue/src/components/color-slider/ColorSliderThumb.vue @@ -0,0 +1,174 @@ + + + + + + + + diff --git a/packages/vue/src/components/color-slider/ColorSliderTrack.vue b/packages/vue/src/components/color-slider/ColorSliderTrack.vue new file mode 100644 index 0000000..4d06f8d --- /dev/null +++ b/packages/vue/src/components/color-slider/ColorSliderTrack.vue @@ -0,0 +1,122 @@ + + + + + + + diff --git a/packages/vue/src/components/color-slider/context.ts b/packages/vue/src/components/color-slider/context.ts new file mode 100644 index 0000000..90bcef0 --- /dev/null +++ b/packages/vue/src/components/color-slider/context.ts @@ -0,0 +1,55 @@ +import { + inject, + type ComputedRef, + type InjectionKey, + type Ref, + type ShallowRef, +} from "vue"; +import type { colorSliderVariants } from "@heroui-vue/styles"; +import type { ColorChannel, ColorSpace } from "../color/value"; +import type { ColorState } from "../color/model"; +import type { useColorSlider } from "../color/slider"; +import type { ColorSliderRenderProps } from "./types"; + +export type ColorSliderControl = ReturnType; +export type ColorSliderStyles = ReturnType; + +export interface ColorSliderElements { + root: ShallowRef; + track: ShallowRef; + thumb: ShallowRef; + input: ShallowRef; +} + +export interface ColorSliderContext { + elements: ColorSliderElements; + state: ColorState; + control: ColorSliderControl; + styles: ColorSliderStyles; + focusVisible: ShallowRef; + pointerFocus: ShallowRef; + disabled: ComputedRef; + readOnly: ComputedRef; + channel: Ref; + space: ComputedRef; + orientation: ComputedRef<"horizontal" | "vertical">; + dir: ComputedRef<"ltr" | "rtl">; + locale: ComputedRef; + inputId: ComputedRef; + name: Ref; + form: Ref; + label: () => string | undefined; + labelledBy: () => string | undefined; + describedBy: () => string | undefined; + renderProps: ComputedRef; +} + +export const colorSliderKey: InjectionKey = + Symbol("hv-color-slider"); + +export function useColorSliderContext() { + const context = inject(colorSliderKey, undefined); + if (!context) + throw new Error("ColorSlider parts must be rendered inside ColorSlider."); + return context; +} diff --git a/packages/vue/src/components/color-slider/types.ts b/packages/vue/src/components/color-slider/types.ts new file mode 100644 index 0000000..cfb9d92 --- /dev/null +++ b/packages/vue/src/components/color-slider/types.ts @@ -0,0 +1,176 @@ +import type { StyleValue, VNodeChild } from "vue"; +import type { + Color, + ColorChannel, + ColorSpace, + ColorValue, +} from "../color/value"; + +/** Values shared by the public style functions, slots and render state. */ +export interface ColorSliderRenderProps { + /** Display color converted for the active channel; defaults to the accepted value. */ + color: Color; + channel: ColorChannel; + /** Color space actually used to interpret the channel after auto-correction. */ + colorSpace: ColorSpace; + orientation: "horizontal" | "vertical"; + isDisabled: boolean; + isReadOnly: boolean; +} + +export interface ColorSliderOutputRenderProps extends ColorSliderRenderProps { + /** Accepted channel value in the model scale (alpha is 0–1). */ + value: number; + /** Locale-formatted channel value, also used as the native input value text. */ + label: string; +} + +export interface ColorSliderTrackRenderProps extends ColorSliderRenderProps { + /** Accepted channel position in the 0–1 content box, before RTL mapping. */ + percent: number; +} + +export interface ColorSliderThumbRenderProps extends ColorSliderTrackRenderProps { + isDragging: boolean; +} + +export type ColorSliderStyleFn = ( + renderProps: ColorSliderRenderProps, +) => StyleValue | undefined; + +/** Vue style binding (object/array/string) or the upstream style function. */ +export type ColorSliderStyle = StyleValue | ColorSliderStyleFn; + +export type ColorSliderOutputStyleFn = ( + renderProps: ColorSliderOutputRenderProps, +) => StyleValue | undefined; + +export type ColorSliderOutputStyle = StyleValue | ColorSliderOutputStyleFn; + +export type ColorSliderTrackStyleFn = ( + renderProps: ColorSliderTrackRenderProps, +) => StyleValue | undefined; + +export type ColorSliderTrackStyle = StyleValue | ColorSliderTrackStyleFn; + +export type ColorSliderThumbStyleFn = ( + renderProps: ColorSliderThumbRenderProps, +) => StyleValue | undefined; + +export type ColorSliderThumbStyle = StyleValue | ColorSliderThumbStyleFn; + +export interface ColorSliderSlots { + default?: (renderProps: ColorSliderRenderProps) => VNodeChild; +} + +export interface ColorSliderOutputSlots { + default?: (renderProps: ColorSliderOutputRenderProps) => VNodeChild; +} + +export interface ColorSliderTrackSlots { + default?: (renderProps: ColorSliderTrackRenderProps) => VNodeChild; +} + +export interface ColorSliderThumbSlots { + default?: (renderProps: ColorSliderThumbRenderProps) => VNodeChild; +} + +/** Channels available in the HSL color space. */ +export type HSLChannel = "hue" | "saturation" | "lightness" | "alpha"; + +/** Channels available in the HSB color space. */ +export type HSBChannel = "hue" | "saturation" | "brightness" | "alpha"; + +/** Channels available in the RGB color space. */ +export type RGBChannel = "red" | "green" | "blue" | "alpha"; + +/** Channels shared by HSL and HSB but not RGB. */ +export type HSLHSBSharedChannel = "hue" | "saturation"; + +/** Alpha works across every color space. */ +export type AlphaChannel = "alpha"; + +/** + * Discriminated union for valid channel/colorSpace pairs, mirroring the fixed + * source. Invalid combinations such as `channel="red"` with `colorSpace="hsl"` + * or `channel="hue"` with `colorSpace="rgb"` fail type checking. + */ +export type ColorSliderChannelProps = + | { channel: HSLChannel; colorSpace?: "hsl" } + | { channel: HSBChannel; colorSpace?: "hsb" } + | { channel: RGBChannel; colorSpace?: "rgb" } + | { channel: HSLHSBSharedChannel; colorSpace?: "hsl" | "hsb" } + | { channel: AlphaChannel; colorSpace?: ColorSpace }; + +/** Props shared by every valid channel/colorSpace combination. */ +export interface ColorSliderBaseProps { + /** Accepted color; the Vue `v-model` value. Omitted inherits the nearest owner. */ + modelValue?: ColorValue | null; + /** Lower-priority alias for `modelValue`, matching the shared color model. */ + value?: ColorValue | null; + /** Initial color for uncontrolled use. */ + defaultValue?: ColorValue | null; + /** Slider direction. */ + orientation?: "horizontal" | "vertical"; + /** Native form field name for the channel value. */ + name?: string; + /** Id of an external form. */ + form?: string; + isDisabled?: boolean; + /** Alias for `isDisabled`. */ + disabled?: boolean; + /** Library extension: blocks edits without removing the slider from the tab order. */ + isReadOnly?: boolean; + locale?: string; + dir?: "ltr" | "rtl"; + /** Render a different root element; corresponds to the upstream render prop. */ + as?: string; + /** Merge the slider attributes and handlers onto the single default-slot root. */ + asChild?: boolean; + /** Vue style binding or upstream style function, merged after base styles. */ + style?: ColorSliderStyle; + /** Template-friendly alias for the style function; receives render props. */ + styleFn?: ColorSliderStyleFn; + /** Id assigned to the real native range input. */ + id?: string; +} + +export type ColorSliderProps = ColorSliderBaseProps & ColorSliderChannelProps; +export type ColorSliderRootProps = ColorSliderProps; + +export interface ColorSliderOutputProps { + /** Render a different output element. */ + as?: string; + /** Vue style binding or upstream style function, merged after base styles. */ + style?: ColorSliderOutputStyle; + /** Template-friendly alias for the style function; receives render props. */ + styleFn?: ColorSliderOutputStyleFn; +} + +export interface ColorSliderTrackProps { + /** Render a different track element. */ + as?: string; + /** Vue style binding or upstream style function, merged after base styles. */ + style?: ColorSliderTrackStyle; + /** Template-friendly alias for the style function; receives render props. */ + styleFn?: ColorSliderTrackStyleFn; +} + +export interface ColorSliderThumbProps { + /** Render a different thumb element; corresponds to the upstream render prop. */ + as?: string; + /** Vue style binding or upstream style function, merged after base styles. */ + style?: ColorSliderThumbStyle; + /** Template-friendly alias for the style function; receives render props. */ + styleFn?: ColorSliderThumbStyleFn; +} + +/** + * State exposed by the root instance. Refs are unwrapped on the public + * instance proxy, matching the ColorArea `element`/`color` convention. + */ +export interface ColorSliderExpose { + element: HTMLElement | null; + color: Color | null; + focus: () => void; +} diff --git a/packages/vue/src/components/color/labels.ts b/packages/vue/src/components/color/labels.ts new file mode 100644 index 0000000..9846d84 --- /dev/null +++ b/packages/vue/src/components/color/labels.ts @@ -0,0 +1,32 @@ +import type { ColorChannel } from "./value"; + +const english: Record = { + red: "Red", + green: "Green", + blue: "Blue", + hue: "Hue", + saturation: "Saturation", + lightness: "Lightness", + brightness: "Brightness", + alpha: "Alpha", +}; + +const chinese: Record = { + red: "红色", + green: "绿色", + blue: "蓝色", + hue: "色相", + saturation: "饱和度", + lightness: "亮度", + brightness: "明度", + alpha: "透明度", +}; + +function isChinese(locale: string) { + return locale.toLowerCase().startsWith("zh"); +} + +/** Localized native slider/channel name; other locales fall back to English. */ +export function colorChannelLabel(channel: ColorChannel, locale: string) { + return (isChinese(locale) ? chinese : english)[channel]; +} diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 8dfa1fc..1b0c119 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1156,6 +1156,47 @@ export type { ColorAreaThumbProps, } from "./types"; +export { default as ColorSlider } from "./components/color-slider/ColorSlider.vue"; +export { default as ColorSliderRoot } from "./components/color-slider/ColorSlider.vue"; +export { default as ColorSliderOutput } from "./components/color-slider/ColorSliderOutput.vue"; +export { default as ColorSliderTrack } from "./components/color-slider/ColorSliderTrack.vue"; +export { default as ColorSliderThumb } from "./components/color-slider/ColorSliderThumb.vue"; +export { + colorSliderVariants, + type ColorSliderVariants, +} from "@heroui-vue/styles"; +export type { + AlphaChannel, + ColorSliderBaseProps, + ColorSliderChannelProps, + ColorSliderExpose, + ColorSliderOutputProps, + ColorSliderOutputRenderProps, + ColorSliderOutputSlots, + ColorSliderOutputStyle, + ColorSliderOutputStyleFn, + ColorSliderProps, + ColorSliderRenderProps, + ColorSliderRootProps, + ColorSliderSlots, + ColorSliderStyle, + ColorSliderStyleFn, + ColorSliderThumbProps, + ColorSliderThumbRenderProps, + ColorSliderThumbSlots, + ColorSliderThumbStyle, + ColorSliderThumbStyleFn, + ColorSliderTrackProps, + ColorSliderTrackRenderProps, + ColorSliderTrackSlots, + ColorSliderTrackStyle, + ColorSliderTrackStyleFn, + HSLChannel, + HSLHSBSharedChannel, + HSBChannel, + RGBChannel, +} from "./components/color-slider/types"; + export { default as ColorSwatch } from "./components/color-swatch/ColorSwatch.vue"; export { default as ColorSwatchRoot } from "./components/color-swatch/ColorSwatch.vue"; export { diff --git a/tests/color-slider-demos.test.ts b/tests/color-slider-demos.test.ts new file mode 100644 index 0000000..8646665 --- /dev/null +++ b/tests/color-slider-demos.test.ts @@ -0,0 +1,301 @@ +import { afterEach, describe, expect, it } from "vitest"; +import { mount, flushPromises } from "@vue/test-utils"; +import { readFileSync } from "node:fs"; +import { ColorSlider, parseColor } from "../packages/vue/src"; +import Basic from "../apps/docs/demos/color-slider-basic.vue"; +import Disabled from "../apps/docs/demos/color-slider-disabled.vue"; +import Vertical from "../apps/docs/demos/color-slider-vertical.vue"; +import Controlled from "../apps/docs/demos/color-slider-controlled.vue"; +import Channels from "../apps/docs/demos/color-slider-channels.vue"; +import AlphaChannel from "../apps/docs/demos/color-slider-alpha-channel.vue"; +import RgbChannels from "../apps/docs/demos/color-slider-rgb-channels.vue"; +import RenderFunction from "../apps/docs/demos/color-slider-render-function.vue"; +import CustomStyles from "../apps/docs/demos/color-slider-custom-styles.vue"; + +const mounted: ReturnType[] = []; +function render(component: Parameters[0]) { + const w = mount(component, { attachTo: document.body }); + mounted.push(w); + return w; +} +afterEach(() => { + mounted.splice(0).forEach((w) => w.unmount()); + document.body.innerHTML = ""; +}); + +const previews = [ + "basic", + "disabled", + "vertical", + "controlled", + "channels", + "alpha-channel", + "rgb-channels", + "render-function", + "custom-styles", +]; +const roots = (w: ReturnType) => + w.findAll("[data-slot=color-slider]"); +const root = (w: ReturnType) => roots(w)[0]!; +const outputs = (w: ReturnType) => + w.findAll("[data-slot=color-slider-output]").map((node) => node.text()); +const inputs = (w: ReturnType) => + w.findAll( + "[data-slot=color-slider-thumb] input[type=range]", + ); +const thumbs = (w: ReturnType) => + w.findAll("[data-slot=color-slider-thumb]"); +const tracks = (w: ReturnType) => + w.findAll("[data-slot=color-slider-track]"); + +describe("ColorSlider documentation demos", () => { + it("keeps the nine pinned previews in the upstream order", () => { + const document = readFileSync( + "apps/docs/components/color-slider.md", + "utf8", + ); + const names = [ + ...document.matchAll(/ match[1]); + expect(names).toEqual(previews); + for (const name of previews) { + const source = readFileSync( + `apps/docs/demos/color-slider-${name}.vue`, + "utf8", + ); + expect(source).toContain(""); + expect(source).toContain('from "@heroui-vue/components"'); + expect(source).not.toContain("className"); + } + }); + + it("renders the basic example with Label, Output, Track and Thumb", () => { + const w = render(Basic); + expect(roots(w)).toHaveLength(1); + expect(root(w).classes()).toContain("hv-color-slider"); + expect(root(w).attributes("data-orientation")).toBe("horizontal"); + expect(outputs(w)).toEqual(["0°"]); + expect(inputs(w)).toHaveLength(1); + expect(inputs(w)[0]!.element.value).toBe("0"); + expect(inputs(w)[0]!.attributes("aria-valuetext")).toBe("0°"); + expect(w.get("label[data-slot=label]").text()).toBe("色相"); + expect(inputs(w)[0]!.attributes("id")).toBe( + w.get("label[data-slot=label]").attributes("for"), + ); + expect(thumbs(w)[0]!.element.style.left).toBe("0%"); + expect( + tracks(w)[0]!.element.style.getPropertyValue("--track-background"), + ).toContain("linear-gradient"); + expect( + tracks(w)[0]!.element.style.getPropertyValue("--track-start-color"), + ).toBe("rgb(255, 0, 0)"); + }); + + it("renders the disabled example without editable input", async () => { + const w = render(Disabled); + expect(root(w).attributes("data-disabled")).toBe("true"); + expect(thumbs(w)[0]!.attributes("data-disabled")).toBe("true"); + expect(inputs(w)[0]!.element.disabled).toBe(true); + expect(thumbs(w)[0]!.element.style.backgroundColor).toBe(""); + await inputs(w)[0]!.trigger("keydown", { key: "ArrowRight" }); + await inputs(w)[0]!.trigger("keyup", { key: "ArrowRight" }); + expect(inputs(w)[0]!.element.value).toBe("200"); + expect(w.findComponent(ColorSlider).emitted("change")).toBeUndefined(); + }); + + it("renders three vertical sliders with localized accessible names", () => { + const w = render(Vertical); + expect(roots(w)).toHaveLength(3); + for (const node of roots(w)) { + expect(node.attributes("data-orientation")).toBe("vertical"); + } + expect(inputs(w).map((input) => input.attributes("aria-label"))).toEqual([ + "色相", + "饱和度", + "明度", + ]); + expect( + inputs(w).map((input) => input.attributes("aria-orientation")), + ).toEqual(["vertical", "vertical", "vertical"]); + expect(thumbs(w).map((thumb) => thumb.element.style.top)).toEqual([ + "100%", + "0%", + "50%", + ]); + expect( + tracks(w).map((track) => + track.element.style.getPropertyValue("--track-background"), + ), + ).toEqual([ + expect.stringContaining("to top"), + expect.stringContaining("to top"), + expect.stringContaining("to top"), + ]); + }); + + it("keeps the controlled slider and swatch in sync", async () => { + const w = render(Controlled); + const swatch = w.get("[data-slot=color-swatch]"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("hsl(200, 100%, 50%)").toString("css"), + ); + expect(w.text()).toContain("hsl(200, 100%, 50%)"); + expect(outputs(w)).toEqual(["200°"]); + await inputs(w)[0]!.trigger("keydown", { key: "ArrowRight" }); + await inputs(w)[0]!.trigger("keyup", { key: "ArrowRight" }); + await flushPromises(); + expect(inputs(w)[0]!.element.value).toBe("201"); + expect(outputs(w)).toEqual(["201°"]); + expect(w.text()).toContain("hsl(201, 100%, 50%)"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("hsl(201, 100%, 50%)").toString("css"), + ); + }); + + it("shares one color across the HSL channel sliders", async () => { + const w = render(Channels); + expect(roots(w)).toHaveLength(3); + expect(outputs(w)).toEqual(["0°", "100%", "50%"]); + expect(inputs(w).map((input) => input.element.value)).toEqual([ + "0", + "100", + "50", + ]); + await inputs(w)[1]!.trigger("keydown", { key: "ArrowDown" }); + await inputs(w)[1]!.trigger("keyup", { key: "ArrowDown" }); + await flushPromises(); + expect(outputs(w)).toEqual(["0°", "99%", "50%"]); + expect(w.text()).toContain("hsl(0, 99%, 50%)"); + expect(inputs(w)[1]!.element.value).toBe("99"); + const swatch = w.get("[data-slot=color-swatch]"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("hsl(0, 99%, 50%)").toString("css"), + ); + }); + + it("renders the alpha channel with a checkerboard and percent output", () => { + const w = render(AlphaChannel); + expect(inputs(w)[0]!.attributes("min")).toBe("0"); + expect(inputs(w)[0]!.attributes("max")).toBe("1"); + expect(inputs(w)[0]!.element.value).toBe("0.5"); + expect(outputs(w)).toEqual(["50%"]); + expect( + tracks(w)[0]!.element.style.getPropertyValue("--track-background"), + ).toContain("repeating-conic-gradient"); + expect( + tracks(w)[0]!.element.style.getPropertyValue("--track-start-color"), + ).toBe("rgba(255, 0, 0, 0)"); + expect( + tracks(w)[0]!.element.style.getPropertyValue("--track-end-color"), + ).toBe("rgb(255, 0, 0)"); + }); + + it("shares one RGB color across red, green and blue sliders", async () => { + const w = render(RgbChannels); + expect(outputs(w)).toEqual(["255", "100", "50"]); + expect(inputs(w).map((input) => input.attributes("max"))).toEqual([ + "255", + "255", + "255", + ]); + await inputs(w)[0]!.trigger("keydown", { key: "ArrowLeft" }); + await inputs(w)[0]!.trigger("keyup", { key: "ArrowLeft" }); + await flushPromises(); + expect(outputs(w)).toEqual(["254", "100", "50"]); + expect(w.text()).toContain("rgb(254, 100, 50)"); + const swatch = w.get("[data-slot=color-swatch]"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("rgb(254, 100, 50)").toString("css"), + ); + }); + + it("maps the render-function example to asChild and keeps interaction", async () => { + const w = render(RenderFunction); + const node = root(w); + expect(node.attributes("data-custom")).toBe("foo"); + expect(node.element.tagName).toBe("DIV"); + expect(node.classes()).toContain("hv-color-slider"); + expect(outputs(w)).toEqual(["0°"]); + await inputs(w)[0]!.trigger("keydown", { key: "ArrowRight" }); + await inputs(w)[0]!.trigger("keyup", { key: "ArrowRight" }); + await flushPromises(); + expect(outputs(w)).toEqual(["1°"]); + }); + + it("merges the custom style example classes onto real parts", () => { + const w = render(CustomStyles); + expect(root(w).classes()).toContain("hv-color-slider"); + const output = w.get("[data-slot=color-slider-output]"); + for (const name of [ + "text-muted", + "tabular-nums", + "hv-color-slider__output", + ]) { + expect(output.classes()).toContain(name); + } + const track = tracks(w)[0]!; + for (const name of [ + "h-4!", + "rounded-none!", + "ring-1", + "ring-border", + "hv-color-slider__track", + ]) { + expect(track.classes()).toContain(name); + } + const thumb = thumbs(w)[0]!; + for (const name of [ + "size-4", + "rounded-sm!", + "border-2", + "border-background", + "shadow-md", + "hv-color-slider__thumb", + ]) { + expect(thumb.classes()).toContain(name); + } + const label = w.get("label[data-slot=label]"); + expect(label.text()).toBe("色相"); + expect(label.classes()).toContain("font-medium"); + }); + + it("documents the Vue API, channels and related state", () => { + const document = readFileSync( + "apps/docs/components/color-slider.md", + "utf8", + ); + expect(document).toContain("title: ColorSlider 颜色滑块"); + expect(document).toContain("ColorSliderOutput"); + expect(document).toContain("ColorSliderTrack"); + expect(document).toContain("ColorSliderThumb"); + expect(document).toContain("`channel`"); + expect(document).toContain("`colorSpace`"); + expect(document).toContain("`orientation`"); + expect(document).toContain("`name`"); + expect(document).toContain("`form`"); + expect(document).toContain("`asChild`"); + expect(document).toContain("`styleFn`"); + expect(document).toContain("`isReadOnly`"); + expect(document).toContain("ColorSliderThumbRenderProps"); + expect(document).toContain("changeEnd"); + expect(document).toContain("`modelValue`/`value` 或 `defaultValue`"); + expect(document).not.toMatch(/\|\s*`className`\s*\|/); + expect(document).not.toContain("### ColorSlider.Output"); + expect(document).toContain("ColorField"); + expect(document).toContain("仍为私有颜色协议"); + }); + + it("adds ColorSlider to the shared navigation between Area and Swatch", () => { + const navigation = readFileSync( + "apps/docs/.vitepress/theme/navigation.ts", + "utf8", + ); + const area = navigation.indexOf("ColorArea 颜色区域"); + const slider = navigation.indexOf("ColorSlider 颜色滑块"); + const swatch = navigation.indexOf("ColorSwatch 颜色色块"); + expect(area).toBeGreaterThan(-1); + expect(slider).toBeGreaterThan(area); + expect(swatch).toBeGreaterThan(slider); + expect(navigation).toContain('url: "/components/color-slider"'); + }); +}); diff --git a/tests/color-slider.test.ts b/tests/color-slider.test.ts new file mode 100644 index 0000000..5ad71b9 --- /dev/null +++ b/tests/color-slider.test.ts @@ -0,0 +1,1040 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { mount, flushPromises } from "@vue/test-utils"; +import { defineComponent, shallowRef } from "vue"; +import { + ColorSlider, + ColorSliderOutput, + ColorSliderRoot, + ColorSliderThumb, + ColorSliderTrack, + ColorSwatch, + ConfigProvider, + Description, + Label, + colorSliderVariants, + parseColor, + type Color, +} from "../packages/vue/src"; +import Picker from "../packages/vue/tests/fixtures/ColorPickerFoundation.vue"; + +const mounted: ReturnType[] = []; +function render( + component: Parameters[0], + options: Parameters[1] = {}, +) { + const w = mount(component, { attachTo: document.body, ...options }); + mounted.push(w); + return w; +} +function slide( + props: Record = {}, + template = 'Hue', + setup: () => Record = () => ({}), +) { + return render( + defineComponent({ + components: { + ColorSlider, + ColorSliderOutput, + ColorSliderTrack, + ColorSliderThumb, + ColorSwatch, + ConfigProvider, + Description, + Label, + Picker, + }, + setup: () => ({ props, ...setup() }), + template, + }), + ); +} +afterEach(() => { + mounted.splice(0).forEach((w) => w.unmount()); + document.body.innerHTML = ""; + vi.restoreAllMocks(); +}); + +const root = (w: ReturnType) => + w.get("[data-slot=color-slider]"); +const output = (w: ReturnType) => + w.get("[data-slot=color-slider-output]"); +const track = (w: ReturnType) => + w.get("[data-slot=color-slider-track]"); +const thumb = (w: ReturnType) => + w.get("[data-slot=color-slider-thumb]"); +const input = (w: ReturnType) => + w.get("[data-slot=color-slider-thumb] input[type=range]"); +const emitted = (w: ReturnType, name: string) => + w.findComponent(ColorSlider).emitted(name) ?? []; +const values = (w: ReturnType, name: string) => + emitted(w, name).map(([value]) => value as Color); +async function key( + w: ReturnType, + name: string, + up = true, + extra = {}, +) { + const element = input(w); + await element.trigger("keydown", { key: name, ...extra }); + if (up) await element.trigger("keyup", { key: name, ...extra }); + await flushPromises(); +} +function geometry( + w: ReturnType, + vertical = false, + scale = 1, + border = 0, +) { + const node = track(w).element; + const width = vertical ? 20 : 220, + height = vertical ? 220 : 20; + node.style.border = `${border}px solid transparent`; + Object.defineProperties(node, { + offsetWidth: { get: () => width, configurable: true }, + offsetHeight: { get: () => height, configurable: true }, + }); + vi.spyOn(node, "getBoundingClientRect").mockReturnValue({ + left: 10, + top: 20, + width: width * scale, + height: height * scale, + right: 10 + width * scale, + bottom: 20 + height * scale, + x: 10, + y: 20, + toJSON: () => ({}), + }); + let captured: number | undefined; + node.setPointerCapture = vi.fn((id) => { + captured = id; + }); + node.hasPointerCapture = vi.fn((id) => captured === id); + node.releasePointerCapture = vi.fn(() => { + captured = undefined; + }); + return node; +} +async function pointer(node: Element, type: string, extra = {}) { + const event = new Event(type, { bubbles: true, cancelable: true }); + Object.assign(event, { + pointerId: 1, + pointerType: "mouse", + button: 0, + isPrimary: true, + clientX: 65, + clientY: 30, + ...extra, + }); + node.dispatchEvent(event); + await flushPromises(); + return event; +} + +describe("ColorSlider public contract", () => { + it("renders the baseline root, output, track, thumb and native range", () => { + const w = slide({ + defaultValue: "hsl(200, 100%, 50%)", + }); + expect(ColorSliderRoot).toBe(ColorSlider); + const node = root(w); + expect(node.classes()).toEqual(expect.arrayContaining(["hv-color-slider"])); + expect(node.attributes("data-slot")).toBe("color-slider"); + expect(node.attributes("data-orientation")).toBe("horizontal"); + expect(node.attributes("dir")).toBe("ltr"); + expect(colorSliderVariants().base()).toBe("hv-color-slider"); + expect(colorSliderVariants().output()).toBe("hv-color-slider__output"); + expect(colorSliderVariants().track()).toBe("hv-color-slider__track"); + expect(colorSliderVariants().thumb()).toBe("hv-color-slider__thumb"); + + expect(output(w).attributes("data-slot")).toBe("color-slider-output"); + expect(output(w).text()).toBe("200°"); + expect(output(w).attributes("for")).toBe(input(w).element.id); + expect(output(w).element.tagName).toBe("OUTPUT"); + + const label = w.get("[data-slot=label]"); + expect(label.element.tagName).toBe("LABEL"); + expect(label.attributes("for")).toBe(input(w).element.id); + + const bar = track(w); + expect(bar.attributes("data-slot")).toBe("color-slider-track"); + expect(bar.element.style.getPropertyValue("--track-start-color")).toBe( + "rgb(255, 0, 0)", + ); + expect(bar.element.style.getPropertyValue("--track-end-color")).toBe( + "rgb(255, 0, 0)", + ); + expect(bar.element.style.getPropertyValue("--track-background")).toContain( + "linear-gradient", + ); + expect(bar.element.style.getPropertyValue("--track-background")).toContain( + "repeating-conic-gradient", + ); + + const handle = thumb(w); + expect(handle.attributes("data-slot")).toBe("color-slider-thumb"); + expect(handle.classes()).toContain("hv-color-slider__thumb"); + expect(handle.element.style.left).toBe(`${(200 / 360) * 100}%`); + expect(handle.element.style.top).toBe("50%"); + expect(handle.element.style.transform).toBe("translate(-50%, -50%)"); + expect(handle.element.style.backgroundColor).toBe( + parseColor("hsl(200, 100%, 50%)").toString("css"), + ); + expect(handle.find("input[type=range]").exists()).toBe(true); + + const range = input(w); + expect(range.attributes("type")).toBe("range"); + expect(range.attributes("step")).toBe("any"); + expect(range.attributes("min")).toBe("0"); + expect(range.attributes("max")).toBe("360"); + expect(range.attributes("aria-valuetext")).toBe("200°"); + expect(range.attributes("aria-orientation")).toBe("horizontal"); + expect(range.element.value).toBe("200"); + }); + + it("supports every channel, alpha scale and library space inference", () => { + const saturation = slide({ + channel: "saturation", + defaultValue: "hsb(240, 50%, 50%)", + }); + expect(input(saturation).attributes("max")).toBe("100"); + expect(input(saturation).element.value).toBe("50"); + expect(output(saturation).text()).toBe("50%"); + expect((emitted(saturation, "update:modelValue") as unknown[]).length).toBe( + 0, + ); + + const lightness = slide({ + channel: "lightness", + defaultValue: "hsl(200, 100%, 50%)", + }); + expect(input(lightness).attributes("max")).toBe("100"); + expect(input(lightness).element.value).toBe("50"); + + const brightness = slide({ + channel: "brightness", + defaultValue: "hsb(200, 100%, 40%)", + }); + expect(input(brightness).element.value).toBe("40"); + + const red = slide({ + channel: "red", + defaultValue: "rgb(10, 20, 30)", + }); + expect(input(red).attributes("max")).toBe("255"); + expect(input(red).element.value).toBe("10"); + expect(output(red).text()).toBe("10"); + + // The private channel bridge infers the required space when one is omitted. + const inferred = slide({ + channel: "red", + defaultValue: "hsl(0, 100%, 50%)", + }); + expect(input(inferred).attributes("max")).toBe("255"); + expect(input(inferred).element.value).toBe("255"); + + const alpha = slide({ + channel: "alpha", + defaultValue: "hsla(0, 100%, 50%, 0.5)", + }); + expect(input(alpha).attributes("min")).toBe("0"); + expect(input(alpha).attributes("max")).toBe("1"); + expect(input(alpha).element.value).toBe("0.5"); + expect(output(alpha).text()).toBe("50%"); + expect( + track(alpha).element.style.getPropertyValue("--track-background"), + ).toContain("repeating-conic-gradient"); + }); + + it("auto-corrects invalid explicit spaces and warns in development", () => { + const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); + const red = slide({ + channel: "red", + colorSpace: "hsl", + defaultValue: "hsl(0, 100%, 50%)", + }); + expect(input(red).attributes("max")).toBe("255"); + expect(warn).toHaveBeenCalledWith( + expect.stringContaining('channel="red" requires colorSpace="rgb"'), + ); + const hue = slide({ + channel: "hue", + colorSpace: "rgb", + defaultValue: "rgb(10, 20, 30)", + }); + expect(input(hue).attributes("max")).toBe("360"); + expect(warn).toHaveBeenCalledWith( + expect.stringContaining("is not available in RGB color space"), + ); + const lightness = slide({ + channel: "lightness", + colorSpace: "hsb", + defaultValue: "hsb(200, 100%, 40%)", + }); + expect(input(lightness).attributes("max")).toBe("100"); + expect(warn).toHaveBeenCalledWith( + expect.stringContaining('channel="lightness" requires colorSpace="hsl"'), + ); + }); + + it("requires a value, default value or inherited owner", () => { + expect(() => + render( + defineComponent({ + components: { ColorSlider, ColorSliderTrack, ColorSliderThumb }, + template: ``, + }), + ), + ).toThrow(/requires a value or defaultValue/); + + const cleared = slide( + {}, + ``, + ); + expect(input(cleared).element.value).toBe("90"); + + expect(() => + render( + defineComponent({ + components: { ColorSlider, ColorSliderTrack, ColorSliderThumb }, + template: ``, + }), + ), + ).toThrow(/requires a value or defaultValue/); + }); + + it("starts keyboard edits, uses page steps, bounds and one end event", async () => { + const w = slide({ defaultValue: "hsl(10, 100%, 50%)" }); + await key(w, "ArrowRight", false); + expect(input(w).element.value).toBe("11"); + expect(values(w, "change")).toHaveLength(1); + expect(emitted(w, "changeEnd")).toHaveLength(0); + await input(w).trigger("keyup", { key: "ArrowRight" }); + expect(emitted(w, "changeEnd")).toHaveLength(1); + + await key(w, "ArrowRight", true, { shiftKey: true }); + expect(input(w).element.value).toBe("26"); + await key(w, "PageUp"); + expect(input(w).element.value).toBe("41"); + await key(w, "PageDown"); + expect(input(w).element.value).toBe("26"); + await key(w, "Home"); + expect(input(w).element.value).toBe("0"); + await key(w, "End"); + expect(input(w).element.value).toBe("360"); + expect(values(w, "changeEnd").at(-1)?.getChannelValue("hue")).toBe(360); + + const rtl = slide({ + defaultValue: "hsl(10, 100%, 50%)", + dir: "rtl", + }); + await key(rtl, "ArrowRight"); + expect(input(rtl).element.value).toBe("9"); + await key(rtl, "ArrowLeft"); + expect(input(rtl).element.value).toBe("10"); + + const vertical = slide({ + defaultValue: "hsl(10, 100%, 50%)", + dir: "rtl", + orientation: "vertical", + }); + await key(vertical, "ArrowLeft"); + expect(input(vertical).element.value).toBe("9"); + await key(vertical, "ArrowUp"); + expect(input(vertical).element.value).toBe("10"); + expect(input(vertical).attributes("aria-orientation")).toBe("vertical"); + }); + + it("cancels with Escape, blur commits and disabled/readonly block edits", async () => { + const w = slide({ defaultValue: "hsl(10, 100%, 50%)" }); + await key(w, "ArrowRight", false); + expect(values(w, "change")).toHaveLength(1); + await key(w, "Escape", false); + await input(w).trigger("keyup", { key: "ArrowRight" }); + await flushPromises(); + expect(emitted(w, "changeEnd")).toHaveLength(0); + expect(input(w).element.value).toBe("11"); + + await key(w, "ArrowRight", false); + await input(w).trigger("blur"); + expect(emitted(w, "changeEnd")).toHaveLength(1); + + const disabled = slide({ + defaultValue: "hsl(10, 100%, 50%)", + isDisabled: true, + }); + expect(root(disabled).attributes("data-disabled")).toBe("true"); + expect(thumb(disabled).attributes("data-disabled")).toBe("true"); + expect(input(disabled).element.disabled).toBe(true); + await key(disabled, "ArrowRight"); + expect(emitted(disabled, "change")).toHaveLength(0); + + const readOnly = slide({ + defaultValue: "hsl(10, 100%, 50%)", + isReadOnly: true, + }); + expect(root(readOnly).attributes("data-readonly")).toBe("true"); + expect(input(readOnly).attributes("aria-readonly")).toBe("true"); + expect(input(readOnly).attributes()).not.toHaveProperty("disabled"); + await key(readOnly, "ArrowRight"); + expect(emitted(readOnly, "change")).toHaveLength(0); + }); + + it("keeps accepted values on controlled rejection and allows retries", async () => { + const value = shallowRef(parseColor("hsb(240,50%,50%)")); + const w = slide( + {}, + `Hue`, + () => ({ value }), + ); + for (let i = 0; i < 2; i++) await key(w, "ArrowRight"); + expect(emitted(w, "change")).toHaveLength(2); + expect(values(w, "change")[1]?.getChannelValue("hue")).toBe(241); + expect(input(w).element.value).toBe("240"); + expect(output(w).text()).toBe("240°"); + expect(thumb(w).element.style.left).toBe(`${(240 / 360) * 100}%`); + expect(values(w, "changeEnd")).toHaveLength(2); + expect(values(w, "changeEnd")[1]?.getChannelValue("hue")).toBe(241); + + value.value = parseColor("hsb(90,50%,50%)"); + await flushPromises(); + expect(input(w).element.value).toBe("90"); + expect(output(w).text()).toBe("90°"); + expect(emitted(w, "changeEnd")).toHaveLength(2); + }); + + it("accepts controlled updates and preserves alpha and fractional precision", async () => { + const value = shallowRef(parseColor("hsb(240,50.123%,50.567%,.321)")); + const w = slide( + {}, + `Saturation`, + () => ({ value }), + ); + expect(input(w).element.value).toBe("50.123"); + await key(w, "ArrowRight"); + expect(value.value?.getChannelValue("saturation")).toBe(51.123); + expect(value.value?.getChannelValue("alpha")).toBe(0.321); + expect(input(w).element.value).toBe("51.123"); + expect(output(w).text()).toBe("51%"); + }); + + it("preserves gray hue and normalizes RTL/vertical thumb geometry", async () => { + const gray = slide({ + channel: "hue", + defaultValue: "hsb(270,0%,50%,.125)", + }); + expect(input(gray).element.value).toBe("270"); + expect(output(gray).text()).toBe("270°"); + await key(gray, "ArrowRight"); + expect(values(gray, "change")[0]?.getChannelValue("alpha")).toBe(0.125); + + const rtl = slide({ + defaultValue: "hsb(90,50%,50%)", + dir: "rtl", + }); + expect(thumb(rtl).element.style.left).toBe("75%"); + expect( + track(rtl).element.style.getPropertyValue("--track-background"), + ).toContain("to left"); + + const vertical = slide({ + defaultValue: "hsb(270,50%,50%)", + orientation: "vertical", + }); + expect(root(vertical).attributes("data-orientation")).toBe("vertical"); + expect(thumb(vertical).element.style.left).toBe("50%"); + expect(thumb(vertical).element.style.top).toBe("25%"); + expect( + track(vertical).element.style.getPropertyValue("--track-background"), + ).toContain("to top"); + }); + + it("maps pointer clicks, borders, ancestor scaling and grab offsets", async () => { + const click = slide({ defaultValue: "hsl(0, 100%, 50%)" }); + const bar = geometry(click); + vi.spyOn(input(click).element, "matches").mockReturnValue(true); + await pointer(bar, "pointerdown", { clientX: 65, clientY: 30 }); + expect(thumb(click).attributes("data-focus-visible")).toBeUndefined(); + expect(values(click, "change")[0]?.getChannelValue("hue")).toBe(90); + await pointer(bar, "pointerup", { clientX: 65, clientY: 30 }); + expect(emitted(click, "change")).toHaveLength(1); + expect(values(click, "changeEnd")).toHaveLength(1); + expect(bar.releasePointerCapture).toHaveBeenCalledWith(1); + + const scaled = slide({ defaultValue: "hsl(0, 100%, 50%)" }); + const scaledBar = geometry(scaled, false, 2, 10); + await pointer(scaledBar, "pointerdown", { clientX: 330, clientY: 40 }); + await pointer(scaledBar, "pointerup", { clientX: 330, clientY: 40 }); + expect(values(scaled, "changeEnd")[0]?.getChannelValue("hue")).toBe(270); + + const grab = slide({ defaultValue: "hsl(240, 100%, 50%)" }); + const grabBar = geometry(grab); + const start = 10 + 220 * (240 / 360) + 3; + await pointer(thumb(grab).element, "pointerdown", { + clientX: start, + clientY: 30, + }); + expect(emitted(grab, "change")).toHaveLength(0); + await pointer(grabBar, "pointermove", { + clientX: start + 22, + clientY: 30, + }); + expect(values(grab, "change").at(-1)?.getChannelValue("hue")).toBe(276); + await pointer(grabBar, "pointerup", { clientX: 1000, clientY: 30 }); + expect(values(grab, "changeEnd").at(-1)?.getChannelValue("hue")).toBe(360); + expect(emitted(grab, "changeEnd")).toHaveLength(1); + expect(thumb(grab).attributes("data-dragging")).toBeUndefined(); + }); + + it("maps RTL and vertical pointers independently", async () => { + const rtl = slide({ defaultValue: "hsl(0, 100%, 50%)", dir: "rtl" }); + const rtlBar = geometry(rtl); + await pointer(rtlBar, "pointerdown", { clientX: 65, clientY: 30 }); + await pointer(rtlBar, "pointerup", { clientX: 65, clientY: 30 }); + expect(values(rtl, "changeEnd")[0]?.getChannelValue("hue")).toBe(270); + + const vertical = slide({ + defaultValue: "hsl(0, 100%, 50%)", + orientation: "vertical", + dir: "rtl", + }); + const verticalBar = geometry(vertical, true); + await pointer(verticalBar, "pointerdown", { clientX: 20, clientY: 75 }); + await pointer(verticalBar, "pointerup", { clientX: 20, clientY: 75 }); + expect(values(vertical, "changeEnd")[0]?.getChannelValue("hue")).toBe(270); + }); + + it("cancels pointer gestures without faking end and isolates pointers", async () => { + const w = slide({ defaultValue: "hsl(10, 100%, 50%)" }); + const bar = geometry(w); + await pointer(bar, "pointerdown"); + await pointer(bar, "pointermove", { clientX: 175, pointerId: 2 }); + await pointer(bar, "pointercancel", { pointerId: 2 }); + expect(bar.hasPointerCapture(1)).toBe(true); + await pointer(bar, "pointercancel"); + expect(bar.hasPointerCapture(1)).toBe(false); + await pointer(bar, "pointerup"); + expect(emitted(w, "changeEnd")).toHaveLength(0); + + const lost = slide({ defaultValue: "hsl(10, 100%, 50%)" }); + const lostBar = geometry(lost); + await pointer(lostBar, "pointerdown"); + await pointer(lostBar, "lostpointercapture"); + expect(emitted(lost, "changeEnd")).toHaveLength(0); + + const prevented = slide({ defaultValue: "hsl(10, 100%, 50%)" }); + const preventedBar = geometry(prevented); + preventedBar.addEventListener( + "pointerdown", + (event) => event.preventDefault(), + { capture: true, once: true }, + ); + await pointer(preventedBar, "pointerdown"); + expect(emitted(prevented, "change")).toHaveLength(0); + expect(preventedBar.setPointerCapture).not.toHaveBeenCalled(); + }); + + it("releases capture on disable, orientation changes, replacement and unmount", async () => { + const off = shallowRef(false), + orientation = shallowRef<"horizontal" | "vertical">("horizontal"); + const w = slide( + {}, + ``, + () => ({ off, orientation }), + ); + const bar = geometry(w); + await pointer(bar, "pointerdown"); + off.value = true; + await flushPromises(); + expect(bar.hasPointerCapture(1)).toBe(false); + expect(emitted(w, "changeEnd")).toHaveLength(0); + off.value = false; + await flushPromises(); + await pointer(bar, "pointerdown"); + orientation.value = "vertical"; + await flushPromises(); + expect(bar.hasPointerCapture(1)).toBe(false); + + const trackKey = shallowRef("first"); + const replaced = slide( + {}, + ``, + () => ({ trackKey }), + ); + const oldBar = geometry(replaced); + await pointer(oldBar, "pointerdown"); + trackKey.value = "second"; + await flushPromises(); + expect(oldBar.hasPointerCapture(1)).toBe(false); + expect(track(replaced).element).not.toBe(oldBar); + await pointer(oldBar, "pointerup", { clientX: 175 }); + expect(emitted(replaced, "changeEnd")).toHaveLength(0); + + const unmounted = slide({ defaultValue: "hsl(10,100%,50%)" }); + const lastBar = geometry(unmounted); + await pointer(lastBar, "pointerdown"); + const component = unmounted.findComponent(ColorSlider); + unmounted.unmount(); + expect(lastBar.hasPointerCapture(1)).toBe(false); + expect(component.emitted("changeEnd")).toBeUndefined(); + }); + + it("aborts stale drags on external replacement but accepts synchronous echoes", async () => { + const value = shallowRef(parseColor("hsb(240,50%,50%)")); + const w = slide( + {}, + ``, + () => ({ value }), + ); + const bar = geometry(w); + await pointer(bar, "pointerdown"); + value.value = parseColor("hsb(180,50%,50%)"); + await flushPromises(); + expect(bar.hasPointerCapture(1)).toBe(false); + await pointer(bar, "pointerup"); + expect(emitted(w, "changeEnd")).toHaveLength(0); + + const accepted = slide( + {}, + ``, + () => ({ value: shallowRef(parseColor("hsb(240,50%,50%)")) }), + ); + const acceptedBar = geometry(accepted); + await pointer(acceptedBar, "pointerdown"); + await pointer(acceptedBar, "pointermove", { clientX: 120 }); + await pointer(acceptedBar, "pointerup", { clientX: 175 }); + expect(emitted(accepted, "changeEnd")).toHaveLength(1); + expect(values(accepted, "changeEnd")[0]?.getChannelValue("hue")).toBe(270); + }); + + it("submits the accepted channel value and restores input.value on reset", async () => { + const w = slide( + {}, + ``, + ); + await key(w, "ArrowRight"); + const form = w.get("form").element as HTMLFormElement; + expect(new FormData(form).getAll("hue")).toEqual(["201"]); + expect(values(w, "change")).toHaveLength(1); + form.reset(); + await flushPromises(); + expect(input(w).element.value).toBe("200"); + expect(output(w).text()).toBe("200°"); + expect(emitted(w, "change")).toHaveLength(1); + expect(emitted(w, "changeEnd")).toHaveLength(1); + + const external = slide( + {}, + ` + + + `, + ); + const outside = external.get("#external-slider").element as HTMLFormElement; + expect(new FormData(outside).get("alpha")).toBe("0.5"); + await key(external, "ArrowRight"); + expect(new FormData(outside).get("alpha")).toBe("0.51"); + outside.reset(); + await flushPromises(); + expect(input(external).element.value).toBe("0.5"); + + const disabled = slide( + {}, + ``, + ); + expect(new FormData(disabled.get("form").element).has("hue")).toBe(false); + }); + + it("inherits the nearest owner, supports overrides and restores inheritance", async () => { + const override = shallowRef>({}); + const w = slide( + {}, + ` + + + + + `, + () => ({ override }), + ); + const picker = w.findComponent(Picker); + const swatch = () => + w.get("[data-owner-swatch]").element.style.backgroundColor; + expect(input(w).element.value).toBe("240"); + expect(swatch()).toBe(parseColor("hsb(240,50%,50%)").toString("css")); + + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(1); + expect(input(w).element.value).toBe("241"); + expect(swatch()).toBe(parseColor("hsb(241,50%,50%)").toString("css")); + + const form = w.get("form").element as HTMLFormElement; + const data = new FormData(form); + expect(data.getAll("color")).toHaveLength(1); + expect(data.getAll("hue")).toEqual(["241"]); + expect(input(w).element.value).toBe("241"); + + override.value = { modelValue: "hsb(10,20%,30%)" }; + await flushPromises(); + expect(input(w).element.value).toBe("10"); + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(1); + expect(input(w).element.value).toBe("10"); + + override.value = {}; + await flushPromises(); + expect(input(w).element.value).toBe("241"); + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(2); + expect(new FormData(form).getAll("color")).toHaveLength(1); + }); + + it("keeps sibling transactions independent when one slider is disabled", async () => { + const off = shallowRef(false); + const w = slide( + {}, + ` + + + `, + () => ({ off }), + ); + const picker = w.findComponent(Picker); + const bars = w.findAll("[data-slot=color-slider-track]"); + const first = bars[0]!.element; + Object.defineProperties(first, { + offsetWidth: { get: () => 220, configurable: true }, + offsetHeight: { get: () => 20, configurable: true }, + }); + vi.spyOn(first, "getBoundingClientRect").mockReturnValue({ + left: 0, + top: 0, + width: 220, + height: 20, + right: 220, + bottom: 20, + x: 0, + y: 0, + toJSON: () => ({}), + }); + first.setPointerCapture = vi.fn(); + first.hasPointerCapture = vi.fn(() => true); + first.releasePointerCapture = vi.fn(); + await pointer(first, "pointerdown", { clientX: 165, clientY: 10 }); + off.value = true; + await flushPromises(); + await pointer(first, "pointermove", { clientX: 170, clientY: 10 }); + expect(picker.emitted("change")?.length).toBeGreaterThan(1); + await pointer(first, "pointerup", { clientX: 170, clientY: 10 }); + expect(picker.emitted("changeEnd")).toHaveLength(1); + }); + + it("supports as, asChild, class/style/styleFn, slots and exposed state", async () => { + const styleFn = vi.fn(({ color }: { color: Color }) => ({ + outline: `1px solid ${color.toString("hex")}`, + })); + const w = slide( + { defaultValue: "hsl(200,100%,50%)" }, + ` + + Hue + {{ state.label }} / {{ state.value }} + + + `, + () => ({ styleFn }), + ); + const node = root(w); + expect(node.element.tagName).toBe("DIV"); + expect(node.attributes("data-custom")).toBe("slider"); + expect(node.classes()).toContain("hv-color-slider"); + expect(node.element.style.opacity).toBe("0.9"); + expect(node.element.style.outline).toBe("1px solid #00AAFF"); + expect(styleFn).toHaveBeenCalledWith( + expect.objectContaining({ + channel: "hue", + colorSpace: "hsl", + orientation: "horizontal", + isDisabled: false, + isReadOnly: false, + }), + ); + expect(output(w).text()).toBe("200° / 200"); + expect(track(w).attributes("data-custom")).toBe("track"); + expect(thumb(w).element.tagName).toBe("SPAN"); + expect(thumb(w).attributes("data-custom")).toBe("thumb"); + expect(w.text()).toContain("Hue"); + + const exposed = w.vm.$refs.sliderRef as { + element: HTMLElement; + color: Color; + focus: () => void; + }; + expect(exposed.element).toBe(node.element); + expect(exposed.color.toString("hsl")).toBe("hsl(200, 100%, 50%)"); + exposed.focus(); + expect(document.activeElement).toBe(input(w).element); + + await key(w, "ArrowRight"); + expect(output(w).text()).toBe("201° / 201"); + }); + + it("uses style and styleFn for output, track and thumb render props", () => { + const outputFn = vi.fn(() => ({ color: "red" })); + const trackFn = vi.fn(({ percent }: { percent: number }) => ({ + opacity: percent, + })); + const thumbFn = vi.fn(({ isDragging }: { isDragging: boolean }) => ({ + width: isDragging ? "20px" : "16px", + })); + const w = slide( + { defaultValue: "hsl(90,100%,50%)" }, + ` + + + + + `, + () => ({ outputFn, trackFn, thumbFn }), + ); + expect(output(w).element.tagName).toBe("SPAN"); + expect(output(w).element.style.fontSize).toBe("14px"); + expect(output(w).element.style.color).toBe("red"); + expect(track(w).element.style.borderColor).toBe("black"); + expect(track(w).element.style.opacity).toBe("0.25"); + expect(thumb(w).element.style.borderWidth).toBe("3px"); + expect(thumb(w).element.style.width).toBe("16px"); + expect(outputFn).toHaveBeenCalledWith( + expect.objectContaining({ value: 90, label: "90°" }), + ); + expect(trackFn).toHaveBeenCalledWith( + expect.objectContaining({ percent: 0.25 }), + ); + expect(thumbFn).toHaveBeenCalledWith( + expect.objectContaining({ + percent: 0.25, + isDragging: false, + isDisabled: false, + }), + ); + }); + + it("exposes root, output, track and thumb state through scoped slots", async () => { + const w = slide( + { defaultValue: "hsl(90,100%,50%)" }, + ` + {{ root.channel }} / {{ root.colorSpace }} / {{ root.orientation }} + {{ out.label }} / {{ out.value }} + {{ Math.round(track.percent * 100) }}{{ thumb.isDragging ? "dragging" : "idle" }} + `, + ); + expect(w.get("[data-root-scope]").text()).toBe("hue / hsl / horizontal"); + expect(w.get("[data-output-scope]").text()).toBe("90° / 90"); + expect(w.get("[data-track-scope]").text()).toBe("25"); + expect(w.get("[data-thumb-scope]").text()).toBe("idle"); + await key(w, "ArrowRight"); + expect(w.get("[data-output-scope]").text()).toBe("91° / 91"); + expect(w.get("[data-track-scope]").text()).toBe("25"); + }); + + it("associates Label, aria attributes, description and output with the input", async () => { + const labelled = slide( + {}, + ` + + + + + + + 说明 + `, + ); + const inputs = labelled.findAll( + "[data-slot=color-slider-thumb] input", + ); + expect(inputs[0]!.attributes("aria-label")).toBe("主题色"); + expect(inputs[1]!.attributes("aria-labelledby")).toBe("slider-caption"); + const roots = labelled.findAll("[data-slot=color-slider]"); + expect(roots[0]!.attributes("aria-label")).toBeUndefined(); + expect(roots[1]!.attributes("aria-labelledby")).toBeUndefined(); + + const described = slide( + {}, + ` + 色相 + 拖动调整色相 + + `, + ); + const description = described.get("[data-slot=description]"); + expect(input(described).attributes("aria-describedby")).toBe( + description.attributes("id"), + ); + await input(described).trigger("keydown", { key: "ArrowRight" }); + await flushPromises(); + expect(described.findAll("[data-slot=description]")).toHaveLength(1); + }); + + it("applies ConfigProvider locale and dir to labels, values and ramps", async () => { + const w = slide( + {}, + ` + + 饱和度 + + + + `, + ); + expect(root(w).attributes("dir")).toBe("rtl"); + expect(output(w).text()).toBe("25%"); + expect(input(w).attributes("aria-valuetext")).toBe("25%"); + expect(thumb(w).element.style.left).toBe("75%"); + expect( + track(w).element.style.getPropertyValue("--track-background"), + ).toContain("to left"); + expect(w.text()).toContain("饱和度"); + }); + + it("mirrors focus-visible to the thumb and ignores canceled keyboard defaults", async () => { + const w = slide({ defaultValue: "hsl(10,100%,50%)" }); + const range = input(w); + const matches = vi.spyOn(range.element, "matches"); + matches.mockReturnValue(true); + await range.trigger("focus"); + expect(thumb(w).attributes("data-focus-visible")).toBe("true"); + await range.trigger("blur"); + expect(thumb(w).attributes("data-focus-visible")).toBeUndefined(); + + matches.mockReturnValue(false); + await range.trigger("focus"); + expect(thumb(w).attributes("data-focus-visible")).toBeUndefined(); + matches.mockReturnValue(true); + await range.trigger("keydown", { key: "ArrowRight" }); + expect(thumb(w).attributes("data-focus-visible")).toBe("true"); + await range.trigger("keyup", { key: "ArrowRight" }); + + const canceled = slide({ defaultValue: "hsl(10,100%,50%)" }); + const element = input(canceled).element; + element.addEventListener("keydown", (event) => event.preventDefault(), { + capture: true, + once: true, + }); + await input(canceled).trigger("keydown", { key: "ArrowRight" }); + await input(canceled).trigger("keyup", { key: "ArrowRight" }); + expect(emitted(canceled, "change")).toHaveLength(0); + expect(emitted(canceled, "changeEnd")).toHaveLength(0); + }); + + it("keeps disabled thumb paint default and reflects dynamic space-changing ramps", async () => { + const disabled = slide({ + defaultValue: "hsl(200,100%,50%)", + isDisabled: true, + }); + expect(thumb(disabled).element.style.backgroundColor).toBe(""); + + const props = shallowRef>({ + channel: "hue", + colorSpace: "hsl", + defaultValue: "hsl(200,100%,50%)", + }); + const w = slide( + {}, + ``, + () => ({ props }), + ); + await key(w, "ArrowRight", false); + const start = track(w).element.style.getPropertyValue( + "--track-start-color", + ); + props.value = { + channel: "hue", + colorSpace: "hsl", + defaultValue: "hsl(200,100%,50%)", + orientation: "vertical", + }; + await flushPromises(); + expect(emitted(w, "changeEnd")).toHaveLength(0); + expect( + track(w).element.style.getPropertyValue("--track-background"), + ).toContain("to top"); + expect(start).toContain("rgb(255, 0, 0)"); + }); + + it("requires parts to be rendered inside the root", () => { + for (const part of [ + ColorSliderThumb, + ColorSliderTrack, + ColorSliderOutput, + ]) { + expect(() => + render( + defineComponent({ + components: { + ColorSliderThumb, + ColorSliderTrack, + ColorSliderOutput, + }, + template: `<${part === ColorSliderThumb ? "ColorSliderThumb" : part === ColorSliderTrack ? "ColorSliderTrack" : "ColorSliderOutput"} />`, + }), + ), + ).toThrow(/must be rendered inside ColorSlider/); + } + }); + + it("renders label/output without a thumb but exposes no native input", () => { + const w = slide( + {}, + `Hue`, + ); + expect(output(w).text()).toBe("20°"); + expect( + w.findAll("[data-slot=color-slider-thumb] input[type=range]"), + ).toHaveLength(0); + expect(w.findAll("[data-slot=color-slider-track]")).toHaveLength(1); + }); + + it("supports readonly while parent updates still render", async () => { + const value = shallowRef(parseColor("hsb(240,0%,50%)")); + const w = slide( + {}, + ``, + () => ({ value }), + ); + const bar = geometry(w); + await pointer(bar, "pointerdown"); + await pointer(bar, "pointerup"); + expect(emitted(w, "change")).toHaveLength(0); + value.value = parseColor("hsb(90,0%,50%)"); + await flushPromises(); + expect(input(w).element.value).toBe("90"); + expect(thumb(w).element.style.left).toBe("25%"); + }); + + it("keeps hue ramp opaque for transparent gray and alpha ramp with checkerboard", () => { + const gray = slide({ + channel: "hue", + defaultValue: "hsb(270,0%,50%,.1)", + }); + const hueRamp = + track(gray).element.style.getPropertyValue("--track-background"); + expect(hueRamp).toContain("rgb(255, 0, 0)"); + expect(hueRamp).toContain("rgb(0, 255, 0)"); + expect(hueRamp).not.toContain("rgba("); + + const alpha = slide({ + channel: "alpha", + defaultValue: "hsla(0,100%,50%,.25)", + }); + const alphaRamp = + track(alpha).element.style.getPropertyValue("--track-background"); + expect( + track(alpha).element.style.getPropertyValue("--track-start-color"), + ).toBe("rgba(255, 0, 0, 0)"); + expect( + track(alpha).element.style.getPropertyValue("--track-end-color"), + ).toBe("rgb(255, 0, 0)"); + expect(alphaRamp).toContain("repeating-conic-gradient"); + }); +}); diff --git a/tests/package/check-client.mjs b/tests/package/check-client.mjs index e69cf5d..15a5048 100644 --- a/tests/package/check-client.mjs +++ b/tests/package/check-client.mjs @@ -162,6 +162,42 @@ for (const id of process.argv.slice(2)) { "ColorSwatch declarations leak Reka types", ); } + if (id === "color-slider") { + assert(lib.ColorSlider === lib.ColorSliderRoot); + assert(lib.ColorSliderOutput); + assert(lib.ColorSliderTrack); + assert(lib.ColorSliderThumb); + assert( + lib.colorSliderVariants().base() === "hv-color-slider", + "ColorSlider base class must stay in the baseline namespace", + ); + assert( + lib.colorSliderVariants().track() === "hv-color-slider__track", + "ColorSlider track class must stay in the baseline namespace", + ); + const sliderDts = readFileSync( + new URL( + "./node_modules/@heroui-vue/components/dist/components/color-slider/ColorSlider.vue.d.ts", + import.meta.url, + ), + "utf8", + ); + const thumbDts = readFileSync( + new URL( + "./node_modules/@heroui-vue/components/dist/components/color-slider/ColorSliderThumb.vue.d.ts", + import.meta.url, + ), + "utf8", + ); + assert( + !sliderDts.includes("reka-ui"), + "ColorSlider declarations leak Reka types", + ); + assert( + !thumbDts.includes("reka-ui"), + "ColorSliderThumb declarations leak Reka types", + ); + } if (id === "b03-tag-error-message") { assert(/\.hv-tag-group\s*\[data-slot=["']?error-message/.test(css)); assert(lib.tagVariants({ size: "sm" }).base().includes("hv-tag--sm")); diff --git a/tests/package/client-checks.json b/tests/package/client-checks.json index b88850a..897c4ca 100644 --- a/tests/package/client-checks.json +++ b/tests/package/client-checks.json @@ -137,12 +137,12 @@ ".hv-color-input-group__prefix", ".hv-color-input-group__suffix" ], - "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] + "absent": ["ColorField", "ColorInputGroup", "ColorPicker"] }, "color-foundation": { "exports": [], "css": [".hv-color-area", ".hv-color-area__thumb"], - "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] + "absent": ["ColorField", "ColorInputGroup", "ColorPicker"] }, "color-picker-protocol": { "exports": [], @@ -151,7 +151,7 @@ ".hv-color-picker__trigger", ".hv-color-picker__popover" ], - "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] + "absent": ["ColorField", "ColorInputGroup", "ColorPicker"] }, "color-slider-foundation": { "exports": [], @@ -165,7 +165,7 @@ "max-height:inherit", "overscroll-behavior:contain" ], - "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] + "absent": ["ColorField", "ColorInputGroup", "ColorPicker"] }, "date-field": { "exports": [ @@ -442,5 +442,25 @@ "data-exiting", "data-endpoint" ] + }, + "color-slider": { + "exports": [ + "ColorSlider", + "ColorSliderRoot", + "ColorSliderOutput", + "ColorSliderTrack", + "ColorSliderThumb", + "colorSliderVariants", + "Color", + "parseColor" + ], + "css": [ + ".hv-color-slider", + ".hv-color-slider__output", + ".hv-color-slider__track", + ".hv-color-slider__thumb", + "--track-start-color", + "--track-end-color" + ] } } diff --git a/tests/package/color-slider-contract.ts b/tests/package/color-slider-contract.ts new file mode 100644 index 0000000..b087357 --- /dev/null +++ b/tests/package/color-slider-contract.ts @@ -0,0 +1,234 @@ +import { + ColorSlider, + ColorSliderOutput, + ColorSliderRoot, + ColorSliderThumb, + ColorSliderTrack, + colorSliderVariants, + parseColor, + type AlphaChannel, + type Color, + type ColorChannel, + type ColorSliderBaseProps, + type ColorSliderChannelProps, + type ColorSliderExpose, + type ColorSliderOutputProps, + type ColorSliderOutputRenderProps, + type ColorSliderOutputSlots, + type ColorSliderOutputStyle, + type ColorSliderOutputStyleFn, + type ColorSliderProps, + type ColorSliderRenderProps, + type ColorSliderRootProps, + type ColorSliderSlots, + type ColorSliderStyle, + type ColorSliderStyleFn, + type ColorSliderThumbProps, + type ColorSliderThumbRenderProps, + type ColorSliderThumbSlots, + type ColorSliderThumbStyle, + type ColorSliderThumbStyleFn, + type ColorSliderTrackProps, + type ColorSliderTrackRenderProps, + type ColorSliderTrackSlots, + type ColorSliderTrackStyle, + type ColorSliderTrackStyleFn, + type ColorSliderVariants, + type ColorSpace, + type ColorValue, + type HSLChannel, + type HSLHSBSharedChannel, + type HSBChannel, + type RGBChannel, +} from "@heroui-vue/components"; + +const color = parseColor("#9B80FF"); +const value: ColorValue = color; +const channel: ColorChannel = "hue"; +const space: ColorSpace = "hsb"; +const hslChannel: HSLChannel = "lightness"; +const hsbChannel: HSBChannel = "brightness"; +const rgbChannel: RGBChannel = "red"; +const sharedChannel: HSLHSBSharedChannel = "saturation"; +const alphaChannel: AlphaChannel = "alpha"; +const style: ColorSliderStyle = { outline: "1px solid black" }; +const styleFn: ColorSliderStyleFn = ({ color: current }) => ({ + outline: `1px solid ${current.toString("hex")}`, +}); +const styleRender: ColorSliderStyle = ({ channel: active }) => ({ + opacity: active ? 0.8 : 1, +}); +const outputStyle: ColorSliderOutputStyle = { + fontVariantNumeric: "tabular-nums", +}; +const outputStyleFn: ColorSliderOutputStyleFn = ({ label }) => ({ + width: `${label.length}ch`, +}); +const trackStyle: ColorSliderTrackStyle = { borderColor: "black" }; +const trackStyleFn: ColorSliderTrackStyleFn = ({ percent }) => ({ + opacity: percent, +}); +const thumbStyle: ColorSliderThumbStyle = { cursor: "grab" }; +const thumbStyleFn: ColorSliderThumbStyleFn = ({ isDragging }) => ({ + width: isDragging ? "20px" : "16px", +}); +const base: ColorSliderBaseProps = { + modelValue: color, + value, + defaultValue: "hsb(240, 50%, 50%)", + orientation: "vertical", + name: "hue", + form: "color-form", + isDisabled: false, + disabled: false, + isReadOnly: false, + locale: "zh-CN", + dir: "rtl", + as: "div", + asChild: false, + style, + styleFn, + id: "hue-slider", +}; +const channelProps: ColorSliderChannelProps = { + channel: "hue", + colorSpace: "hsb", +}; +const props: ColorSliderProps = { ...base, ...channelProps }; +const rootProps: ColorSliderRootProps = props; +const outputProps: ColorSliderOutputProps = { + as: "output", + style: outputStyle, + styleFn: outputStyleFn, +}; +const trackProps: ColorSliderTrackProps = { + as: "div", + style: trackStyle, + styleFn: trackStyleFn, +}; +const thumbProps: ColorSliderThumbProps = { + as: "span", + style: thumbStyle, + styleFn: thumbStyleFn, +}; +const render: ColorSliderRenderProps = { + color, + channel: "hue", + colorSpace: "hsb", + orientation: "vertical", + isDisabled: false, + isReadOnly: false, +}; +const outputRender: ColorSliderOutputRenderProps = { + ...render, + value: 240, + label: "240°", +}; +const trackRender: ColorSliderTrackRenderProps = { ...render, percent: 0.5 }; +const thumbRender: ColorSliderThumbRenderProps = { + ...trackRender, + isDragging: true, +}; +const slots: ColorSliderSlots = { default: () => null }; +const outputSlots: ColorSliderOutputSlots = { default: () => null }; +const trackSlots: ColorSliderTrackSlots = { default: () => null }; +const thumbSlots: ColorSliderThumbSlots = { default: () => null }; +const variants: ColorSliderVariants = {}; +const exposed: ColorSliderExpose = { + element: null, + color: null, + focus: () => {}, +}; +const typedColor: Color = color; + +// @ts-expect-error red requires the rgb color space +const badRed: ColorSliderProps = { channel: "red", colorSpace: "hsl" }; +// @ts-expect-error hue is not available in the rgb color space +const badHue: ColorSliderProps = { channel: "hue", colorSpace: "rgb" }; +// @ts-expect-error brightness requires the hsb color space +const badBrightness: ColorSliderProps = { + channel: "brightness", + colorSpace: "hsl", +}; +// @ts-expect-error lightness requires the hsl color space +const badLightness: ColorSliderProps = { + channel: "lightness", + colorSpace: "hsb", +}; +// @ts-expect-error blue requires the rgb color space +const badBlue: ColorSliderProps = { channel: "blue", colorSpace: "hsb" }; +// @ts-expect-error channel is required +const badMissing: ColorSliderProps = {}; +// @ts-expect-error the public channel set is finite +const badChannel: ColorSliderProps = { channel: "cyan" }; +// @ts-expect-error the public space set is rgb | hsl | hsb +const badSpace: ColorSliderProps = { channel: "alpha", colorSpace: "lab" }; +const badRender: ColorSliderRenderProps = { + // @ts-expect-error render props require a Color instance + color: "#fff", + channel: "hue", + colorSpace: "hsl", + orientation: "horizontal", + isDisabled: false, + isReadOnly: false, +}; +const badThumb: ColorSliderThumbRenderProps = { + ...render, + // @ts-expect-error percent is a 0–1 number, not a string + percent: "50%", + isDragging: false, +}; +const badExpose: ColorSliderExpose = { + element: null, + color: null, + focus: () => {}, + // @ts-expect-error channel is not part of the exposed instance + channel: "hue", +}; +// @ts-expect-error style functions return Vue style values, not numbers +const badStyle: ColorSliderStyleFn = () => 1; + +void [ + ColorSlider, + ColorSliderRoot, + ColorSliderOutput, + ColorSliderTrack, + ColorSliderThumb, + colorSliderVariants, + value, + channel, + space, + hslChannel, + hsbChannel, + rgbChannel, + sharedChannel, + alphaChannel, + styleRender, + props, + rootProps, + outputProps, + trackProps, + thumbProps, + outputRender, + trackRender, + thumbRender, + slots, + outputSlots, + trackSlots, + thumbSlots, + variants, + exposed, + typedColor, + badRed, + badHue, + badBrightness, + badLightness, + badBlue, + badMissing, + badChannel, + badSpace, + badRender, + badThumb, + badExpose, + badStyle, +];
+ 当前颜色: + + {{ color ? color.toString("hsl") : "(empty)" }} + +
+ {{ color ? color.toString("hsl") : "(empty)" }} +
+ 当前颜色: + + {{ color ? color.toString("rgb") : "(empty)" }} + +
+ {{ color ? color.toString("rgb") : "(empty)" }} +