diff --git a/apps/docs/.vitepress/theme/navigation.ts b/apps/docs/.vitepress/theme/navigation.ts index 2da5dd4..035ab1e 100644 --- a/apps/docs/.vitepress/theme/navigation.ts +++ b/apps/docs/.vitepress/theme/navigation.ts @@ -90,6 +90,11 @@ export const componentItems: DocsItem[] = [ url: "/components/close-button", category: "buttons", }, + { + title: "ColorArea 颜色区域", + url: "/components/color-area", + category: "colors", + }, { title: "ColorSwatch 颜色色块", url: "/components/color-swatch", diff --git a/apps/docs/components/color-area.md b/apps/docs/components/color-area.md new file mode 100644 index 0000000..2650846 --- /dev/null +++ b/apps/docs/components/color-area.md @@ -0,0 +1,181 @@ +--- +title: ColorArea 颜色区域 +description: 二维颜色选择器,允许用户从渐变区域中选择颜色 +component: color-area +group: 组件 +--- + +## 用法 + +```vue + + + + + + + +``` + + + +## 组件结构 + +Vue 版使用具名部件:`ColorArea` 负责共享颜色状态、渐变背景与指针/键盘事务,`ColorAreaThumb` 负责滑块定位和两个原生轴。`ColorAreaRoot` 是 `ColorArea` 的别名。 + +```vue + + + + + + + +``` + +## 示例 + +### 带定位点 + + + +### 色彩空间与通道 + +使用 `colorSpace` 设置颜色空间(RGB、HSL、HSB),使用 `xChannel`/`yChannel` 自定义各轴显示的颜色通道。示例继续使用上游的英文控件标签、通道名称与示例顺序。 + + + +### 禁用 + + + +### 受控组件 + +使用 `v-model` 绑定本库 `Color` 或颜色字符串;色块与二维区域共享同一个接受值。 + + + +### 渲染函数 + +上游 `render` 用于替换根元素和滑块元素:Vue 版在根元素上使用 `as` 更换标签,或用 `asChild` 把区域属性和事件合并到默认插槽中唯一的自定义根元素;滑块使用 `as` 更换标签。`data-*`、`aria-*`、事件、`class` 与 `style` 直接透传。 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 ColorArea 组件类。 +[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。 + +```css +@layer components { + .hv-color-area { + @apply rounded-3xl; + } + + .hv-color-area__thumb { + @apply size-5 border-4; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +ColorArea 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/color-area.css)): + +#### 基础类 [!toc] + +- `.hv-color-area` - 渐变背景与内阴影的基础样式 +- `.hv-color-area--show-dots` - 添加点阵网格覆盖层以精确选色 + +#### 元素类 [!toc] + +- `.hv-color-area__thumb` - 可拖拽的滑块指示器 + +组件通过行内自定义属性提供当前绘制值:`--color-area-background` 保存基础色与全部梯度图层,`--color-area-thumb-color` 保存滑块颜色。传入的 `style` 与 `styleFn` 在基础样式之后合并,可覆盖冲突属性。 + +### 交互状态 + +组件同时支持 CSS 伪类与 data 属性: + +- **Disabled**:`[data-disabled="true"]` +- **Focus**:`[data-focus-visible="true"]` +- **Dragging**:`[data-dragging="true"]`(仅 thumb) +- **ReadOnly**:`[data-readonly="true"]`(本库扩展,不改变基线 CSS) + +## API 参考 + +### ColorArea + +| Prop / 事件 | 类型 | 默认值 | 描述 | +| ------------------------- | --------------------------------------------- | -------------------------------- | ---------------------------------------------------------------------- | +| `v-model` (`modelValue`) | `string \| Color \| null` | - | 当前颜色(受控);更新时触发 `update:modelValue` | +| `value` | `string \| Color \| null` | - | `modelValue` 的低优先级别名;与共享颜色模型一致 | +| `defaultValue` | `string \| Color \| null` | `#ffffff` | 非受控初始值 | +| `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | 接受值自身的颜色空间 | 通道使用的颜色空间 | +| `xChannel` | `ColorAxisChannel` | 空间内第一个非 `yChannel` 的通道 | 水平轴颜色通道;RGB 默认 `red`,HSL/HSB 默认 `hue` | +| `yChannel` | `ColorAxisChannel` | 空间内第一个非 `xChannel` 的通道 | 垂直轴颜色通道;RGB 默认 `green`,HSL/HSB 默认 `saturation` | +| `xName` / `yName` | `string` | - | 两个轴的原生表单名称;分别提交通道数值 | +| `form` | `string` | - | 关联的外部 `form` id | +| `isDisabled` / `disabled` | `boolean` | `false` | 是否禁用;`disabled` 为别名 | +| `isReadOnly` | `boolean` | `false` | 本库扩展:阻止编辑但保留焦点和 Tab 顺序 | +| `showDots` | `boolean` | `false` | 是否显示点阵网格覆盖层 | +| `locale` | `string` | `ConfigProvider` / `en-US` | 轴的可访问名称与数值格式 | +| `dir` | `"ltr" \| "rtl"` | `ConfigProvider` / `ltr` | 布局方向;影响坐标映射与背景方向 | +| `aria-label` | `string` | 本地化“颜色区域” | 组的可访问名称;提供 `aria-labelledby` 时不生成默认名称 | +| `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` | - | 手势、键盘交互或失焦结束时触发一次;取消、卸载或外部替换不伪造完成事件 | +| 默认插槽 | `ColorAreaThumb` | - | 区域内的滑块;省略时没有可交互的原生轴 | + +`changeEnd` 只在本次事务确有接受提案时触发,回调参数是最后一次提案。受控父级拒绝提案时,滑块、两个轴、背景和原生值都保持接受值,同一手势可以再次提案;取消指针、`lostpointercapture`、窗口失焦、禁用/只读切换、卸载和外部颜色替换只终止本控件事务,不取消兄弟控件的拖动。 + +省略全部 `modelValue`/`value`/`defaultValue` 时会继承最近的共享颜色 owner(当前私有组合与后续公开颜色组件使用同一协议);显式值覆盖继承,显式 `null` 清空接受值并用默认色绘制区域。空字符串和无效颜色不是“清空”:它们按 `parseColor` 边界抛出 `RangeError`。 + +`colorSpace`、`xChannel`、`yChannel` 必须形成一个合法的有序轴组合;同一通道、通道不属于所选空间或 `alpha` 轴会抛出 `RangeError`。可用的 18 个有序轴组合(三种空间 × 六个方向)共用与指针相同的通道映射,并保留 alpha 与灰色色相。 + +固定源 1.21.1 的 `useColorAreaState` 实际以 `#ffffff` 为默认值,并按 `getColorSpaceAxes` 的通道顺序推断未指定的轴;上游中文 API 简表标注的 `saturation`/`brightness` 与该运行时默认不一致。本库以固定源实际行为为准:RGB 默认 `red`/`green`,HSL/HSB 默认 `hue`/`saturation`;需要饱和度 × 明度或饱和度 × 亮度时显式传入 `xChannel`/`yChannel`(“色彩空间与通道”示例即如此)。 + +`isReadOnly` 与 `disabled` 别名是本库在固定源之外保留的现有扩展;没有新增 React Aria 的完整 props 集合。 + +### ColorAreaThumb + +Vue 版写作 `ColorAreaThumb`(对应上游 `ColorArea.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 | 原生属性 | - | 透传到滑块根元素 | + +滑块内包含两个真正提交的原生 `range` 输入:两个轴都有本地化可访问名称、数值范围和格式化值,但只有一个进入 Tab 顺序;方向键按轴移动焦点。组件不使用一个虚构的二维 `aria-valuenow` 代替这两个轴。 + +`ColorAreaRenderProps` 包含 `{ color, space, x, y }`;`ColorAreaThumbRenderProps` 额外包含 `{ percent, isDragging, isDisabled, isReadOnly }`。根实例通过 `defineExpose` 公开 `element`(实际根 DOM)与 `color`(当前接受值)。 + +### 包根导出 + +`ColorArea`、`ColorAreaRoot`、`ColorAreaThumb`、`colorAreaVariants`、`ColorAreaVariants` 以及上述 Props/插槽/样式类型均从 `@heroui-vue/components` 导出。`ColorArea` 与 `ColorAreaRoot` 是同一个组件。 + +## 相关组件 + +本批次公开 ColorArea 与 ColorSwatch。ColorField、ColorInputGroup、ColorPicker、ColorSlider 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。 diff --git a/apps/docs/components/color-swatch.md b/apps/docs/components/color-swatch.md index 5e582f0..bdcfca2 100644 --- a/apps/docs/components/color-swatch.md +++ b/apps/docs/components/color-swatch.md @@ -152,4 +152,4 @@ ColorSwatch 组件使用以下 CSS 类([查看源码样式](https://github.com ## 相关组件 -本批次仅公开 ColorSwatch。ColorArea、ColorField、ColorPicker、ColorSlider 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。 +本批次公开 ColorArea 与 ColorSwatch。ColorField、ColorInputGroup、ColorPicker、ColorSlider 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。 diff --git a/apps/docs/demos/color-area-basic.vue b/apps/docs/demos/color-area-basic.vue new file mode 100644 index 0000000..1d70e47 --- /dev/null +++ b/apps/docs/demos/color-area-basic.vue @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/apps/docs/demos/color-area-controlled.vue b/apps/docs/demos/color-area-controlled.vue new file mode 100644 index 0000000..3672c85 --- /dev/null +++ b/apps/docs/demos/color-area-controlled.vue @@ -0,0 +1,34 @@ + + + + + + + + + + + Current color: + + {{ color ? color.toString("hex") : "(empty)" }} + + + + + diff --git a/apps/docs/demos/color-area-custom-styles.vue b/apps/docs/demos/color-area-custom-styles.vue new file mode 100644 index 0000000..464fb6a --- /dev/null +++ b/apps/docs/demos/color-area-custom-styles.vue @@ -0,0 +1,9 @@ + + + + + + + diff --git a/apps/docs/demos/color-area-disabled.vue b/apps/docs/demos/color-area-disabled.vue new file mode 100644 index 0000000..bdd3c32 --- /dev/null +++ b/apps/docs/demos/color-area-disabled.vue @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/apps/docs/demos/color-area-render-function.vue b/apps/docs/demos/color-area-render-function.vue new file mode 100644 index 0000000..e16af6b --- /dev/null +++ b/apps/docs/demos/color-area-render-function.vue @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/apps/docs/demos/color-area-space-and-channels.vue b/apps/docs/demos/color-area-space-and-channels.vue new file mode 100644 index 0000000..304cf40 --- /dev/null +++ b/apps/docs/demos/color-area-space-and-channels.vue @@ -0,0 +1,187 @@ + + + + + + + Color Space + + + + + + + + {{ space.name }} + + + + + + + + X Axis + + + + + + + + {{ channel.name }} + + + + + + + + Y Axis + + + + + + + + {{ channel.name }} + + + + + + + + + + + + + + + {{ color?.toString(colorSpace) ?? "(empty)" }} + + + + diff --git a/apps/docs/demos/color-area-with-dots.vue b/apps/docs/demos/color-area-with-dots.vue new file mode 100644 index 0000000..5f99e1f --- /dev/null +++ b/apps/docs/demos/color-area-with-dots.vue @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/docs/compatibility.md b/docs/compatibility.md index 264ed8c..4d63e05 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 | 私有基建已验证(COLOR-01) | 接受值、二维键盘、18 轴组合、指针捕获与两个原生轴/reset 已验证;未公开部件或 7 个正式预览 | -| 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 | 私有轨道已验证 | 自定义轨道、指针捕获/取消、键盘/方向/渐变及共享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 上下文。 | ## 公共导出差异 @@ -223,7 +223,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式 ## COLOR-01 颜色基建 -颜色值、接受值/继承 owner、二维交互与梯度已由私有夹具验证;不表示公开组件或 React Stately Color 全 API 完成。范围和限制见 [COLOR-01](component-notes.md),公共Swatch迁移见 [当前任务卡](tasks/COLOR-SWATCH.md);旧COLOR-02不再作为调度依据。 +颜色值、接受值/继承 owner、二维交互与梯度已由私有夹具验证;公共 ColorArea 迁移见 [COLOR-AREA 结果](tasks/results/COLOR-AREA.md),公共 Swatch 见 [COLOR-SWATCH](tasks/results/COLOR-SWATCH.md)。固定源 1.21.1 的实际默认值为 `#ffffff`,未指定轴按接受值空间首两个通道推断(RGB red/green,HSL/HSB hue/saturation);中文 API 简表的 saturation/brightness 与运行时不同,迁移按源码行为实现。旧COLOR-02不再作为调度依据。 ## COLOR-03 颜色输入基建 @@ -241,6 +241,12 @@ ColorField/ColorInputGroup 内部 Root/Input/前后缀、校验/关联、独立 ColorPicker/Trigger/Popover 正式组合内部已接入,共享非空 owner、现有 Popover 和单一原生提交/reset。尚无包根导出、公共 variants/六例完成声明;默认值、明确 Vue 扩展和公开待办见 [COLOR-08](component-notes.md)。 +## COLOR-AREA 公共颜色区域(2026-10-26) + +公开 ColorArea/ColorAreaRoot、ColorAreaThumb、Props/RenderProps/插槽/样式类型与 colorAreaVariants;固定源中文 7 例、API/样式参考与导航已接入。复用共享 Color/model 接受值、二维指针/键盘事务、18 个有序轴组合和既有 hv-color-area CSS;Root 输出 data-slot/color-area 与可访问组名,Thumb 输出两个本地化命名原生轴和单 Tab 入口。 + +上游 render 映射为 `as`/`asChild` 与 attrs,style 函数在模板中使用 `styleFn`;`xName`/`yName`/`form` 只提交两个轴,继承 owner 时不重复完整颜色提交。固定源默认 `#ffffff`、按接受值空间推断轴;默认指针捕获与 mouse/touch 手势、受控拒绝/重试、动态 owner、表单/reset、浅深主题和最终 tarball 的验证边界见 [任务结果](tasks/results/COLOR-AREA.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 000cc63..9dcd5d9 100644 --- a/docs/component-notes.md +++ b/docs/component-notes.md @@ -15,7 +15,13 @@ 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私有协议已有实现,公共Color/parseColor及组件家族仍待任务验收。不能把内核/夹具通过写成公共完成。共享owner、归一化通道、接受值与草稿保持同一状态源。见 [颜色决策](decisions/color-foundation.md);下一项只有用户选定后才按 [COLOR-SWATCH卡](tasks/COLOR-SWATCH.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)。 + +## COLOR-AREA(2026-10-26) + +ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复用 hv-color-area CSS 和共享二维内核;固定源中文 7 例全部迁移。Root 负责接受值、背景、指针/键盘事务与组标签,Thumb 负责定位、两个本地化命名原生轴和单 Tab 入口;两个轴的 xName/yName/form 只提交通道值,owner 的完整颜色提交不重复。 + +上游 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)。 ## 当前不投入 diff --git a/docs/status.md b/docs/status.md index 59415b8..b861dc8 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公共子集已公开;Area、Slider、Field/InputGroup、Picker组合协议仍有私有实现和回归夹具,尚未作为完整公共颜色家族发布。 -- 兼容矩阵目前84条(包含子部件与基础设施),文档有68个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。 +- ColorSwatch/ColorSwatchRoot及Color/parseColor公共子集已公开;ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复用共享颜色 owner、二维交互与固定源 7 例。Area、Slider、Field/InputGroup、Picker组合协议仍有私有实现和回归夹具;ColorField/ColorSlider/ColorPicker/ColorSwatchPicker尚未作为完整公共颜色家族发布。 +- 兼容矩阵目前85条(包含子部件与基础设施),文档有69个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。 ## 尚未完成的公共家族 -ColorArea、ColorField、ColorSlider、ColorSwatchPicker、ColorPicker,共5项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收。 +ColorField、ColorSlider、ColorSwatchPicker、ColorPicker,共4项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收。 -TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md)。RANGE-CALENDAR 结果见 [任务结果](tasks/results/RANGE-CALENDAR.md)。DATE-RANGE-PICKER 结果见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。 +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)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。 ## 当前工程边界 唯一Vue工作目录heroui-vue,一任务一分支、会话串行。b01/b02/b03已删除并解除Git登记;core内容已整合,是否保留该目录不影响运行。开发默认文档5173,playground按实际脚本;服务只在任务需要时启动,结束按用户要求停止。 -已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归97文件/1415项通过;本轮DateRangePicker新增2文件/45项,任务定向18文件/254项通过,已通过增量复核与全量回归并合入 main,见任务结果;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。 +已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归99文件/1445项通过;本轮ColorArea新增2文件/30项,任务定向12文件/173项通过;任务分支待复核与集成,结果见任务文件;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。 ## 按需入口 diff --git a/docs/upstream.md b/docs/upstream.md index 789855f..6d25af1 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -253,6 +253,14 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`circle/square`、`xs/sm/md/lg 上游 `render` 映射为 `as`/`asChild` 与原生 attrs;`style` render prop 的函数形式在 Vue 模板中改为 `styleFn`(Vue 编译器会规整保留的 `style` 函数值),普通样式仍用 `style`。默认作用域插槽接收 `{ color }`。未迁移 ColorSwatchPicker 的 `ColorSwatchContext`(该家族不在本任务范围),也没有运行时依赖相邻 React 仓库。 +## COLOR-AREA ColorArea(2026-10-26) + +固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/color-area/{index.ts,color-area.tsx}`、`packages/styles/components/color-area.css`、`packages/styles/src/components/color-area/color-area.styles.ts`,中文 `(colors)/color-area.mdx` 与 `demos/cn/color-area` 全部 7 例(basic/with-dots/space-and-channels/disabled/controlled/render-function/custom-styles)。 + +CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`showDots`、`hv-color-area`/`__thumb` 与 data-disabled/focus-visible/dragging 保持基线。Vue 侧复用本库 `components/color/{value,model,area,gradient}.ts` 的不可变 Color、共享 owner、二维事务与梯度,不包装 React Aria。固定源 `react-stately@3.9.0` 的 `useColorAreaState` 默认 `#ffffff`,`getColorSpaceAxes` 未指定轴时取空间首个剩余通道(RGB red/green,HSL/HSB hue/saturation);本库按该运行时行为实现,未照抄中文 API 简表的 saturation/brightness。上游 `render` 映射为 `as`/`asChild`(Root)与 `as`(Thumb),style 函数在模板中使用 `styleFn`。 + +ColorArea 的 `xName`/`yName`/`form` 只生成两个原生 range 输入;共享 owner 的完整颜色提交仍归 owner,未在子项增加重复隐藏颜色或 reset 所有权。默认值、受控拒绝/重试、动态 owner、locale/RTL、readOnly 扩展、真实浏览器和 tarball 证据见 [任务结果](tasks/results/COLOR-AREA.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 4648aec..a1a5e7b 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -59,3 +59,16 @@ Playground 5174 嵌套 Modal 场景:面板在 Modal 上方可见/可操作,E 差异与限制:固定源 `slot="start"/"end"` 改为 `endpoint` prop;格式选项的 `w-full` 弹层在 Portal 自动宽度下映射为 252px 日历 + 24px 内边距;字段编辑无法显示毫秒,保留端点先前精度。未开展 SSR/水合/Nuxt、逐像素、完整读屏/真机矩阵;触屏长按拖选仍是 RangeCalendar 已知缺口。详情见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。 首轮复核 R1–R3 已修复:locale 历法显示与提交历法分离(Hebrew 下显示 5784、编辑后 change 仍为 Gregorian);动态 `endpoint` 同时切换显示与编辑适配器(start→end 后 ArrowUp 只改 end);只读/禁用时 `setTimeRange` 不再写空值时间草稿。复核反例与补充回归计入 date-range-picker 33 项;全量 97 文件/1415 项、定向 18 文件/254 项、类型检查、文档构建与五契约 tarball 检查通过。修复以行为测试核销,未新增浏览器专项。 + +## COLOR-AREA(2026-10-26,客户端) + +公开 ColorArea/ColorAreaRoot、ColorAreaThumb、colorAreaVariants、Props/RenderProps/插槽/样式类型;固定源中文 7 例全部迁移,预览/复制/高亮共用同一 SFC。新增 20 项公共行为测试与 10 项文档/示例测试;修正共享颜色轴推断为固定源运行时行为(`#ffffff` 默认,RGB red/green,HSL/HSB hue/saturation),既有私有夹具显式保留 saturation×brightness。 + +- `pnpm test`:99 文件/1445 项客户端回归通过。 +- 任务定向 12 文件/173 项通过:color-area 两个新文件、color-foundation、color-swatch、picker composition/protocol、slider/input/field 基础及 regressions/color。 +- `pnpm typecheck`、`pnpm build:docs`:通过;文档构建保留已有大 chunk 提示,不是组件 SSR 验收。 +- `node scripts/check-package.mjs color-area color-swatch`:最终 tarball 独立安装、ESM/CSS/variants 与 strict NodeNext/bundler 类型正反例通过;旧契约仅移除 ColorArea 的“暂不公开”断言。 + +真实文档 5173(Chrome,1280×900 CSS 视口):7 个预览顺序正确;基础/定位点/禁用 224×224,自定义 176×176、圆角 24px,Thumb 16px(拖动/自定义 20px);RGB screen 混合与 HSL/HSB 图层、showDots、当前色变量、浅深主题和焦点环均实际检查。触屏拖拽在区内/拖出边界均保持 pointer capture,pointerup 提交并清理;releasePointerCapture 后下一次指针事件取消拖动且不回写旧手势;pointercancel 清理且保留接受值;禁用区域触摸不改变值。键盘 ArrowRight/ArrowUp 更新对应轴、切换单 Tab 入口并显示 3px 焦点轮廓与焦点阴影;控制台无新增 warn/error。 + +CDP 合成鼠标事件本身不保持 pointer capture(中性 div 复现),因此鼠标区外拖动未作为浏览器通过证据,鼠标捕获仍由单元夹具的 `setPointerCapture` 断言覆盖;未开展 SSR/水合/Nuxt、逐像素、完整读屏或真机矩阵。详情见 [任务结果](tasks/results/COLOR-AREA.md)。 diff --git a/packages/styles/index.css b/packages/styles/index.css index 4bd5712..9772517 100644 --- a/packages/styles/index.css +++ b/packages/styles/index.css @@ -173,9 +173,10 @@ @import "./components/calendar-year-picker.css" layer(components); -/* Private color interaction foundation; public components are not exported yet. */ +/* Public ColorArea (COLOR-AREA). */ @import "./components/color-area.css" layer(components); +/* Private color interaction foundation; remaining color families are not public. */ @import "./components/color-slider.css" layer(components); @import "./components/color-field.css" layer(components); diff --git a/packages/styles/src/index.ts b/packages/styles/src/index.ts index 4f91002..95d96b3 100644 --- a/packages/styles/src/index.ts +++ b/packages/styles/src/index.ts @@ -1828,6 +1828,27 @@ export const colorSwatchVariants = tv({ export type ColorSwatchVariants = VariantProps; +/** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */ +export const colorAreaVariants = tv({ + defaultVariants: { + showDots: false, + }, + slots: { + base: "hv-color-area", + thumb: "hv-color-area__thumb", + }, + variants: { + showDots: { + false: {}, + true: { + base: "hv-color-area--show-dots", + }, + }, + }, +}); + +export type ColorAreaVariants = 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/ColorArea.vue b/packages/vue/src/components/color-area/ColorArea.vue new file mode 100644 index 0000000..91349b1 --- /dev/null +++ b/packages/vue/src/components/color-area/ColorArea.vue @@ -0,0 +1,243 @@ + + + + + + + diff --git a/packages/vue/src/components/color-area/ColorAreaThumb.vue b/packages/vue/src/components/color-area/ColorAreaThumb.vue new file mode 100644 index 0000000..2561acd --- /dev/null +++ b/packages/vue/src/components/color-area/ColorAreaThumb.vue @@ -0,0 +1,155 @@ + + + + + + + + diff --git a/packages/vue/src/components/color-area/context.ts b/packages/vue/src/components/color-area/context.ts new file mode 100644 index 0000000..5708260 --- /dev/null +++ b/packages/vue/src/components/color-area/context.ts @@ -0,0 +1,43 @@ +import { + inject, + type ComputedRef, + type InjectionKey, + type ShallowRef, +} from "vue"; +import type { ColorState } from "../color/model"; +import type { ColorAreaControl, ColorAreaOptions } from "../color/area"; + +export interface ColorAreaElements { + root: ShallowRef; + thumb: ShallowRef; + focusX: ShallowRef; + focusY: ShallowRef; +} + +export interface ColorAreaStyles { + base: () => string; + thumb: () => string; +} + +export interface ColorAreaContext { + elements: ColorAreaElements; + state: ColorState; + control: ColorAreaControl; + styles: ComputedRef; + focusVisible: ShallowRef; + disabled: ComputedRef; + readOnly: ComputedRef; + locale: ComputedRef; + dir: ComputedRef<"ltr" | "rtl">; + options: ColorAreaOptions; +} + +export const colorAreaKey: InjectionKey = + Symbol("hv-color-area"); + +export function useColorAreaContext() { + const context = inject(colorAreaKey, undefined); + if (!context) + throw new Error("ColorAreaThumb must be rendered inside ColorArea."); + return context; +} diff --git a/packages/vue/src/components/color-area/labels.ts b/packages/vue/src/components/color-area/labels.ts new file mode 100644 index 0000000..fa25a05 --- /dev/null +++ b/packages/vue/src/components/color-area/labels.ts @@ -0,0 +1,35 @@ +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: "明度", +}; + +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-area/types.ts b/packages/vue/src/components/color-area/types.ts new file mode 100644 index 0000000..0fc2c11 --- /dev/null +++ b/packages/vue/src/components/color-area/types.ts @@ -0,0 +1,51 @@ +import type { StyleValue, VNodeChild } from "vue"; +import type { Color, ColorAxisChannel, ColorSpace } from "../color/value"; + +/** Values shared by the public style functions and render state. */ +export interface ColorAreaRenderProps { + /** Display color for the current space; defaults to the accepted value. */ + color: Color; + space: ColorSpace; + x: ColorAxisChannel; + y: ColorAxisChannel; +} + +export interface ColorAreaThumbRenderProps extends ColorAreaRenderProps { + /** Accepted axis positions in the 0–1 content box, before RTL mapping. */ + percent: { x: number; y: number }; + isDragging: boolean; + isDisabled: boolean; + isReadOnly: boolean; +} + +/** + * Function form of the upstream `style` render prop. Vue's template compiler + * reserves `style` for ordinary bindings, so templates pass the function + * through `styleFn`; render functions may pass it directly. + */ +export type ColorAreaStyleFn = ( + renderProps: ColorAreaRenderProps, +) => StyleValue | undefined; + +/** Vue style binding (object/array/string) or the upstream style function. */ +export type ColorAreaStyle = StyleValue | ColorAreaStyleFn; + +export type ColorAreaThumbStyleFn = ( + renderProps: ColorAreaThumbRenderProps, +) => StyleValue | undefined; + +export type ColorAreaThumbStyle = StyleValue | ColorAreaThumbStyleFn; + +/** Default slot; render one ColorAreaThumb per area. */ +export interface ColorAreaSlots { + default?: () => VNodeChild; +} + +/** + * State exposed by the root instance. Refs are unwrapped on the public + * instance proxy, matching the ColorSwatch `element` convention. + */ +export interface ColorAreaExpose { + element: HTMLElement | null; + color: Color | null; +} diff --git a/packages/vue/src/components/color/area.ts b/packages/vue/src/components/color/area.ts index f2cd3b7..905a87f 100644 --- a/packages/vue/src/components/color/area.ts +++ b/packages/vue/src/components/color/area.ts @@ -47,7 +47,7 @@ export function useColorArea( const axes = computed(() => colorAxes( state.value.value ?? - new Color({ space: "hsb", h: 0, s: 100, b: 100, alpha: 1 }), + new Color({ space: "rgb", r: 255, g: 255, b: 255, alpha: 1 }), props.colorSpace, props.xChannel, props.yChannel, @@ -156,6 +156,7 @@ export function useColorArea( // Capture the stable area, never the transient child that received pointerdown. owner.setPointerCapture?.(event.pointerId); event.preventDefault(); + focusedAxis.value = "x"; thumb.value?.focus({ preventScroll: true }); if (!inThumb) update(point); } @@ -323,3 +324,4 @@ export function useColorArea( blur: () => stop(true), }; } +export type ColorAreaControl = ReturnType; diff --git a/packages/vue/src/components/color/value.ts b/packages/vue/src/components/color/value.ts index 5fbe631..15ed7a1 100644 --- a/packages/vue/src/components/color/value.ts +++ b/packages/vue/src/components/color/value.ts @@ -311,33 +311,16 @@ export function colorAxes( x?: ColorAxisChannel, y?: ColorAxisChannel, ) { - const working = - space ?? - (x === "red" || - x === "green" || - x === "blue" || - y === "red" || - y === "green" || - y === "blue" - ? "rgb" - : x === "lightness" || y === "lightness" - ? "hsl" - : x === "brightness" || y === "brightness" - ? "hsb" - : color.getColorSpace() === "rgb" - ? "hsb" - : color.getColorSpace()); + // Matches the fixed source: the value's own space wins when `colorSpace` is + // omitted, and an omitted axis takes the first remaining channel in that + // space (RGB red/green, HSL/HSB hue/saturation). + const working = space ?? color.getColorSpace(); const native = channels[working]; - const xChannel = x ?? (working === "rgb" ? "red" : "saturation"); - const yChannel = - y ?? - native.find( - (c) => - c !== xChannel && - (c === "brightness" || c === "lightness" || c === "green"), - ) ?? - native.find((c) => c !== xChannel)!; + const xChannel = x ?? native.find((channel) => channel !== y); + const yChannel = y ?? native.find((channel) => channel !== xChannel); if ( + !xChannel || + !yChannel || xChannel === yChannel || !native.includes(xChannel) || !native.includes(yChannel) diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 15860df..8dfa1fc 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1136,6 +1136,26 @@ export { type AutocompleteVariants, } from "@heroui-vue/styles"; +export { default as ColorArea } from "./components/color-area/ColorArea.vue"; +export { default as ColorAreaRoot } from "./components/color-area/ColorArea.vue"; +export { default as ColorAreaThumb } from "./components/color-area/ColorAreaThumb.vue"; +export { colorAreaVariants, type ColorAreaVariants } from "@heroui-vue/styles"; +export type { + ColorAreaExpose, + ColorAreaRenderProps, + ColorAreaSlots, + ColorAreaStyle, + ColorAreaStyleFn, + ColorAreaThumbRenderProps, + ColorAreaThumbStyle, + ColorAreaThumbStyleFn, +} from "./components/color-area/types"; +export type { + ColorAreaProps, + ColorAreaRootProps, + ColorAreaThumbProps, +} from "./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/packages/vue/src/types.ts b/packages/vue/src/types.ts index 4ea04d5..33b2794 100644 --- a/packages/vue/src/types.ts +++ b/packages/vue/src/types.ts @@ -911,6 +911,11 @@ export type AutocompleteFilterProps = InstanceType< import type ColorSwatch from "./components/color-swatch/ColorSwatch.vue"; export type ColorSwatchProps = InstanceType["$props"]; export type ColorSwatchRootProps = ColorSwatchProps; +import type ColorArea from "./components/color-area/ColorArea.vue"; +import type ColorAreaThumb from "./components/color-area/ColorAreaThumb.vue"; +export type ColorAreaProps = InstanceType["$props"]; +export type ColorAreaRootProps = ColorAreaProps; +export type ColorAreaThumbProps = InstanceType["$props"]; export type { ColorSwatchRenderProps, ColorSwatchSlots, diff --git a/packages/vue/tests/fixtures/ColorAreaFoundation.vue b/packages/vue/tests/fixtures/ColorAreaFoundation.vue index e3eaa70..bf3e8dc 100644 --- a/packages/vue/tests/fixtures/ColorAreaFoundation.vue +++ b/packages/vue/tests/fixtures/ColorAreaFoundation.vue @@ -11,7 +11,12 @@ import { import { colorAreaBackground } from "../../src/components/color/gradient"; import { parseColor, type Color } from "../../src/components/color/value"; defineOptions({ inheritAttrs: false }); -const props = defineProps(); +const props = withDefaults(defineProps(), { + // The private picker proof uses the common saturation × brightness square; + // public ColorArea inference follows the fixed source's channel order. + xChannel: "saturation", + yChannel: "brightness", +}); const emit = defineEmits<{ "update:modelValue": [Color | null]; change: [Color | null]; diff --git a/tests/color-area-demos.test.ts b/tests/color-area-demos.test.ts new file mode 100644 index 0000000..84c9787 --- /dev/null +++ b/tests/color-area-demos.test.ts @@ -0,0 +1,197 @@ +import { afterEach, describe, expect, it } from "vitest"; +import { mount, flushPromises } from "@vue/test-utils"; +import { readFileSync } from "node:fs"; +import { ColorArea, Select, parseColor } from "../packages/vue/src"; +import Basic from "../apps/docs/demos/color-area-basic.vue"; +import WithDots from "../apps/docs/demos/color-area-with-dots.vue"; +import SpaceAndChannels from "../apps/docs/demos/color-area-space-and-channels.vue"; +import Disabled from "../apps/docs/demos/color-area-disabled.vue"; +import Controlled from "../apps/docs/demos/color-area-controlled.vue"; +import RenderFunction from "../apps/docs/demos/color-area-render-function.vue"; +import CustomStyles from "../apps/docs/demos/color-area-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 root = (w: ReturnType) => + w.get("[data-slot=color-area]"); +const thumb = (w: ReturnType) => + w.get("[data-slot=color-area-thumb]"); +const axis = (w: ReturnType, name: "x" | "y") => + w.get(`[data-axis="${name}"]`); + +const previews = [ + "basic", + "with-dots", + "space-and-channels", + "disabled", + "controlled", + "render-function", + "custom-styles", +]; + +describe("ColorArea documentation demos", () => { + it("keeps the seven pinned previews in the upstream order", () => { + const document = readFileSync("apps/docs/components/color-area.md", "utf8"); + const names = [ + ...document.matchAll(/ match[1]); + expect(names).toEqual(previews); + for (const name of previews) { + const source = readFileSync( + `apps/docs/demos/color-area-${name}.vue`, + "utf8", + ); + expect(source).toContain(""); + expect(source).toContain('from "@heroui-vue/components"'); + expect(source).not.toContain("className"); + } + }); + + it("renders the basic color area from the baseline default value", () => { + const w = render(Basic); + expect(root(w).classes()).toContain("hv-color-area"); + expect(axis(w, "x").element.value).toBe("116"); + expect(axis(w, "y").element.value).toBe("52"); + expect(axis(w, "x").attributes("aria-label")).toBe("Red"); + expect(axis(w, "y").attributes("aria-label")).toBe("Green"); + expect(thumb(w).element.style.left).toBe(`${(116 / 255) * 100}%`); + expect( + root(w).element.style.getPropertyValue("--color-area-background"), + ).toContain("linear-gradient"); + }); + + it("applies the dots overlay variant", () => { + const w = render(WithDots); + expect(root(w).classes()).toContain("hv-color-area--show-dots"); + expect(axis(w, "x").element.value).toBe("200"); + expect(axis(w, "y").element.value).toBe("100"); + }); + + it("switches color space and axes in the space-and-channels example", async () => { + const w = render(SpaceAndChannels); + const selects = w.findAllComponents(Select); + expect(selects).toHaveLength(3); + expect(w.findAll("[data-slot=color-area]")).toHaveLength(1); + expect(axis(w, "x").attributes("aria-label")).toBe("Saturation"); + expect(axis(w, "y").attributes("aria-label")).toBe("Brightness"); + expect(axis(w, "x").element.value).toBe("58"); + expect(axis(w, "y").element.value).toBe("93"); + expect(w.text()).toContain("hsb(219, 58%, 93%)"); + + await selects[0]!.vm.$emit("update:modelValue", "rgb"); + await flushPromises(); + expect(axis(w, "x").attributes("aria-label")).toBe("Blue"); + expect(axis(w, "y").attributes("aria-label")).toBe("Green"); + expect(w.text()).toMatch(/rgb\(/); + + await w.findAllComponents(Select)[1]!.vm.$emit("update:modelValue", "red"); + await flushPromises(); + expect(axis(w, "x").attributes("aria-label")).toBe("Red"); + expect(axis(w, "x").attributes("max")).toBe("255"); + }); + + it("disables both axes and pointer interaction", async () => { + const w = render(Disabled); + expect(root(w).attributes("data-disabled")).toBe("true"); + expect(axis(w, "x").element.disabled).toBe(true); + expect(axis(w, "y").element.disabled).toBe(true); + await axis(w, "x").trigger("keydown", { key: "ArrowRight" }); + expect(w.findComponent(ColorArea).emitted("change")).toBeUndefined(); + }); + + it("keeps the controlled swatch and hex output in sync", async () => { + const w = render(Controlled); + const swatch = w.get("[data-slot=color-swatch]"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("#9B80FF").toString("css"), + ); + expect(axis(w, "x").element.value).toBe("155"); + expect(axis(w, "y").element.value).toBe("128"); + await axis(w, "x").trigger("keydown", { key: "ArrowRight" }); + await axis(w, "x").trigger("keyup", { key: "ArrowRight" }); + await flushPromises(); + expect(w.text()).toContain("#9C80FF"); + expect(swatch.element.style.backgroundColor).toBe( + parseColor("#9C80FF").toString("css"), + ); + }); + + it("maps the render-function demo to asChild, as and native attributes", async () => { + const w = render(RenderFunction); + const area = root(w); + expect(area.attributes("data-custom")).toBe("slider"); + expect(area.element.tagName).toBe("DIV"); + expect(area.classes()).toContain("hv-color-area"); + expect(area.attributes("role")).toBe("group"); + const handle = thumb(w); + expect(handle.attributes("data-custom")).toBe("thumb"); + expect(handle.element.tagName).toBe("SPAN"); + expect(handle.classes()).toContain("hv-color-area__thumb"); + expect(axis(w, "x").element.value).toBe("116"); + + await axis(w, "x").trigger("keydown", { key: "ArrowRight" }); + await axis(w, "x").trigger("keyup", { key: "ArrowRight" }); + await flushPromises(); + expect(axis(w, "x").element.value).toBe("117"); + }); + + it("merges the custom style classes onto the real parts", () => { + const w = render(CustomStyles); + const area = root(w); + const handle = thumb(w); + for (const name of ["size-44", "rounded-3xl", "hv-color-area"]) { + expect(area.classes()).toContain(name); + } + for (const name of [ + "size-5", + "rounded-full", + "border-4", + "border-white", + "hv-color-area__thumb", + ]) { + expect(handle.classes()).toContain(name); + } + }); + + it("documents the Vue API, adaptation range and related state", () => { + const document = readFileSync("apps/docs/components/color-area.md", "utf8"); + expect(document).toContain("title: ColorArea 颜色区域"); + expect(document).toContain("ColorAreaThumb"); + expect(document).toContain("`colorSpace`"); + expect(document).toContain("`xChannel`"); + expect(document).toContain("`yChannel`"); + expect(document).toContain("`showDots`"); + expect(document).toContain("`asChild`"); + expect(document).toContain("`styleFn`"); + expect(document).toContain("`isReadOnly`"); + expect(document).toContain("`xName` / `yName`"); + expect(document).toContain("ColorAreaRenderProps"); + expect(document).toContain("changeEnd"); + expect(document).not.toMatch(/\|\s*`className`\s*\|/); + expect(document).not.toContain("### ColorArea.Thumb"); + expect(document).toContain("ColorField"); + expect(document).toContain("仍为私有颜色协议"); + }); + + it("adds ColorArea to the shared navigation before ColorSwatch", () => { + const navigation = readFileSync( + "apps/docs/.vitepress/theme/navigation.ts", + "utf8", + ); + const area = navigation.indexOf("ColorArea 颜色区域"); + const swatch = navigation.indexOf("ColorSwatch 颜色色块"); + expect(area).toBeGreaterThan(-1); + expect(swatch).toBeGreaterThan(area); + expect(navigation).toContain('url: "/components/color-area"'); + expect(navigation).toContain('category: "colors"'); + }); +}); diff --git a/tests/color-area.test.ts b/tests/color-area.test.ts new file mode 100644 index 0000000..6db2d02 --- /dev/null +++ b/tests/color-area.test.ts @@ -0,0 +1,620 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { mount, flushPromises } from "@vue/test-utils"; +import { defineComponent, ref, shallowRef } from "vue"; +import { + ColorArea, + ColorAreaRoot, + ColorAreaThumb, + ColorSwatch, + ConfigProvider, + colorAreaVariants, + parseColor, + type Color, +} from "../packages/vue/src"; +import ColorPickerFoundation 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 area( + props: Record = {}, + template = '', + setup: () => Record = () => ({}), +) { + return render( + defineComponent({ + components: { ColorArea, ColorAreaThumb }, + 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-area]"); +const thumb = (w: ReturnType) => + w.get("[data-slot=color-area-thumb]"); +const x = (w: ReturnType) => + w.get('[data-axis="x"]'); +const y = (w: ReturnType) => + w.get('[data-axis="y"]'); +const axisValue = (w: ReturnType, axis: "x" | "y") => + w.get(`[data-axis="${axis}"]`).element.value; +const thumbColor = (w: ReturnType) => + thumb(w).element.style.getPropertyValue("--color-area-thumb-color"); +const emitted = (w: ReturnType, name: string) => + w.findComponent(ColorArea).emitted(name) ?? []; +async function key( + w: ReturnType, + name: string, + up = true, + extra = {}, + axis: "x" | "y" = "x", +) { + const input = w.get(`[data-axis="${axis}"]`); + await input.trigger("keydown", { key: name, ...extra }); + if (up) await input.trigger("keyup", { key: name, ...extra }); + await flushPromises(); +} +function geometry( + w: ReturnType, + selector = "[data-slot=color-area]", +) { + const node = w.get(selector).element; + let captured: number | undefined; + Object.defineProperties(node, { + offsetWidth: { get: () => 224, configurable: true }, + offsetHeight: { get: () => 224, configurable: true }, + }); + vi.spyOn(node, "getBoundingClientRect").mockReturnValue({ + left: 0, + top: 0, + width: 224, + height: 224, + right: 224, + bottom: 224, + x: 0, + y: 0, + toJSON: () => ({}), + }); + 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", + isPrimary: true, + button: 0, + clientX: 112, + clientY: 112, + ...extra, + }); + node.dispatchEvent(event); + await flushPromises(); + return event; +} + +describe("ColorArea public contract", () => { + it("renders the baseline root, thumb, two axes and background variable", () => { + const w = area({ defaultValue: "hsl(200, 100%, 50%)" }); + expect(ColorAreaRoot).toBe(ColorArea); + const node = root(w); + expect(node.attributes("role")).toBe("group"); + expect(node.attributes("dir")).toBe("ltr"); + expect(node.classes()).toEqual(expect.arrayContaining(["hv-color-area"])); + expect(node.classes()).not.toContain("hv-color-area--show-dots"); + expect( + node.element.style.getPropertyValue("--color-area-background"), + ).toContain("linear-gradient"); + expect(node.element.style.backgroundBlendMode).toBe("normal"); + + const handle = thumb(w); + expect(handle.classes()).toContain("hv-color-area__thumb"); + expect(handle.element.tagName).toBe("DIV"); + expect(parseFloat(handle.element.style.left)).toBeCloseTo( + (200 / 360) * 100, + ); + expect(handle.element.style.top).toBe("0%"); + expect(handle.element.style.transform).toBe("translate(-50%, -50%)"); + expect( + handle.element.style.getPropertyValue("--color-area-thumb-color"), + ).toBe(parseColor("hsl(200, 100%, 50%)").toString("css")); + + expect(x(w).attributes("type")).toBe("range"); + expect(x(w).attributes("step")).toBe("any"); + expect(x(w).attributes("aria-label")).toBe("Hue"); + expect(x(w).attributes("aria-valuetext")).toBe("200°"); + expect(x(w).attributes("min")).toBe("0"); + expect(x(w).attributes("max")).toBe("360"); + expect(x(w).attributes("tabindex")).toBe("0"); + expect(y(w).attributes("aria-label")).toBe("Saturation"); + expect(y(w).attributes("aria-orientation")).toBe("vertical"); + expect(y(w).attributes("tabindex")).toBe("-1"); + expect(x(w).element.value).toBe("200"); + expect(y(w).element.value).toBe("100"); + }); + + it("maps showDots to the variant classes", () => { + const w = area({ defaultValue: "#ff0000", showDots: true }); + expect(root(w).classes()).toContain("hv-color-area--show-dots"); + expect(colorAreaVariants({ showDots: true }).base()).toContain( + "hv-color-area--show-dots", + ); + expect(colorAreaVariants().thumb()).toBe("hv-color-area__thumb"); + }); + + it("updates an uncontrolled area through the native axes and commits once", async () => { + const w = area({ + defaultValue: "hsb(240, 50%, 50%)", + xChannel: "saturation", + yChannel: "brightness", + }); + await key(w, "ArrowRight", false); + expect(x(w).element.value).toBe("51"); + expect(thumb(w).element.style.left).toBe("51%"); + expect(emitted(w, "update:modelValue")).toHaveLength(1); + expect(emitted(w, "change")).toHaveLength(1); + expect(emitted(w, "changeEnd")).toHaveLength(0); + await x(w).trigger("keyup", { key: "ArrowRight" }); + expect(emitted(w, "changeEnd")).toHaveLength(1); + const value = emitted(w, "changeEnd")[0]![0] as Color; + expect(value.getChannelValue("saturation")).toBe(51); + expect(value.getChannelValue("alpha")).toBe(1); + + await key(w, "ArrowUp", true, {}, "y"); + expect(y(w).element.value).toBe("51"); + expect(x(w).attributes("tabindex")).toBe("-1"); + expect(y(w).attributes("tabindex")).toBe("0"); + expect(document.activeElement).toBe(y(w).element); + }); + + it("keeps the accepted value on controlled rejection and allows retries", async () => { + const value = shallowRef(parseColor("hsb(240,50%,50%)")); + const w = render( + defineComponent({ + components: { ColorArea, ColorAreaThumb }, + setup: () => ({ value }), + template: ``, + }), + ); + for (let i = 0; i < 2; i++) await key(w, "ArrowRight"); + expect(emitted(w, "change")).toHaveLength(2); + expect( + (emitted(w, "change")[1]![0] as Color).getChannelValue("saturation"), + ).toBe(51); + expect(x(w).element.value).toBe("50"); + expect(thumb(w).element.style.left).toBe("50%"); + + value.value = parseColor("hsb(240,80%,70%)"); + await flushPromises(); + expect(x(w).element.value).toBe("80"); + expect(y(w).element.value).toBe("70"); + expect(thumb(w).element.style.left).toBe("80%"); + expect(parseFloat(thumb(w).element.style.top)).toBeCloseTo(30); + }); + + it("commits pointer drags once and cleans up cancellations", async () => { + const w = area({ + defaultValue: "hsb(240, 50%, 50%)", + xChannel: "saturation", + yChannel: "brightness", + }); + const node = geometry(w); + await pointer(node, "pointerdown", { clientX: 112, clientY: 112 }); + await pointer(node, "pointermove", { clientX: 168, clientY: 112 }); + await pointer(node, "pointerup", { clientX: 168, clientY: 112 }); + expect(node.setPointerCapture).toHaveBeenCalledWith(1); + expect(node.releasePointerCapture).toHaveBeenCalledWith(1); + expect(emitted(w, "change")).toHaveLength(1); + expect(emitted(w, "changeEnd")).toHaveLength(1); + expect( + (emitted(w, "changeEnd")[0]![0] as Color).getChannelValue("saturation"), + ).toBe(75); + + const cancel = area({ + colorSpace: "hsb", + xChannel: "saturation", + yChannel: "brightness", + }); + const cancelled = geometry(cancel); + await pointer(cancelled, "pointerdown"); + await pointer(cancelled, "pointermove", { clientX: 168 }); + await pointer(cancelled, "pointercancel"); + expect(emitted(cancel, "changeEnd")).toHaveLength(0); + expect(cancelled.releasePointerCapture).toHaveBeenCalledWith(1); + }); + + it("honors disabled and read-only permissions", async () => { + const disabled = area({ isDisabled: true, defaultValue: "#ff0000" }); + expect(root(disabled).attributes("data-disabled")).toBe("true"); + expect(thumb(disabled).attributes("data-disabled")).toBe("true"); + expect(x(disabled).attributes()).toHaveProperty("disabled"); + const node = geometry(disabled); + await pointer(node, "pointerdown"); + await key(disabled, "ArrowRight"); + expect(emitted(disabled, "change")).toHaveLength(0); + expect(node.setPointerCapture).not.toHaveBeenCalled(); + + const readOnly = area({ isReadOnly: true, defaultValue: "#ff0000" }); + expect(root(readOnly).attributes("data-readonly")).toBe("true"); + expect(x(readOnly).attributes("aria-readonly")).toBe("true"); + expect(x(readOnly).attributes()).not.toHaveProperty("disabled"); + await key(readOnly, "ArrowRight"); + expect(emitted(readOnly, "change")).toHaveLength(0); + }); + + it("supports channels, color spaces and locale-aware labels", () => { + const rgb = area({ + colorSpace: "rgb", + defaultValue: "rgb(10, 20, 30)", + }); + expect(x(rgb).attributes("aria-label")).toBe("Red"); + expect(y(rgb).attributes("aria-label")).toBe("Green"); + expect(x(rgb).attributes("max")).toBe("255"); + expect(x(rgb).element.value).toBe("10"); + expect(thumb(rgb).element.style.left).toBe(`${(10 / 255) * 100}%`); + + const zh = render( + defineComponent({ + components: { ConfigProvider, ColorArea, ColorAreaThumb }, + template: ` + + + + `, + }), + ); + expect(root(zh).attributes("aria-label")).toBe("颜色区域"); + expect(root(zh).attributes("dir")).toBe("rtl"); + expect(x(zh).attributes("aria-label")).toBe("饱和度"); + expect(y(zh).attributes("aria-label")).toBe("明度"); + expect(x(zh).attributes("aria-valuetext")).toBe("25%"); + expect(thumb(zh).element.style.left).toBe("75%"); + expect( + root(zh).element.style.getPropertyValue("--color-area-background"), + ).toContain("to left"); + }); + + it("supports as, asChild, class, style, styleFn and exposed state", () => { + const styleFn = vi.fn(({ color }: { color: Color }) => ({ + outline: `1px solid ${color.toString("hex")}`, + })); + const w = area( + {}, + ` + + `, + () => ({ styleFn }), + ); + const node = root(w); + expect(node.element.tagName).toBe("DIV"); + expect(node.attributes("data-custom")).toBe("area"); + expect(node.attributes("role")).toBe("group"); + expect(node.classes()).toContain("hv-color-area"); + expect(node.element.style.opacity).toBe("0.9"); + expect(node.element.style.outline).toBe("1px solid #FF0000"); + expect(styleFn).toHaveBeenCalled(); + expect(thumb(w).element.tagName).toBe("SPAN"); + expect(thumb(w).attributes("data-custom")).toBe("thumb"); + const exposed = w.vm.$refs.areaRef as { + element: HTMLElement; + color: Color; + }; + expect(exposed.element).toBe(node.element); + expect(exposed.color.toString("hex")).toBe("#FF0000"); + }); + + it("keeps one Tab entry and restores focused axes", async () => { + const w = area({ defaultValue: "hsb(240,50%,50%)" }); + expect(x(w).attributes("tabindex")).toBe("0"); + expect(y(w).attributes("tabindex")).toBe("-1"); + await key(w, "ArrowUp", true, {}, "x"); + expect(document.activeElement).toBe(y(w).element); + expect(y(w).attributes("tabindex")).toBe("0"); + expect(x(w).attributes("tabindex")).toBe("-1"); + await key(w, "ArrowRight", true, {}, "y"); + expect(document.activeElement).toBe(x(w).element); + expect(x(w).attributes("tabindex")).toBe("0"); + }); + + it("keeps the thumb grab offset and cleans up when disabled mid-drag", async () => { + const disabled = ref(false); + const w = area( + {}, + ``, + () => ({ disabled }), + ); + const node = geometry(w); + await pointer(thumb(w).element, "pointerdown", { + clientX: 115, + clientY: 112, + }); + expect(thumb(w).attributes("data-dragging")).toBe("true"); + await pointer(node, "pointermove", { clientX: 137.4, clientY: 112 }); + expect( + (emitted(w, "change")[0]![0] as Color).getChannelValue("saturation"), + ).toBeCloseTo(60); + disabled.value = true; + await flushPromises(); + await pointer(node, "pointerup", { clientX: 137.4 }); + expect(emitted(w, "changeEnd")).toHaveLength(0); + expect(node.releasePointerCapture).toHaveBeenCalledWith(1); + expect(thumb(w).attributes("data-dragging")).toBeUndefined(); + }); + + it("cancels stale keyboard transactions after an external replacement", async () => { + const value = shallowRef(parseColor("hsb(240,50%,50%)")); + const w = render( + defineComponent({ + components: { ColorArea, ColorAreaThumb }, + setup: () => ({ value }), + template: ``, + }), + ); + await key(w, "ArrowRight", false); + value.value = parseColor("hsb(90,25%,75%)"); + await flushPromises(); + await x(w).trigger("keyup", { key: "ArrowRight" }); + expect(emitted(w, "changeEnd")).toHaveLength(0); + expect(x(w).element.value).toBe("25"); + }); + + it("honors consumer cancellation of keyboard and pointer defaults", async () => { + const w = area( + {}, + ` + + `, + ); + const node = geometry(w); + await key(w, "ArrowRight"); + await pointer(node, "pointerdown"); + expect(emitted(w, "change")).toHaveLength(0); + expect(node.setPointerCapture).not.toHaveBeenCalled(); + }); + + it("submits and resets the two named axes, including an external form", async () => { + const w = area( + {}, + ` + + `, + ); + await key(w, "ArrowUp", true, {}, "y"); + const form = w.get("form").element as HTMLFormElement; + expect(new FormData(form).get("s")).toBe("50"); + expect(new FormData(form).get("b")).toBe("51"); + form.reset(); + await flushPromises(); + expect(x(w).element.value).toBe("50"); + expect(y(w).element.value).toBe("50"); + + const external = area( + {}, + ` + + + `, + ); + const outside = external.get("#external-area").element as HTMLFormElement; + await key(external, "ArrowRight"); + expect(new FormData(outside).get("s")).toBe("51"); + outside.reset(); + await flushPromises(); + expect(x(external).element.value).toBe("50"); + }); + + it("shares the nearest color owner, supports overrides and restores inheritance", async () => { + const override = shallowRef>({}); + const w = render( + defineComponent({ + components: { + Picker: ColorPickerFoundation, + ColorArea, + ColorAreaThumb, + ColorSwatch, + }, + setup: () => ({ override }), + template: ` + + + `, + }), + ); + const picker = w.findComponent(ColorPickerFoundation); + const swatch = () => + w.get("[data-owner-swatch]").element.style.backgroundColor; + expect(x(w).element.value).toBe("50"); + expect(swatch()).toBe(parseColor("hsb(240,50%,50%)").toString("css")); + + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(1); + expect(x(w).element.value).toBe("51"); + expect(swatch()).toBe(parseColor("hsb(240,51%,50%)").toString("css")); + + override.value = { modelValue: "hsb(10,20%,30%)" }; + await flushPromises(); + expect(x(w).element.value).toBe("20"); + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(1); + expect(x(w).element.value).toBe("20"); + + override.value = {}; + await flushPromises(); + expect(x(w).element.value).toBe("51"); + await key(w, "ArrowRight"); + expect(picker.emitted("change")).toHaveLength(2); + expect( + new FormData(w.get("form").element as HTMLFormElement).getAll("color"), + ).toHaveLength(1); + }); + + it("supports thumb style functions and preserves ordinary styles", () => { + const styleFn = vi.fn( + ({ percent }: { percent: { x: number; y: number } }) => ({ + opacity: percent.x, + }), + ); + const w = area( + {}, + ` + + `, + () => ({ styleFn }), + ); + const handle = thumb(w); + expect(handle.attributes("data-custom")).toBe("thumb"); + expect(handle.element.style.borderColor).toBe("black"); + expect(handle.element.style.opacity).toBe("0.25"); + expect(styleFn).toHaveBeenCalledWith( + expect.objectContaining({ + percent: { x: 0.25, y: 0.5 }, + isDragging: false, + isDisabled: false, + isReadOnly: false, + }), + ); + }); + + it("uses the documented default, explicit null and root label fallbacks", async () => { + const fallback = area(); + expect(x(fallback).element.value).toBe("255"); + expect(y(fallback).element.value).toBe("255"); + expect(thumb(fallback).element.style.left).toBe("100%"); + expect(thumb(fallback).element.style.top).toBe("0%"); + + const cleared = area( + {}, + ``, + ); + expect(x(cleared).element.value).toBe("255"); + expect(y(cleared).element.value).toBe("255"); + expect(thumb(cleared).element.style.left).toBe("100%"); + expect(thumb(cleared).element.style.top).toBe("0%"); + await key(cleared, "ArrowLeft"); + expect(emitted(cleared, "change")).toHaveLength(1); + + const labelled = area( + {}, + ` + + + 说明 + `, + ); + const roots = labelled.findAll("[data-slot=color-area]"); + expect(roots[0]!.attributes("aria-label")).toBe("主题色"); + expect(roots[1]!.attributes("aria-label")).toBeUndefined(); + expect(roots[1]!.attributes("aria-labelledby")).toBe("area-caption"); + }); + + it("honors modelValue over value over defaultValue and the disabled alias", async () => { + const both = area( + {}, + ``, + ); + expect(axisValue(both, "x")).toBe("255"); + expect(thumbColor(both)).toBe("rgb(255, 0, 0)"); + + const valueOnly = area( + {}, + ``, + ); + expect(thumbColor(valueOnly)).toBe("rgb(0, 255, 0)"); + + const disabled = area({ disabled: true, defaultValue: "#ff0000" }); + expect(root(disabled).attributes("data-disabled")).toBe("true"); + expect(x(disabled).element.disabled).toBe(true); + }); + + it("re-infer axes when colorSpace and channel props change dynamically", async () => { + const props = shallowRef>({ + defaultValue: "hsb(240, 50%, 50%)", + colorSpace: "hsb", + }); + const w = area( + {}, + ``, + () => ({ + props, + }), + ); + expect(x(w).attributes("aria-label")).toBe("Hue"); + expect(y(w).attributes("aria-label")).toBe("Saturation"); + expect(x(w).element.value).toBe("240"); + + props.value = { + defaultValue: "hsb(240, 50%, 50%)", + colorSpace: "rgb", + }; + await flushPromises(); + expect(x(w).attributes("aria-label")).toBe("Red"); + expect(y(w).attributes("aria-label")).toBe("Green"); + expect(x(w).attributes("max")).toBe("255"); + + props.value = { + defaultValue: "hsb(240, 50%, 50%)", + colorSpace: "rgb", + xChannel: "green", + yChannel: "blue", + }; + await flushPromises(); + expect(x(w).attributes("aria-label")).toBe("Green"); + expect(y(w).attributes("aria-label")).toBe("Blue"); + expect(thumb(w).element.style.left).not.toBe(""); + + props.value = { + defaultValue: "hsl(200, 50%, 50%)", + colorSpace: "hsl", + }; + await flushPromises(); + expect(x(w).attributes("aria-label")).toBe("Hue"); + expect(y(w).attributes("aria-label")).toBe("Saturation"); + expect(x(w).attributes("max")).toBe("360"); + }); + + it("keeps accepted alpha and fractional channel precision through keyboard changes", async () => { + const value = parseColor("hsb(240,50.123%,50.567%,.321)"); + const w = area({ + defaultValue: value, + xChannel: "saturation", + yChannel: "brightness", + }); + expect(x(w).element.value).toBe("50.123"); + await key(w, "ArrowUp", true, {}, "y"); + const proposal = emitted(w, "change")[0]![0] as Color; + expect(proposal.getChannelValue("alpha")).toBe(0.321); + expect(proposal.getChannelValue("saturation")).toBe(50.123); + expect(proposal.getChannelValue("brightness")).toBeCloseTo(51.567); + }); + + it("requires the thumb to be rendered inside the root", () => { + expect(() => + render( + defineComponent({ + components: { ColorAreaThumb }, + template: ``, + }), + ), + ).toThrow(/ColorAreaThumb must be rendered inside ColorArea/); + }); +}); diff --git a/tests/color-foundation.test.ts b/tests/color-foundation.test.ts index 4767740..e9efc89 100644 --- a/tests/color-foundation.test.ts +++ b/tests/color-foundation.test.ts @@ -171,9 +171,19 @@ describe("immutable private color value boundary", () => { }); it("resolves legal space defaults and rejects duplicate/mismatched axes", () => { expect(colorAxes(parseColor("#f00"))).toMatchObject({ + space: "rgb", + x: "red", + y: "green", + }); + expect(colorAxes(parseColor("hsl(200, 50%, 50%)"))).toMatchObject({ + space: "hsl", + x: "hue", + y: "saturation", + }); + expect(colorAxes(parseColor("hsb(240, 50%, 50%)"))).toMatchObject({ space: "hsb", - x: "saturation", - y: "brightness", + x: "hue", + y: "saturation", }); expect(colorAxes(parseColor("#f00"), "rgb")).toMatchObject({ x: "red", diff --git a/tests/package/check-client.mjs b/tests/package/check-client.mjs index 8d7a885..e69cf5d 100644 --- a/tests/package/check-client.mjs +++ b/tests/package/check-client.mjs @@ -90,6 +90,42 @@ for (const id of process.argv.slice(2)) { .base() .includes("hv-select--secondary"), ); + if (id === "color-area") { + assert(lib.ColorArea === lib.ColorAreaRoot); + assert(lib.ColorAreaThumb); + assert( + lib + .colorAreaVariants({ showDots: true }) + .base() + .includes("hv-color-area--show-dots"), + ); + assert( + lib.colorAreaVariants().thumb() === "hv-color-area__thumb", + "ColorArea thumb class must stay in the baseline namespace", + ); + const areaDts = readFileSync( + new URL( + "./node_modules/@heroui-vue/components/dist/components/color-area/ColorArea.vue.d.ts", + import.meta.url, + ), + "utf8", + ); + const thumbDts = readFileSync( + new URL( + "./node_modules/@heroui-vue/components/dist/components/color-area/ColorAreaThumb.vue.d.ts", + import.meta.url, + ), + "utf8", + ); + assert( + !areaDts.includes("reka-ui"), + "ColorArea declarations leak Reka types", + ); + assert( + !thumbDts.includes("reka-ui"), + "ColorAreaThumb declarations leak Reka types", + ); + } if (id === "color-swatch") { assert(lib.ColorSwatch === lib.ColorSwatchRoot); assert( diff --git a/tests/package/client-checks.json b/tests/package/client-checks.json index 24208c9..b88850a 100644 --- a/tests/package/client-checks.json +++ b/tests/package/client-checks.json @@ -110,6 +110,23 @@ ".hv-calendar-year-picker__year-cell" ] }, + "color-area": { + "exports": [ + "ColorArea", + "ColorAreaRoot", + "ColorAreaThumb", + "colorAreaVariants", + "Color", + "parseColor" + ], + "css": [ + ".hv-color-area", + ".hv-color-area--show-dots", + ".hv-color-area__thumb", + "--color-area-background", + "--color-area-thumb-color" + ] + }, "color-field-protocol": { "exports": [], "css": [ @@ -120,24 +137,12 @@ ".hv-color-input-group__prefix", ".hv-color-input-group__suffix" ], - "absent": [ - "ColorArea", - "ColorSlider", - "ColorField", - "ColorInputGroup", - "ColorPicker" - ] + "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] }, "color-foundation": { "exports": [], "css": [".hv-color-area", ".hv-color-area__thumb"], - "absent": [ - "ColorArea", - "ColorSlider", - "ColorField", - "ColorInputGroup", - "ColorPicker" - ] + "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] }, "color-picker-protocol": { "exports": [], @@ -146,13 +151,7 @@ ".hv-color-picker__trigger", ".hv-color-picker__popover" ], - "absent": [ - "ColorArea", - "ColorSlider", - "ColorField", - "ColorInputGroup", - "ColorPicker" - ] + "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] }, "color-slider-foundation": { "exports": [], @@ -166,13 +165,7 @@ "max-height:inherit", "overscroll-behavior:contain" ], - "absent": [ - "ColorArea", - "ColorSlider", - "ColorField", - "ColorInputGroup", - "ColorPicker" - ] + "absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"] }, "date-field": { "exports": [ diff --git a/tests/package/color-area-contract.ts b/tests/package/color-area-contract.ts new file mode 100644 index 0000000..bfa4b48 --- /dev/null +++ b/tests/package/color-area-contract.ts @@ -0,0 +1,135 @@ +import { + ColorArea, + ColorAreaRoot, + ColorAreaThumb, + colorAreaVariants, + parseColor, + type Color, + type ColorAreaExpose, + type ColorAreaProps, + type ColorAreaRenderProps, + type ColorAreaRootProps, + type ColorAreaSlots, + type ColorAreaStyle, + type ColorAreaStyleFn, + type ColorAreaThumbProps, + type ColorAreaThumbRenderProps, + type ColorAreaThumbStyle, + type ColorAreaThumbStyleFn, + type ColorAreaVariants, + type ColorAxisChannel, + type ColorSpace, + type ColorValue, +} from "@heroui-vue/components"; + +const color = parseColor("#9B80FF"); +const value: ColorValue = color; +const axis: ColorAxisChannel = "saturation"; +const space: ColorSpace = "hsb"; +const style: ColorAreaStyle = { outline: "1px solid black" }; +const styleFn: ColorAreaStyleFn = ({ color: current }) => ({ + outline: `1px solid ${current.toString("hex")}`, +}); +const styleRender: ColorAreaStyle = ({ color: current }) => ({ + background: current.toString("css"), +}); +const thumbStyle: ColorAreaThumbStyle = ({ percent }) => ({ + opacity: percent.x, +}); +const thumbStyleFn: ColorAreaThumbStyleFn = ({ isDragging }) => ({ + width: isDragging ? "20px" : "16px", +}); +const props: ColorAreaProps = { + modelValue: color, + value, + defaultValue: "hsb(240, 50%, 50%)", + colorSpace: space, + xChannel: "hue", + yChannel: axis, + xName: "hue", + yName: "saturation", + form: "color-form", + isDisabled: false, + disabled: false, + isReadOnly: false, + showDots: true, + locale: "zh-CN", + dir: "rtl", + as: "div", + asChild: false, + style, + styleFn, +}; +const rootProps: ColorAreaRootProps = props; +const thumbProps: ColorAreaThumbProps = { + as: "span", + style: thumbStyle, + styleFn: thumbStyleFn, +}; +const slots: ColorAreaSlots = { default: () => null }; +const variants: ColorAreaVariants = { showDots: true }; +const render: ColorAreaRenderProps = { + color, + space: "hsb", + x: "hue", + y: "saturation", +}; +const thumbRender: ColorAreaThumbRenderProps = { + ...render, + percent: { x: 1, y: 0 }, + isDragging: false, + isDisabled: false, + isReadOnly: false, +}; +const exposed: ColorAreaExpose = { element: null, color: null }; +const typedColor: Color = parseColor("rgb(1, 2, 3)"); + +// @ts-expect-error alpha is not a two-dimensional axis +const badAxis: ColorAxisChannel = "alpha"; +// @ts-expect-error the public space set is rgb | hsl | hsb +const badSpace: ColorSpace = "lab"; +// @ts-expect-error showDots only accepts a boolean +const badVariant: ColorAreaVariants = { showDots: "yes" }; +// @ts-expect-error xChannel is a channel name, not an index +const badProps: ColorAreaProps = { xChannel: 1 }; +const badRender: ColorAreaRenderProps = { + // @ts-expect-error render props require a Color instance + color: "#fff", + space: "rgb", + x: "red", + y: "green", +}; +const badThumb: ColorAreaThumbRenderProps = { + ...render, + // @ts-expect-error the thumb exposes percent, not raw pixel coordinates + percent: 1, + isDragging: false, + isDisabled: false, + isReadOnly: false, +}; + +void [ + ColorArea, + ColorAreaRoot, + ColorAreaThumb, + colorAreaVariants, + value, + axis, + space, + styleRender, + props, + rootProps, + thumbProps, + slots, + variants, + render, + thumbRender, + exposed, + typedColor, + badAxis, + badSpace, + badVariant, + badProps, + badRender, + badThumb, +];
+ Current color: + + {{ color ? color.toString("hex") : "(empty)" }} + +
+ {{ color?.toString(colorSpace) ?? "(empty)" }} +