Compare commits
10 Commits
7287318d86
...
b72a6e0dd0
| Author | SHA1 | Date | |
|---|---|---|---|
| b72a6e0dd0 | |||
| 457d340d7b | |||
| 8e8fc69117 | |||
| 3c8473d597 | |||
| 3a4142e891 | |||
| adca8d0047 | |||
| 980930ed76 | |||
| efb53d4ce7 | |||
| 8d9adda8da | |||
| fa4146ee0b |
@@ -110,6 +110,11 @@ export const componentItems: DocsItem[] = [
|
||||
url: "/components/color-swatch",
|
||||
category: "colors",
|
||||
},
|
||||
{
|
||||
title: "ColorSwatchPicker 颜色色块选择器",
|
||||
url: "/components/color-swatch-picker",
|
||||
category: "colors",
|
||||
},
|
||||
{
|
||||
title: "ComboBox 组合框",
|
||||
url: "/components/combo-box",
|
||||
|
||||
@@ -178,4 +178,4 @@ Vue 版写作 `ColorAreaThumb`(对应上游 `ColorArea.Thumb`)。
|
||||
|
||||
## 相关组件
|
||||
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch) 与 [ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker)。ColorPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -266,7 +266,7 @@ color.toString("hex");
|
||||
color.getChannelValue("red");
|
||||
```
|
||||
|
||||
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。ColorPicker/ColorSwatchPicker 尚未公开。
|
||||
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 已公开;ColorPicker 尚未公开。
|
||||
|
||||
## ColorField.Group Styling
|
||||
|
||||
|
||||
@@ -281,4 +281,4 @@ ColorSlider 实现 ARIA slider 模式,提供:
|
||||
|
||||
## 相关组件
|
||||
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch) 与 [ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker)。ColorPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
---
|
||||
title: ColorSwatchPicker 颜色色块选择器
|
||||
description: 允许用户从预置调色板中选择颜色的 swatch 列表
|
||||
component: color-swatch-picker
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem color="#F43F5E">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
固定源使用 `ColorSwatchPicker.Item` 对象组合;Vue 版提供同名具名组件,Root 别名 `ColorSwatchPickerRoot` 与 `ColorSwatchPicker` 共用实现。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem color="#F43F5E">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
<ColorSwatchPickerItem color="#D946EF">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
<ColorSwatchPickerItem color="#8B5CF6">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-variants" />
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-sizes" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-disabled" />
|
||||
|
||||
### 堆叠布局
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-stack-layout" />
|
||||
|
||||
### 默认值
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-default-value" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-controlled" />
|
||||
|
||||
### 自定义指示器
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-custom-indicator" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
上游 `render` 用于替换根元素或附加属性;Vue 版通过 `as` 更换元素类型,`data-*`、`aria-*` 与事件直接透传,并使用作用域插槽透出真实状态(根与项两级)。
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="color-swatch-picker-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 ColorSwatchPicker 组件类。
|
||||
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-color-swatch-picker {
|
||||
@apply gap-4;
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply shadow-md;
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply border-2 border-white;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
ColorSwatchPicker 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/color-swatch-picker.css)):
|
||||
|
||||
#### 基础与结构 [!toc]
|
||||
|
||||
- `.hv-color-swatch-picker` - 基础容器(flex 布局)
|
||||
- `.hv-color-swatch-picker__item` - 单个 swatch 包裹层
|
||||
- `.hv-color-swatch-picker__swatch` - swatch 视觉元素
|
||||
- `.hv-color-swatch-picker__indicator` - 选中指示器
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-color-swatch-picker--xs` - 特小(16px)
|
||||
- `.hv-color-swatch-picker--sm` - 小(24px)
|
||||
- `.hv-color-swatch-picker--md` - 中(32px,默认)
|
||||
- `.hv-color-swatch-picker--lg` - 大(36px)
|
||||
- `.hv-color-swatch-picker--xl` - 特大(40px)
|
||||
|
||||
#### 形状变体 [!toc]
|
||||
|
||||
- `.hv-color-swatch-picker--circle` - 圆形(默认)
|
||||
- `.hv-color-swatch-picker--square` - 圆角方形
|
||||
|
||||
#### 布局类 [!toc]
|
||||
|
||||
- `.hv-color-swatch-picker--grid` - 横向换行网格(默认)
|
||||
- `.hv-color-swatch-picker--stack` - 纵向堆叠
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件同时支持 CSS 伪类与 data 属性:
|
||||
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]` - 缩放至 1.1(选中状态以选中缩放为准)
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]` - 焦点环
|
||||
- **Selected**:`[data-selected="true"]` - 与 swatch 同色的内边框,swatch 缩至 0.77 显出间隔
|
||||
- **Disabled**:`[data-disabled="true"]` - 降低透明度并禁用交互
|
||||
|
||||
透明颜色保留 ColorSwatch 的棋盘格底纹;`--color-swatch-current` 写在每个项与色块节点上,供选中边框与棋盘底色使用。
|
||||
|
||||
## API 参考
|
||||
|
||||
### ColorSwatchPicker
|
||||
|
||||
对应固定源的 [React Aria ColorSwatchPicker](https://react-spectrum.adobe.com/react-aria/ColorSwatchPicker.html)(`listbox` / `option` 语义,单项选择且不允许清空)。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | ------------------------------------------ | ---------- | ------------------------------------------------------------------------ |
|
||||
| `modelValue` | `string \| Color \| null` | - | 当前接受颜色(`v-model`;受控) |
|
||||
| `value` | `string \| Color \| null` | - | 低优先级受控别名,与共享颜色模型一致 |
|
||||
| `defaultValue` | `string \| Color \| null` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值,不会自动选中第一个候选 |
|
||||
| `layout` | `"grid" \| "stack"` | `"grid"` | 布局方向(视觉 flex 布局,ARIA 方向固定为 vertical) |
|
||||
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | swatch 尺寸 |
|
||||
| `variant` | `"circle" \| "square"` | `"circle"` | swatch 形状 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用整个选择器(库扩展) |
|
||||
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
|
||||
| `isReadOnly` | `boolean` | `false` | 只读:保留选择与焦点,阻止新的选择(库扩展) |
|
||||
| `dir` | `"ltr" \| "rtl"` | - | 方向;影响水平方向键映射 |
|
||||
| `as` | `string` | `"div"` | 自定义根元素标签;对应上游 `render` 的元素替换 |
|
||||
| `aria-label` | `string` | - | 列表名称;省略且没有 `aria-labelledby` 时使用本地化默认名称 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| 默认作用域插槽 | `({ color, isEmpty, isDisabled, isReadOnly, isFocused, layout }) => VNodeChild` | - | 根渲染状态 |
|
||||
|
||||
`change` 事件与 `update:modelValue` 一起在选择被接受时触发,参数为本库 `Color`,保留候选色自身的颜色空间与精度。选择比较使用固定源的 hexa 键(8 位 RGB + alpha):等价格式(hex/rgb/hsl)视为同一颜色,alpha 按 1/255 量化比较,灰色的色相在比较中折叠;接受值本身不会被反写或量化。
|
||||
|
||||
省略全部自身值属性时继承最近的颜色 owner(例如 [ColorField](/components/color-field) 家族共享的私有 ColorPicker 组合);显式 `value`/`modelValue` 覆盖继承,动态增删属性可切换归属。显式 `null` 表示受控空值(不选中任何项);固定源把 `null` 视为非受控,此项差异已记录。
|
||||
|
||||
### ColorSwatchPicker.Item
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | -------------------------------- | ------ | -------------------------------------------------------- |
|
||||
| `color` | `string \| Color \| null` | - | 候选颜色;省略或空字符串渲染透明色块(对应固定源 `#0000`) |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用该项(不可聚焦、不可选择、方向键跳过) |
|
||||
| `as` | `string` | `"div"` | 自定义根元素标签 |
|
||||
| `aria-label` | `string` | - | 覆盖自动生成的项名称 |
|
||||
| 默认作用域插槽 | `(state) => VNodeChild` | - | 项状态,见下方 Render Props |
|
||||
|
||||
### ColorSwatchPicker.Swatch
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ------------------------- | ------ | ------------------------------------------ |
|
||||
| `color` | `string \| Color \| null` | - | 覆盖颜色;省略时使用所属项的颜色 |
|
||||
| `colorName` | `string` | - | 颜色的可访问名称(覆盖自动生成的描述) |
|
||||
| `as` | `string` | `"div"` | 自定义根元素标签 |
|
||||
|
||||
### ColorSwatchPicker.Indicator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---- | ---------------- | --------- | ------------------------ |
|
||||
| `as` | `string` | `"span"` | 自定义根元素标签 |
|
||||
| 默认作用域插槽 | `(state) => VNodeChild` | - | 替换默认勾选图标,接收项状态 |
|
||||
|
||||
默认图标是固定源的勾选 SVG;`[data-light-color="true"]` 由色块相对亮度(> 0.5)决定,浅色背景使用黑色勾选。指示器始终渲染在 DOM 中,由 CSS 在选中时缩放显示。
|
||||
|
||||
### Render Props
|
||||
|
||||
| 插槽状态 | 类型 | 含义 |
|
||||
| --------------------------------------------------- | --------- | -------------------------------------- |
|
||||
| `color`(项) | `Color` | 该项的候选颜色 |
|
||||
| `isSelected` / `isDisabled` / `isFocused` / `isFocusVisible` / `isPressed` / `isHovered` | `boolean` | 项的真实状态 |
|
||||
| `color`(根) | `Color \| null` | 当前接受颜色 |
|
||||
| `isEmpty` / `isDisabled` / `isReadOnly` / `isFocused` | `boolean` | 根的真实状态 |
|
||||
| `layout`(根) | `"grid" \| "stack"` | 当前布局 |
|
||||
|
||||
Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `focus()`(按入口规则聚焦项);Item 提供 `element`。不暴露颜色 owner、事务 token 或内部集合键。
|
||||
|
||||
### 选择与焦点
|
||||
|
||||
| 操作 | 行为 |
|
||||
| ----------------------- | ----------------------------------------------------------------------- |
|
||||
| 鼠标主键按下 | 选择该项;仅主键(`button === 0`)激活,右键/中键保留原生行为;可取消的 `mousedown`(`preventDefault`)会阻止选择 |
|
||||
| `Enter` / `Space` | 选择当前聚焦项(按下即选中) |
|
||||
| `Tab` / `Shift+Tab` | 整个列表是一个 tab 停靠点;进入时聚焦已选项或首/末可用项 |
|
||||
| `↑` / `↓` | 只移动焦点不选择;grid 按几何在换行行间移动,stack 按顺序移动 |
|
||||
| `←` / `→` | grid 按顺序移动(RTL 反向);stack 交给浏览器滚动 |
|
||||
| `Home` / `End` | 聚焦首/末可用项 |
|
||||
| `PageUp` / `PageDown` | 容器不可滚动时跳到首/末项,可滚动时按页移动 |
|
||||
| `click`(`detail=0`) | 辅助技术/程序化的 click-only 激活选择当前项;正常鼠标/键盘的兼容 click 不重复提案 |
|
||||
| 输入字符 | 按项名称前缀匹配并聚焦(名称差异见下) |
|
||||
| 边界 | 不循环;到边界后保持当前项 |
|
||||
|
||||
焦点与选择分离:方向键只移动焦点,`aria-selected` 与指示器只反映接受颜色。父级拒绝提案后,选择样式、`aria-selected` 与 DOM 保持接受状态,同一手势可重试。窗口失焦或指针取消会清除按压状态与点击去重归属,恢复后可以立即重试。
|
||||
|
||||
### 可访问名称差异
|
||||
|
||||
固定源使用 React Aria 的感知色名(`getColorName`)作为项与色块的自动名称。本库未实现感知色名表:自动名称使用 `hex`/`hexa` 或“透明”文案,并接受显式 `aria-label` / `colorName` 覆盖。列表本身在省略 `aria-label` 时使用本地化默认名称“颜色色块选择器”。
|
||||
|
||||
### 表单
|
||||
|
||||
固定源 ColorSwatchPicker 不提供 `name`/`form` 提交、表单重置或 required/validate 字段 API,本库同样不新增这些字段 API(明确差异)。需要表单提交时请与共享颜色 owner 组合:由 owner 的隐藏值提交完整精度颜色,选择器不重复提交或接管重置,组合中的 reset 会恢复真实 DOM 状态。
|
||||
|
||||
### Color 与 parseColor
|
||||
|
||||
`Color`、`parseColor`、`ColorValue` 等类型从包根导出,与 [ColorSwatch](/components/color-swatch) 共用同一颜色模型;详见该页的公共接口表。
|
||||
|
||||
## 相关组件
|
||||
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch) 与 [ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker)。ColorPicker 仍为私有颜色协议,尚未公开。
|
||||
@@ -152,4 +152,4 @@ ColorSwatch 组件使用以下 CSS 类([查看源码样式](https://github.com
|
||||
|
||||
## 相关组件
|
||||
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch) 与 [ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker)。ColorPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
|
||||
const value = shallowRef<Color | null>(parseColor("#F43F5E"));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorSwatchPicker v-model="value">
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
<p class="text-sm text-muted">
|
||||
已选:<span class="font-medium">{{ value?.toString("hex") }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import { IconHeartFilled } from "@tabler/icons-vue";
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator>
|
||||
<IconHeartFilled aria-hidden="true" />
|
||||
</ColorSwatchPickerIndicator>
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker
|
||||
class="rounded-2xl border border-border/80 bg-surface p-4 shadow-sm ring-1 ring-accent/5"
|
||||
default-value="#8B5CF6"
|
||||
variant="square"
|
||||
>
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker default-value="#8B5CF6">
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
:color="color"
|
||||
is-disabled
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker data-custom="foo" v-slot="root">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
:color="color"
|
||||
v-slot="state"
|
||||
>
|
||||
<ColorSwatchPickerSwatch
|
||||
:data-item-selected="state.isSelected || undefined"
|
||||
:data-picker-layout="root.layout"
|
||||
/>
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
|
||||
const sizes = ["xs", "sm", "md", "lg", "xl"] as const;
|
||||
|
||||
const SIZE_LABELS: Record<(typeof sizes)[number], string> = {
|
||||
lg: "大",
|
||||
md: "中",
|
||||
sm: "小",
|
||||
xl: "特大",
|
||||
xs: "特小",
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<div v-for="size in sizes" :key="size" class="flex items-center gap-4">
|
||||
<span class="w-8 text-sm text-muted">{{ SIZE_LABELS[size] }}</span>
|
||||
<ColorSwatchPicker :size="size">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
:color="color"
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorSwatchPicker layout="stack">
|
||||
<ColorSwatchPickerItem v-for="color in colors" :key="color" :color="color">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const colors = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<div class="flex flex-col gap-2">
|
||||
<span class="text-sm text-muted">圆形(默认)</span>
|
||||
<ColorSwatchPicker variant="circle">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
:color="color"
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<span class="text-sm text-muted">方形</span>
|
||||
<ColorSwatchPicker variant="square">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
:color="color"
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -24,7 +24,7 @@
|
||||
| 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 | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 已迁移(客户端) | ColorSwatchPicker/Root、Item、Swatch、Indicator 与 colorSwatchPickerVariants;listbox/option 单选语义、hexa 键颜色匹配、受控接受/拒绝/重试、鼠标按下与 Enter/Space 选择、grid 几何方向键/stack 顺序、RTL、Home/End、PageUp/Down、禁用跳过、动态候选与焦点回落;10/10 基线例;render→as/attrs+作用域插槽;感知色名与 name/form 为明确差异,见 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 编辑等仍待专项。 |
|
||||
|
||||
+15
-1
@@ -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 与 ColorSlider 已作为公共组件迁移;ColorField/ColorInputGroup 已公开并按用户授权合入 main,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/ColorInputGroup 已公开并按用户授权合入 main,ColorPicker 仍未公开,ColorSwatchPicker 的公共迁移与验收见下节。不能把内核/夹具通过写成整族完成。共享 owner、归一化通道、接受值与草稿保持同一状态源。ColorArea 按固定源运行时默认 `#ffffff` 与空间首通道推断轴,见 [颜色决策](decisions/color-foundation.md) 与 [COLOR-AREA 结果](tasks/results/COLOR-AREA.md)。
|
||||
|
||||
## COLOR-AREA(2026-10-26)
|
||||
|
||||
@@ -52,3 +52,17 @@ Hex 采用命名的可见文本 input,直接 FormData 能读取未提交草稿
|
||||
补齐根 focus/focus-within/focus-visible 状态,所有根 ARIA(含 aria-details)到真实 Input,Root/Group 支持 style/styleFn;实例保留 focus/element,Root 额外提供接受 color。上游 render 对应 as/attrs,不提供 asChild;未知包装不执行 setup/render 探测。浏览器证明 100px 通道组受原生输入固有最小宽度挤压,因此在 Input CSS 增加 min-width:0,后缀保持在组内,其他源视觉数值不变。
|
||||
|
||||
本项由主会话亲自实施/验收;已按用户授权合入 main,不替代独立复核结论。SSR/水合/Nuxt服务端、逐像素/完整读屏/真机矩阵未投入;系统输入法未完整验收,composition 只有合成事件覆盖。
|
||||
|
||||
## COLOR-SWATCH-PICKER(2026-10-27)
|
||||
|
||||
ColorSwatchPicker/Root、Item、Swatch、Indicator、Props/作用域插槽/实例类型与 colorSwatchPickerVariants 已公开,固定源中文 10 例全部迁移。复用既有 `components/color/{value,model}` 接受值、`collection/registry` 集合登记与共享 disabled/config;没有第二套颜色接受状态,也没有把颜色字符串当作集合键(重复/等价候选保持独立 DOM 项)。见 [组件文档](../apps/docs/components/color-swatch-picker.md) 与 [结果](tasks/results/COLOR-SWATCH-PICKER.md)。
|
||||
|
||||
选择匹配沿用固定源 hexa 键(8 位 RGB+alpha):hex/rgb/hsl 等价视为同一颜色,alpha 按 1/255 比较,灰色色相折叠;接受值本身不被反写或量化,选中项输出候选自身颜色空间与精度。同一颜色的多个候选项不合并:选中时按颜色值全部显示 `aria-selected`,焦点仍是逐项的。父级拒绝后 aria-selected/Indicator/样式保持接受状态,同一手势可重试;点击已接受颜色不重复发事件(与固定源选择键不变一致)。
|
||||
|
||||
焦点与选择分离:鼠标主键按下即选择(可取消 mousedown 阻止;右键/中键保留原生行为),辅助技术的 `detail=0` click-only 激活同样可选且不与按下路径重复提案;`data-pressed`/`isPressed` 在释放、拖出、失焦与禁用时清理,按下夺焦不清新按压状态。Enter/Space 选择当前项,方向键/Home/End/PageUp/Down 只移动焦点;grid 按真实几何跨换行行移动、左右按顺序(RTL 反向),stack 上下按顺序、左右交还浏览器,边界不循环。列表是单个 tab 停靠点,进入时聚焦已选项或首/末项;删除/禁用当前焦点项后焦点回落到列表入口,根禁用时离开 tab 序、恢复后回到单一入口,全部项禁用时列表根是唯一入口。自动名称使用 hex/hexa/透明文案并接受显式 `aria-label` 覆盖(固定源为感知色名,未实现);typeahead 按该名称前缀匹配。
|
||||
|
||||
固定源没有 name/form 提交、表单 reset 与 required/validate 字段 API,本库同样不新增这些字段 API(明确差异)。表单提交/重置经共享颜色 owner(私有 ColorPicker 的完整精度隐藏值)完成,选择器不重复提交或接管 reset;组合的 FormData、受控拒绝与 reset 后真实 DOM 恢复已有浏览器证据。Root 的 `isDisabled`/`disabled`/`isReadOnly`/`dir` 为库扩展(与共享颜色模型一致)。
|
||||
|
||||
本项由主会话亲自实施/自测,未委派其他 AI,未宣称独立复核。SSR/水合/Nuxt 服务端、逐像素对比、完整读屏矩阵与真机矩阵未投入;截图在本会话不可用,视觉结论以真实浏览器计算样式与操作结果为准。
|
||||
|
||||
ColorSwatchPicker 最终接手验收:窗口失焦与 pointercancel 统一取消项按压和点击去重归属,禁用/元素失焦/移出复用项级取消;多 Picker 隔离与取消后受控重试通过。最终修复 `3c8473d`,完整证据见 [任务结果](tasks/results/COLOR-SWATCH-PICKER.md)。
|
||||
|
||||
+5
-3
@@ -9,12 +9,12 @@
|
||||
- 展示、按钮、导航、展开、反馈等主要家族已有公共组件与文档。
|
||||
- 字段/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 例;ColorSlider/ColorSliderRoot、ColorSliderOutput/Track/Thumb 与 colorSliderVariants 已公开,复用共享通道/轨道内核与固定源 9 例。ColorField/ColorFieldRoot、配套 ColorInputGroup 与具名字段部件、两套 variants 已完成客户端迁移,含固定源 13 例,并按用户授权合入 main。ColorPicker/ColorSwatchPicker 仍未公开。
|
||||
- 兼容矩阵目前85条(包含子部件与基础设施),文档有71个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
- ColorSwatch/ColorSwatchRoot及Color/parseColor公共子集已公开;ColorArea/ColorAreaRoot、ColorAreaThumb 与 colorAreaVariants 已公开,复用共享颜色 owner、二维交互与固定源 7 例;ColorSlider/ColorSliderRoot、ColorSliderOutput/Track/Thumb 与 colorSliderVariants 已公开,复用共享通道/轨道内核与固定源 9 例。ColorField/ColorFieldRoot、配套 ColorInputGroup 与具名字段部件、两套 variants 已完成客户端迁移,含固定源 13 例,并按用户授权合入 main。ColorSwatchPicker/ColorSwatchPickerRoot、ColorSwatchPickerItem/Swatch/Indicator 与 colorSwatchPickerVariants 已完成客户端迁移,含固定源 10 例(见 [结果](tasks/results/COLOR-SWATCH-PICKER.md),复核通过并已按用户授权合入 main)。ColorPicker 仍未公开。
|
||||
- 兼容矩阵目前85条(包含子部件与基础设施),文档有72个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
|
||||
## 尚未完成的公共家族
|
||||
|
||||
ColorSwatchPicker、ColorPicker,共2项;已有私有内核不等于公共迁移完成。ColorField/ColorInputGroup 迁移结果见 [COLOR-FIELD](tasks/results/COLOR-FIELD.md),已合入 main;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收,ColorSlider 已随 COLOR-SLIDER 验收。
|
||||
ColorPicker,共1项;已有私有内核不等于公共迁移完成。ColorField/ColorInputGroup 迁移结果见 [COLOR-FIELD](tasks/results/COLOR-FIELD.md),已合入 main;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收,ColorSlider 已随 COLOR-SLIDER 验收,ColorSwatchPicker 见 [COLOR-SWATCH-PICKER](tasks/results/COLOR-SWATCH-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)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。
|
||||
|
||||
@@ -32,3 +32,5 @@ TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/
|
||||
- 移植来源/许可:[上游记录](upstream.md),不删减。
|
||||
- 选哪些验证:[tests/README.md](../tests/README.md)。
|
||||
- 过往返工/提示词:[历史查询](history.md),默认不读。
|
||||
|
||||
ColorSwatchPicker 最终修复 `3c8473d`,已合入 main(`457d340`),原复核阻断全部关闭;最终全量客户端105文件/1558项、类型、文档构建、五契约tarball及main集成回归通过。推送已获授权,远端同步以实际Git状态为准,详见任务结果。
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# 当前工作区交接
|
||||
|
||||
- 任务:COLOR-FIELD 已完成,用户已授权合入 main 并推送 origin/main;状态 accepted,无进行中任务。
|
||||
- 任务:COLOR-SWATCH-PICKER 已验收并按用户授权合入 main;卡状态 accepted,无进行中实施任务。
|
||||
- 工作区/分支:heroui-vue / `main`。
|
||||
- 起点:`108a120c81ac53c6a273422a1bb88cb5cfaec9e6`。
|
||||
- 实施提交:`6a7a89be6b5b94e7d8a0778886453832f29d41f9`;实施结果提交:`71b8c77`;合并提交:`ec350c5f4e92d7dc7c9ccdc7e3e3ae9bfa231170`。
|
||||
- 入口:`docs/tasks/COLOR-FIELD.md` 与 `docs/tasks/results/COLOR-FIELD.md`;由主会话亲自完成,未委派其他 AI,不宣称独立复核。
|
||||
- 验证:实施定向13文件/206项、全量103文件/1517项、typecheck、build:docs、最终tarball八契约及实际浏览器通过;集成后全量103文件/1517项、文档构建通过。集成时修正相关组件页的私有Picker措辞以保留原文档边界检查。
|
||||
- 远端:本次授权推送 origin/main;实际同步以最终 git status 与远端 SHA 为准。
|
||||
- 预览:文档5173保留,`/components/color-field`;playground5174已停止。系统IME未完整验收,其他暂缓范围沿用 AGENTS。
|
||||
- 起点:`fa4146ee0b5805e388a6c241c31c69900eabeb18`;实施 `8d9adda`、首次修复 `adca8d0`、最终修复 `3c8473d5974f34f132b129362dc95d405ff9eaae`;验收记录 `8e8fc69`。
|
||||
- 合并提交:`457d340d7b6499899555d523f3e23ae497d71e62`;原 R1–R4 与窗口失焦边界全部关闭。
|
||||
- 验证:组件34项、全量105文件/1558项、typecheck、build:docs、最终tarball五契约通过;真实浏览器取消/受控拒绝/重试序列通过;main 集成全量105文件/1558项通过。
|
||||
- 入口:`docs/tasks/COLOR-SWATCH-PICKER.md` 与 `docs/tasks/results/COLOR-SWATCH-PICKER.md`。
|
||||
- 远端:本轮已授权推送 origin/main;实际同步以最终 git status 与远端回读 SHA 为准。
|
||||
- 预览:文档5173保留,组件页 `/components/color-swatch-picker`;临时验证页已删除,未停止其他服务。
|
||||
- 接续:ColorPicker 仍私有,不自动开始下一家族。
|
||||
|
||||
单目录串行;后续先检查实际git状态,不自动开始下一家族。
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<!-- task-metadata
|
||||
{
|
||||
"base": "7287318d86112159f9a9c4c4beb9bc1cdbdf1942",
|
||||
"upstream": "ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960",
|
||||
"status": "accepted",
|
||||
"requires": [
|
||||
"packages/vue/src/components/color/value.ts",
|
||||
"packages/vue/src/components/color/model.ts",
|
||||
"packages/vue/src/components/color-swatch/ColorSwatch.vue",
|
||||
"packages/vue/src/components/color-swatch/types.ts",
|
||||
"packages/vue/src/components/choice/shared.ts",
|
||||
"packages/vue/src/components/color-picker/ColorPicker.vue",
|
||||
"docs/decisions/color-foundation.md",
|
||||
"tests/color-swatch.test.ts",
|
||||
"tests/color-picker-composition.test.ts",
|
||||
"tests/package/client-checks.json"
|
||||
],
|
||||
"sources": [
|
||||
"packages/react/src/components/color-swatch-picker/index.ts",
|
||||
"packages/react/src/components/color-swatch-picker/color-swatch-picker.tsx",
|
||||
"packages/react/tests/components/color-swatch-picker/color-swatch-picker.test.tsx",
|
||||
"packages/styles/components/color-swatch-picker.css",
|
||||
"packages/styles/src/components/color-swatch-picker/index.ts",
|
||||
"packages/styles/src/components/color-swatch-picker/color-swatch-picker.styles.ts",
|
||||
"apps/docs/content/docs/cn/react/components/(colors)/color-swatch-picker.mdx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/index.ts",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/basic.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/variants.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/sizes.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/disabled.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/stack-layout.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/default-value.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/controlled.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/custom-indicator.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/render-function.tsx",
|
||||
"apps/docs/src/demos/cn/color-swatch-picker/custom-styles.tsx"
|
||||
],
|
||||
"checks": [
|
||||
"pnpm exec vitest run tests/color-swatch-picker.test.ts tests/color-swatch-picker-demos.test.ts tests/color-swatch.test.ts tests/color-swatch-demos.test.ts tests/color-foundation.test.ts tests/color-picker-composition.test.ts tests/color-picker-protocol.test.ts tests/regressions/color",
|
||||
"pnpm typecheck",
|
||||
"pnpm build:docs",
|
||||
"node scripts/check-package.mjs color-swatch-picker color-swatch color-foundation color-picker-protocol color-field"
|
||||
]
|
||||
}
|
||||
-->
|
||||
|
||||
# COLOR-SWATCH-PICKER:公共颜色色块选择器迁移
|
||||
|
||||
## 目标与边界
|
||||
|
||||
将固定 HeroUI 基线的 ColorSwatchPicker 迁移为可独立安装的 Vue 公共组件,交付真实选择交互、源样式、全部 10 个中文示例、发布类型和可复现验收。此卡可以交给新的 AI 会话独立完成,不依赖旧聊天。
|
||||
|
||||
规划时 main 工作区干净,HEAD 为头部 base。Color/parseColor、ColorSwatch、ColorArea、ColorSlider、ColorField 已公开;ColorSwatchPicker 尚无公共实现。ColorPicker 已有私有组合,本项只验证与它的组合,不公开 ColorPicker,不扩展其他颜色家族。
|
||||
|
||||
本轮只创建规划。实施者接到执行指令后再占用目录、建立任务分支并实施;本卡的 planned 不表示实现或验收通过。只支持客户端,不开发、不运行 SSR/水合/Nuxt 服务端专项,不建立逐像素自动对比、完整读屏或真机矩阵。
|
||||
|
||||
## 启动与资料
|
||||
|
||||
1. 读取 AGENTS.md、docs/tasks/README.md、ACTIVE.md、docs/status.md、tests/README.md 和本卡;核对真实分支/HEAD/未提交改动。单目录串行,不切换正在使用的分支,不覆盖未提交内容,不新建 clone/worktree。
|
||||
2. 先让本卡与 README 入口进入可追溯提交,再从包含本卡和前置实现的实际提交建立 `feat/color-swatch-picker-public`,记录完整起点 SHA。base 只是最低祖先,不代表已包含本卡。不合 main、不 push。
|
||||
3. 运行 `node scripts/task-check.mjs COLOR-SWATCH-PICKER`,实施启动后才更新 ACTIVE 与卡状态;缺依赖显式 `pnpm install --frozen-lockfile`,不重生成锁文件。
|
||||
4. 在只读参考仓库逐项 `git show <upstream>:<path>` 读取头部 sources,包括完整 MDX 和全部示例;不按当前官网覆盖固定基线,不改上游或运行 React 包装 Vue。
|
||||
5. 阅读颜色决策与当前 value/model、ColorSwatch、choice/shared、私有 Picker、相关测试及 tests/package/README.md。审计固定源所依赖的实际 RAC 契约,不能把中文 API 简表当作全部能力;资料不足时明确列出待确认行为。
|
||||
|
||||
## 实施顺序
|
||||
|
||||
### 1. 契约与最小完整组合
|
||||
|
||||
- 建立“固定源 API → Vue API → DOM/ARIA/状态 → 证据”映射,记录底座选型。注意:固定源测试明确为 `listbox` / `option`,不能因为单选而直接做成 RadioGroup。优先复用已有集合/焦点能力和颜色接受值模型;若采用 Reka,先验证安装版本的受控拒绝、焦点、禁用和方向键,不新增另一套颜色接受状态。
|
||||
- 公开 ColorSwatchPicker/ColorSwatchPickerRoot、ColorSwatchPickerItem、ColorSwatchPickerSwatch、ColorSwatchPickerIndicator,以及实际 Props、作用域插槽状态、按需实例类型;公开 colorSwatchPickerVariants 及类型。Root 别名共用实现。
|
||||
- 保留 size=xs/sm/md/lg/xl、variant=circle/square、layout=grid/stack,默认 md/circle/grid。不要把 layout=grid 误做成表格式 ARIA grid:固定样式实际是 flex-wrap。
|
||||
- 普通值使用 v-model,保留需要的 value/defaultValue 兼容规则;输出本库 Color。核验无初值、显式 null、空集合、选中值不在候选中、选中项移除等默认行为后明确文档与测试,不擅自选第一项或清空。
|
||||
- 先打通 Root → Item(color) → Swatch + Indicator 的公开 basic:鼠标选择、键盘进入与选择、选中样式、事件和受控更新均真实可用,再扩展其余示例。
|
||||
|
||||
### 2. 选择、焦点与共享颜色
|
||||
|
||||
- 覆盖非受控、受控接受/拒绝/同值重试、外部替换;父拒绝后 aria-selected、Indicator、样式和表单值保持接受状态。焦点与接受选择分开,不能用焦点变化伪造选中。
|
||||
- 颜色比较复用现有模型并审计等价格式(Hex/RGB/HSL)、alpha、灰色色相和浮点精度;不要为了匹配候选色反写或量化接受值。明确重复/等价候选颜色的选择与焦点规则,不以颜色字符串作为唯一 Vue key 强制合并项目。
|
||||
- 覆盖根/单项禁用、动态候选增删重排和颜色变更、当前焦点项删除、空集合和全部禁用;验证 Tab/Shift+Tab、方向键、Home/End、Enter/Space 的固定版本实际行为、循环/边界与 RTL。grid 换行的方向移动需真实几何验证,不能以 jsdom 假布局宣称通过。
|
||||
- 根和项有正确可访问名称、选中/禁用状态及焦点入口;无颜色感知名称能力时,允许显式 aria-label 并记录自动名称差异,不能只展示一块无名称颜色。渲染函数示例改作用域插槽,透出真实状态。
|
||||
- 核验 name/form、提交序列化、reset、外部 form 和禁用排除在固定版本是否支持。支持的能力复用 choice/表单设施并验证;不支持的列为明确差异,不凭空增加 required/validate 等字段 API。reset 必须涵盖父受控值未变时的真实 DOM 恢复。
|
||||
- 核验省略全部自身值属性时与私有 ColorPicker owner 的继承;若固定源支持此组合,则复用现有接受值协议并验证显式自身值覆盖、动态归属切换,以及 Field/Area/Slider/Swatch 联动。不能让每个 Item 提供 owner 导致后续兄弟控件读取错误颜色;继承组合避免重复完整颜色提交/reset。
|
||||
- 定义 attrs/ARIA、class/style、原生可取消事件、ref/focus 的归属;明确缺 Root/缺 Item、未知包装支持边界。不执行未知组件 setup/render 探测元数据,不操作 Vue 私有 ref。
|
||||
|
||||
### 3. 源样式与中文文档
|
||||
|
||||
- 移植完整 color-swatch-picker CSS/tv,使用 hv- 前缀,保留来源、固定 SHA 和 Apache 声明。核对 data-slot/data-selected/data-disabled/data-focus-visible、--color-swatch-current 与真实节点;保留选中缩放/边框、透明棋盘、hover、焦点、浅深主题、两种形状、五种尺寸、两种布局与 reduced-motion。
|
||||
- Indicator 保留固定默认勾选图标和明暗颜色判定,自定义插槽可替换;验证浅色背景下实际 computed color 与可见性。基线选择器若有实际缺陷,做最小适配并记录,不能以“CSS 已拷贝”代替显示验收。
|
||||
- 新建 `/components/color-swatch-picker`,标题“ColorSwatchPicker 颜色色块选择器”,介绍、结构、示例顺序、API/插槽/状态表和样式参考按固定 MDX 迁移。
|
||||
- 完整迁移 basic、variants、sizes、disabled、stack-layout、default-value、controlled、custom-indicator、render-function、custom-styles,恰好 10 个基线示例;颜色、布局、文案保持基线,React 专属机制改为真实 Vue 写法并注明差异。
|
||||
- 演示只用公共导出;预览/复制/高亮共用同一 SFC;演示图标用官方 Tabler Vue。默认库内图标可移植固定源 SVG。表格沿用已有满宽布局,窄屏不靠缩小字号或横向拖动处理。
|
||||
- 增量更新导出、样式入口、navigation.ts;不整文件重写共享入口。
|
||||
|
||||
### 4. 验证与交付
|
||||
|
||||
- 新增 tests/color-swatch-picker.test.ts、tests/color-swatch-picker-demos.test.ts 和 tests/package/color-swatch-picker-contract.ts,登记 client-checks.json;旧 absent 列表仅移除本项,继续保留 ColorPicker 私有边界。
|
||||
- 运行头部 checks;新测试与产物契约由本任务创建,规划时不存在。若修改颜色/集合/表单共享层,按 tests/README.md 补相关使用者回归;不以减少断言、skip 或删除失败用例掩盖回归。
|
||||
- 用最终 tarball 验证全部导出、ESM/CSS、bundler/NodeNext 类型正反例、真实 SFC Props/插槽和按需实例类型;源码 alias 消费不代表产物通过。
|
||||
- 真实浏览器核对 5173 服务所属目录后检查 basic/controlled/disabled、Tab/方向键与换行/stack/RTL、明暗 Indicator、浅深主题/透明度/窄屏、适用表单及私有 owner 组合。浏览器检查需记录操作、可见结果与限制;类名存在、aria 属性变化、挂载成功均不是可点击/可见证据。
|
||||
- 同步 docs/compatibility.md、upstream.md、status.md、component-notes.md、verification.md 的本项事实;不提前标记 ColorPicker 完成,不顺手升级其他验证中组件。
|
||||
- 按 RESULT-TEMPLATE.md 写 docs/tasks/results/COLOR-SWATCH-PICKER.md,记录完整起点/实施 SHA、API 差异、10 例核销、场景→证据、命令结果、未完成与限制。实施后提交到任务分支;单独复核/集成需后续明确授权,不宣称已经独立复核。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
| 项目 | 通过条件 |
|
||||
| --- | --- |
|
||||
| 公共组合 | 消费者只从发布包导入五个具名导出、相关类型与 variants,完整 basic 可运行 |
|
||||
| 选择与焦点 | listbox/option 语义、鼠标/键盘、受控拒绝/重试、动态候选和禁用均符合记录契约 |
|
||||
| 颜色与组合 | 格式比较/alpha 不破坏接受值;共享 owner 按已确认契约联动且没有第二份颜色状态 |
|
||||
| 表单 | 实际支持的 name/form/reset/序列化有原生 FormData 与真实 DOM 证据;不支持项明示 |
|
||||
| 文档与视觉 | 10/10 基线例、完整 API、源样式状态映射和重点浏览器操作通过;差异可追溯 |
|
||||
| 发布与交接 | 头部 checks 全部通过,最终 tarball 类型/运行/CSS 可用,仓库内结果足够让下一 AI 接续 |
|
||||
|
||||
任何未满足条件都不能标记 accepted。外部环境导致无法验证时写出具体失败和可复现步骤,保留为未验;不得写成通过。全量客户端回归由后续集成阶段按仓库规则执行。
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
| 卡 | 用途 |
|
||||
| ----------------------------------------- | ----------------------------------------------------------- |
|
||||
| [COLOR-SWATCH-PICKER](COLOR-SWATCH-PICKER.md) | 公共色块选择集合迁移,含固定源 10 例与产物验收 |
|
||||
| [COLOR-SWATCH](COLOR-SWATCH.md) | 公共颜色值/Swatch家族 |
|
||||
| [COLOR-AREA](COLOR-AREA.md) | 复用二维颜色内核的公共 ColorArea 迁移 |
|
||||
| [COLOR-SLIDER](COLOR-SLIDER.md) | 复用轨道/通道内核的公共颜色滑块与 9 例迁移 |
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
# COLOR-SWATCH-PICKER 交付 / 接续
|
||||
|
||||
- 分支、起点SHA、实施SHA:`feat/color-swatch-picker-public`;起点 `fa4146ee0b5805e388a6c241c31c69900eabeb18`(含任务卡与 README 入口的 `docs: plan public ColorSwatchPicker migration`,前置 HEAD `7287318d86112159f9a9c4c4beb9bc1cdbdf1942`);实施提交 `8d9adda8da702f0c7dabbf290ad03eb446a25570`;结果提交见本文件所在提交。由主会话亲自实施/自测,未委派其他 AI,不宣称独立复核;未合 main、未 push。
|
||||
- 改动:
|
||||
- 组件:`packages/vue/src/components/color-swatch-picker/{ColorSwatchPicker,ColorSwatchPickerItem,ColorSwatchPickerSwatch,ColorSwatchPickerIndicator}.vue`、`context.ts`、`types.ts`、`navigation.ts`(固定源 ListKeyboardDelegate 语义的几何/顺序键盘移动)。包根公开五具名导出(`ColorSwatchPicker`≡`ColorSwatchPickerRoot` 共用实现)、Props/作用域插槽/`ColorSwatchPickerExpose`/`ColorSwatchPickerItemExpose` 与 `colorSwatchPickerVariants`/`ColorSwatchPickerVariants`。
|
||||
- 样式:`packages/styles/components/color-swatch-picker.css`(ce90ea3 移植、hv- 前缀、Apache-2.0;两处最小适配见下)、`colorSwatchPickerVariants`(slots base/item/swatch/indicator,layout/size/variant 默认 md/circle/grid)。
|
||||
- 文档:`apps/docs/components/color-swatch-picker.md`、10 个 `apps/docs/demos/color-swatch-picker-*.vue`、`navigation.ts` 增量一项;color-area/color-field/color-slider/color-swatch 相关组件段改为仅 ColorPicker 私有。
|
||||
- 测试/契约:`tests/color-swatch-picker.test.ts`(24 项)、`tests/color-swatch-picker-demos.test.ts`(7 项)、`tests/package/color-swatch-picker-contract.ts`、`client-checks.json` 新契约(`color-field` absent 仅移除 ColorSwatchPicker,ColorPicker 保留)、`check-client.mjs` 新增运行时/d.ts 断言。
|
||||
- 记录:`docs/{compatibility,upstream,component-notes,verification,status}.md` 与本结果。
|
||||
|
||||
## 固定源 API → Vue API → DOM/ARIA/状态 → 证据
|
||||
|
||||
| 固定源(HeroUI 3.2.6/RAC 1.21.1) | Vue API | DOM/ARIA/状态 | 证据 |
|
||||
| --- | --- | --- | --- |
|
||||
| `ColorSwatchPicker`(Root,RAC ListBox) | `ColorSwatchPicker`/`ColorSwatchPickerRoot`,`modelValue`/`value`/`defaultValue` + `update:modelValue`/`change` | `role=listbox`、`aria-orientation=vertical`、`aria-label`(默认本地化)、`data-slot=color-swatch-picker`、hv- BEM 修饰 | 单测 baseline;浏览器15个实际 listbox |
|
||||
| `ColorSwatchPicker.Item`(ListBoxItem) | `ColorSwatchPickerItem`,`color`/`isDisabled`/`as` + 作用域插槽 | `role=option`、`aria-selected`、`aria-disabled`、`aria-label`、`data-selected/disabled/hovered/focused/focus-visible/pressed`、`--color-swatch-current` | 单测 + 浏览器 a11y 快照(option/image 节点) |
|
||||
| `ColorSwatchPicker.Swatch`(RAC ColorSwatch) | `ColorSwatchPickerSwatch`,`color`/`colorName`/`as` | `role=img`、`data-slot=color-swatch-picker-swatch`、背景色 + 棋盘 | 单测 + 浏览器计算样式 |
|
||||
| `ColorSwatchPicker.Indicator`(含 render fn children) | `ColorSwatchPickerIndicator`,`as` + 作用域插槽替换勾选 | `aria-hidden`、`data-light-color`、默认勾选 SVG | 单测 + 浏览器计算色 |
|
||||
| `render` 渲染函数 | `as` + 原生 attrs + 根/项作用域插槽(真实状态) | attrs 透传(如 `data-custom`) | render-function 示例与单测 |
|
||||
| 无(RAC 无 name/form/required/validate) | 不提供 | 组合时由 owner 隐藏值提交 | 见表单行 |
|
||||
|
||||
## 基线示例核销(10/10)
|
||||
|
||||
basic、variants、sizes、disabled、stack-layout、default-value、controlled、custom-indicator、render-function、custom-styles 全部迁移并在 `color-swatch-picker.md` 按固定 MDX 顺序(用法→结构→8 示例→自定义样式)渲染;演示只用公共导出、预览/复制/高亮同一 SFC、图标为官方 Tabler(custom-indicator 的 HeartFill → `IconHeartFilled`);render-function 按约定改为作用域插槽(根 `data-custom="foo"` + 项状态绑定真实属性)。单测 `tests/color-swatch-picker-demos.test.ts` 锁定预览顺序/类名/状态/文案。
|
||||
|
||||
## 验收场景 / 复核问题
|
||||
|
||||
| 验收场景 / 复核问题 | 断言或复现步骤 | 实际结果 / 限制 |
|
||||
| --- | --- | --- |
|
||||
| 公共组合(五导出+类型+variants,basic 可运行) | `node scripts/check-package.mjs color-swatch-picker ...`;文档页 basic 预览 | tarball ESM 五导出、`ColorSwatchPicker===ColorSwatchPickerRoot`、variants 运行时类名、CSS token 通过;浏览器 basic 7 项真实渲染/点击可选 |
|
||||
| listbox/option 语义 | a11y 快照 | `[listbox]`+`[option]`+`[image]`,`aria-selected`/`aria-disabled`/名称正确(浏览器快照实录) |
|
||||
| 鼠标选择 | 真实点击 option | 选择生效、焦点落该项、鼠标交互 `data-focus-visible` 为空;可取消 `mousedown`(preventDefault)阻止选择(单测) |
|
||||
| 键盘:焦点≠选择 | focus 后按 ArrowDown | 焦点移动、`aria-selected` 不变(浏览器实测 selected 索引保持) |
|
||||
| Enter/Space | 聚焦后按 Enter/Space | 选择当前项;重复按同一项不再发事件 |
|
||||
| grid 换行方向移动(真实几何) | RTL 120px 三列网格聚焦 #D946EF 按 ArrowDown | 移到下一行同列 #06B6D4;ArrowUp 回退;末列下方无同列项时不移动(浏览器几何) |
|
||||
| stack/RTL/边界 | stack 按上下;RTL 按 ArrowRight | stack 上下按顺序、左右无效(交给浏览器滚动)、跳过禁用项;RTL grid ArrowRight=前一项;End 后 ArrowDown 不循环、Home/End 正常 |
|
||||
| PageUp/Down、typeahead | PageDown 在不可滚动容器;输入名称前缀 | PageDown→末项、PageUp→首项;typeahead 按项名称前缀聚焦(单测 + 浏览器 PageDown) |
|
||||
| Tab/Shift+Tab 单停靠点 | Tab 进入列表 | 聚焦已选项(#F43F5E80)且 `data-focused`/`data-focus-visible=true`、漫游 tabindex(项 0 / 根 -1)正确 |
|
||||
| 受控接受/拒绝/重试/外部替换 | 单测 controlled 用例;浏览器 owner 用例 | 拒绝后 aria-selected/Indicator/样式保持接受值,同一手势重试再发;外部替换同步 |
|
||||
| 动态候选:增删/重排/颜色变更/焦点项删除/空集合/全禁用 | 单测 dynamic 用例 | 移除选中项后值保留(不自动清空/不选第一项);焦点项移除后 tabindex 回根;空集合仍渲染 listbox;禁用项不可聚焦不可选 |
|
||||
| 重复/等价候选 | 两个同色项、hex/rgb/hsl、alpha、灰色色相 | 同色两项独立 DOM(不合并),选一个两者均显示选中(记录规则);等价格式按 hexa 键匹配、alpha 1/255、灰度色相折叠;接受值不反写不量化(选中输出候选自身空间/精度,单测断言 hsl 输出) |
|
||||
| 共享 owner 组合 | 临时表单页(验后删除)+ 单测 composition | 省略自身值继承私有 ColorPicker owner、显式值覆盖、动态增删属性切换归属;Field/Area/Slider/Swatch 联动沿用 owner,Item 不提供 owner;单一 `name=color` 隐藏值 |
|
||||
| 表单 | 浏览器 FormData + reset | 真实点击后 FormData=`rgba(217, 70, 239, 1)`(单一完整精度条目);受控拒绝后保持 `rgba(139, 92, 246, 1)`;`reset()` 恢复隐藏值与 `aria-selected` DOM。固定源不支持 name/form/reset/required/validate,本库不新增这些字段 API(明确差异,见文档“表单”节) |
|
||||
| 源样式状态映射 | 计算样式 + CSS 移植 | data-selected 缩放 0.77/边框 `--color-swatch-current`、hover 1.1、焦点环、禁用、两种形状/五种尺寸/两种布局、reduced-motion 保持基线 |
|
||||
| 透明棋盘/明暗 Indicator | 浏览器计算样式 | rgba/透明 swatch 背景含 `repeating-conic-gradient`;浅色 swatch `data-light-color=true` 且勾选计算色 `rgb(0,0,0)`、深色为白(适配后实测) |
|
||||
| 浅深主题 | 切换外观 radios | `mac light`→`mac dark`,选中项 `--field-shadow` 实际变化、swatch 色值不变 |
|
||||
| 可访问名称差异 | 文档 + 单测 | 自动名称为 hex/hexa/透明文案,显式 `aria-label` 覆盖;固定源感知色名未实现(记录差异) |
|
||||
| 头部 checks | 见下命令结果 | 全部通过 |
|
||||
|
||||
## 命令结果(最终状态)
|
||||
|
||||
- `pnpm exec vitest run tests/color-swatch-picker.test.ts tests/color-swatch-picker-demos.test.ts tests/color-swatch.test.ts tests/color-swatch-demos.test.ts tests/color-foundation.test.ts tests/color-picker-composition.test.ts tests/color-picker-protocol.test.ts tests/regressions/color tests/docs-shell.test.ts`:11 文件/129 项通过(含新增 2 文件/31 项)。
|
||||
- `pnpm typecheck`:通过(含发布类型正反例在源码路径下的检查)。
|
||||
- `pnpm build:docs`:通过(保留既有大 chunk 提示,不是组件 SSR 验收)。
|
||||
- `node scripts/check-package.mjs color-swatch-picker color-swatch color-foundation color-picker-protocol color-field`:五契约最终 tarball 独立安装、ESM/CSS/别名/variants、strict NodeNext+bundler 类型正反例、SFC Props/插槽/实例类型、d.ts 不泄漏 Reka 类型全部通过。
|
||||
|
||||
## 两处最小样式适配(记录)
|
||||
|
||||
1. 指示器明暗规则:上游嵌套 `&[data-light-color="true"] & > *` 在单层指示器结构上永远匹配不到(自成为后代),本库改为 `&[data-light-color="true"] > *`。浏览器实测浅色 swatch 勾选为黑色、深色为白色。
|
||||
2. `__swatch` 透明棋盘:上游 picker CSS 无棋盘(RAC ColorSwatch 内联只给纯色),本库沿用公开 ColorSwatch 的棋盘底纹呈现透明度。浏览器实测 rgba/透明 swatch 背景含 `repeating-conic-gradient`。
|
||||
|
||||
## 未完成与下一会话
|
||||
|
||||
- 未做:SSR/水合/Nuxt 服务端适配、逐像素自动对比、完整读屏矩阵、真机矩阵(范围约定内不投入)。截图工具需要可见桌面窗口,本会话不可用,视觉结论以真实浏览器计算样式/几何/事件结果替代;窄屏无缩放工具,换行用 120px 约束容器(同一 flex-wrap 机制)验证;禁用项 `pointer-events:none` 使真实点击工具报不可点击(等价于用户点击穿透),键盘跳过与禁用选择另有单测。
|
||||
- 未宣称独立复核/集成:卡状态为 implemented;合入 main、推送与全量集成回归需用户后续授权(按仓库规则由集成阶段执行全量 `pnpm test`)。
|
||||
|
||||
|
||||
## 独立复核(2026-10-27,未通过)
|
||||
|
||||
复核基线:`efb53d4ce711fd8dda6bb63c4551aaac802b469e`;主会话独立检查代码、公开文档和高风险输入路径,未委派其他会话。结论:有阻断问题,保持 implemented,不合 main、不 push。下列用例追加到现有 `tests/color-swatch-picker.test.ts` 的 `ColorSwatchPicker activation lifecycle and dynamic focus` 分组,属于现有交互契约遗漏,不新增专项矩阵。
|
||||
|
||||
| 编号 / 优先级 | 问题与影响 | 复现与实际证据 | 修复要求 |
|
||||
| --- | --- | --- | --- |
|
||||
| R1 / P2 | 右键/中键按下同样选择颜色;打开菜单或辅助鼠标操作会误改值 | 原生 `mousedown(button=2)` 触发 update:modelValue,预期无事件。真实 5173 basic 页对 #D946EF 右键后该 option 变为 selected | 只允许主鼠标激活,保留取消能力,补中键反例 |
|
||||
| R2 / P1 | 动态禁用当前聚焦项后,根仍 tabindex=-1、其余项也为 -1,列表失去键盘入口 | focus 第一项→将该项 isDisabled 改 true→两次 nextTick;所有未禁用节点 tabindex=0 的数量为 0(预期 1)。根的 watch 只跟踪 ordered(),没有跟踪项 disabled | 监听实际可用集合并恢复合法入口/焦点,兼顾根禁用与重新启用、所有项禁用、焦点移除 |
|
||||
| R3 / P2 | 鼠标释放没有清理 isPressed/data-pressed | 原生主键 mousedown→同项 mouseup→nextTick,data-pressed 仍为 true(预期移除);只在 mouseleave、blur 或 keyup 等其他路径清理 | 完整处理释放/取消/失焦/禁用生命周期,作用域插槽与 DOM 状态一致 |
|
||||
| R4 / P2 | 仅发送 click 的辅助技术激活无法选色 | 对未选 option 分发可取消的 `click(detail=0)`,aria-selected 仍为 false;代码只监听 mousedown、没有 click 路径 | 提供 click-only 激活路径,避免正常鼠标或键盘的兼容 click 重复提案;保留 preventDefault、禁用及受控拒绝/重试语义 |
|
||||
|
||||
独立验证:原提交 `pnpm test` 全量 105 文件/1548 项通过;`pnpm typecheck` 通过。新增四项回归按上述正确期望均失败,未删除/降低断言;定向命令:`pnpm exec vitest run tests/color-swatch-picker.test.ts -t 'activation lifecycle and dynamic focus'`。筛选运行中其他用例由 Vitest 标记为未选择,不是源码新增 skip。
|
||||
|
||||
本轮未重跑 build:docs/tarball:已有明确交互阻断,先修同一问题表,再验证修复影响范围与产物。上一节的构建/产物通过仍为实施方证据,不称本轮独立通过。没有执行合并或推送;任务原有实现提交保持原样,本轮只增加回归与复核记录。
|
||||
|
||||
## 复核修复(2026-10-27,待增量复核)
|
||||
|
||||
修复提交 `adca8d0`(组件 + 回归),复核材料提交 `980930e`(复核记录与四项回归原样保留)。四项问题全部修复,浏览器验证时另发现并修复同族问题 F1。
|
||||
|
||||
| 编号 | 修复 | 断言或复现步骤 | 实际结果 |
|
||||
| --- | --- | --- | --- |
|
||||
| R1 | `onMousedown` 只处理 `button === 0`,其余按键直接交还原生行为(右键菜单、自动滚动);取消能力保留(`preventDefault` 的 mousedown 仍阻止选择) | 回归 `ignores secondary mouse buttons`(补中键反例)+ 真实文档页对 option 右键/中键 | 无 `update:modelValue`、`aria-selected` 不变、`data-pressed` 不产生;真实右键保留原生上下文菜单(工具因此被菜单阻塞),松开后选项未被选中 |
|
||||
| R2 | `enabled()` 计入根禁用;watch 改为监听“成员集合 + 各成员 disabled + 根 disabled”,焦点项不可用时清 `focused` 并在焦点仍在列表内时把焦点交回根(再由入口规则落点);`pressed` 同步清理 | 回归 `keeps an enabled tab entry after dynamically disabling the focused item`、`keeps legal tab entries for all-disabled items and a disabled root` | 动态禁用聚焦项后恰好一个可用 tab 停靠点且焦点不落 body;重新启用仍一个;全部项禁用时根为唯一入口;根禁用时 0 个停靠点、恢复后 1 个 |
|
||||
| R3 | 释放/取消/失焦/禁用全生命周期:项 `mouseup`(主键)与根 `mouseup` 清 `pressed`,`mouseleave`/`blur` 同时清 `pressed` 与按下归属标记,禁用/移除由 R2 的 watch 清理 | 回归 `clears pressed state after the primary mouse release`(含根上释放、拖出取消、按下夺焦场景) | 按下期间 `data-pressed=true`,松开/拖出/失焦/禁用后移除,作用域插槽 `isPressed` 与 DOM 一致 |
|
||||
| R4 | 项增加 `click` 激活路径:仅在 `detail === 0`(辅助技术/程序化激活)且本次手势未被按下路径处理时激活;正常鼠标/键盘的兼容 click 不重复提案 | 回归 `supports click-only activation used by assistive technology`、`keeps press ownership so normal clicks never re-propose` | click-only 选中颜色;按下后的兼容 click 不再发事件(一次手势一次提案);click-only 仍受 `preventDefault`、禁用与受控拒绝/重试语义约束 |
|
||||
| F1(新发现) | `noteBlur` 不再无条件清 `pressed`:按下新项导致旧项失焦时会误清新按压状态 | 真实浏览器 DOM 序列(按下→释放→中键→click-only)+ 回归 `keeps the press state when focus moves from a previously focused item` | 按下期间 `data-pressed=true` 保持到释放;浏览器实测 `duringPress` 显示 `true/pressed`,`afterRelease` 清除 |
|
||||
|
||||
浏览器复核(真实文档页,Vite HMR 后重载):初始无选中;主键按下项 1 变 `selected` 且 `data-pressed` 存在,`mouseup` 后 `data-pressed` 移除;中键按下无任何变化;`detail=0` 的 click-only 激活选中项 3。真实右键保留原生菜单且未选中(R1 修复前复核记录中的误选不复现)。本轮 click 工具在右键菜单后出现桌面连接超时,其余步骤改用页面内派发的真实 DOM 事件并逐次等待 Vue 刷新,结果与单测一致。
|
||||
|
||||
修复后验证:定向 `pnpm exec vitest run tests/color-swatch-picker.test.ts -t 'activation lifecycle and dynamic focus'` 6 项通过(复核 4 项 + 新增中键/根禁用/全部禁用/按下夺焦等反例);全量 `pnpm test` 105 文件/1554 项通过;`pnpm typecheck`、`pnpm build:docs` 通过;`node scripts/check-package.mjs color-swatch-picker color-swatch color-foundation color-picker-protocol color-field` 五契约最终 tarball 通过。状态保持 implemented、不合 main、不 push,等待同一问题表的增量复核。
|
||||
|
||||
|
||||
## 增量独立复核(2026-10-27,仍有 R3 取消边界)
|
||||
|
||||
复核 HEAD:`3a4142e89122b3758458909a42a10c6f4e4fc2f4`;实现修复 `adca8d0`。未改变组件实现,未合 main、未 push。按原 R1–R4 问题范围复核,不另开读屏/真机等专项。
|
||||
|
||||
| 原问题 | 本轮结论与证据 |
|
||||
| --- | --- |
|
||||
| R1 | 原测试通过;真实 5173 basic 页右键 #D946EF、中键 #8B5CF6 均未选中,随后主键点击 #F43F5E 正常选中 |
|
||||
| R2 | 原动态禁用回归、全部项禁用/根禁用恢复回归通过;修复监听成员禁用值,合法 Tab 入口恢复 |
|
||||
| R3 | 普通 mouseup、mouseleave、项 blur 和禁用路径通过;**窗口失焦取消仍未覆盖**。主键按下→`window.dispatchEvent(new Event("blur"))`→nextTick,data-pressed 仍为 true。窗口失焦不同于元素 blur,失去窗口焦点时 document.activeElement 可以仍是原 option,现有项 onBlur 不会负责清理。与原“完整释放/取消/失焦生命周期”同一问题,不是新功能要求 |
|
||||
| R4 | 单独 click-only 激活、取消、禁用、普通兼容 click、受控拒绝后连续两次 click-only 提案通过;但 R3 的旧 pressActivated 标记会连带吞掉窗口失焦取消后的首次 click-only 重试:受控父拒绝主键提案→窗口 blur→click(detail=0),事件数仍为 1,期望 2 |
|
||||
|
||||
独立执行:原修复状态的定向 8 文件/83 项通过,`pnpm typecheck` 通过。真实文档页主键点击后 aria-selected=true 且 data-pressed 已移除。追加到现有组件测试的 `ColorSwatchPicker activation cancellation boundaries` 3 项:普通受控 click-only 连续重试通过;窗口失焦清理与随后重试 2 项失败。复现命令:`pnpm exec vitest run tests/color-swatch-picker.test.ts -t 'activation cancellation boundaries'`。这些是 DOM 事件与状态回归;未声称实际操作系统切换窗口验收。
|
||||
|
||||
剩余修复要求:窗口失焦时统一取消当前 press 并清除点击去重归属;监听器应随组件生命周期清理,避免影响其他 Picker;保留正常一次手势只提案一次、拒绝后可重试。若采用根级取消机制,确保项内 pressActivated 与根 pressed 同步失效。仍保持 implemented,暂不建议合并/推送。本轮没有重复构建或全量回归,先处理已确认失败;后续按同一问题表增量验收。新增回归与本轮复核记录尚未提交。
|
||||
|
||||
|
||||
## 集成人接手修复与验收(2026-10-27,通过)
|
||||
|
||||
用户已明确授权主会话自行修复、合入 main 并推送。接手基线 `3a4142e89122b3758458909a42a10c6f4e4fc2f4`,最终修复提交 `3c8473d5974f34f132b129362dc95d405ff9eaae`,包含前轮未提交的边界回归,未删减原断言。
|
||||
|
||||
- R3 剩余边界:根组件通过 VueUse 的生命周期监听绑定自身 ownerDocument.defaultView 的 blur,统一调用当前注册项的 cancelPress,同时清理 pressed 和各项的 pressActivated;根 pointercancel 也走同一取消路径。项禁用、blur、mouseleave 复用项级清理,不改变接受颜色;监听器卸载时自动清理。
|
||||
- 原 R1/R2/R4 与 R3 的剩余窗口取消问题全部关闭。补充多 Picker 隔离回归,取消一个根不清除另一个根的按压或兼容 click 去重归属;窗口失焦后第一次 click-only 可以立即重试。组件 34 项通过;全量客户端 105 文件/1558 项通过;typecheck、build:docs 通过。
|
||||
- 最终 tarball 五契约 `color-swatch-picker color-swatch color-foundation color-picker-protocol color-field` 通过,含 ESM/CSS 与 NodeNext/bundler 类型正反例。首次离线安装因 TypeScript tarball 未缓存失败;后续联网重新运行统一入口成功,未把离线失败计为通过。
|
||||
- 真实 5173 浏览器临时公开组合验证:受控父拒绝主键提案→保持焦点的 window blur DOM 事件→pressed 移除→click-only 再次提案,页面显示 PASS、总提案 2 次、接受选择不变。该验证在真实浏览器引擎派发窗口事件,不声称实际操作系统切窗验收。临时页面已删除,可复现序列保存在组件测试中。
|
||||
- 卡状态 accepted;本条记录验收完成,实际合并 SHA、集成回归与远端同步写入后续集成记录。支持与未投入范围仍按 AGENTS;ColorPicker 仍私有。
|
||||
|
||||
|
||||
## main 集成(2026-10-27)
|
||||
|
||||
- 最终修复:`3c8473d5974f34f132b129362dc95d405ff9eaae`;验收记录:`8e8fc69`。
|
||||
- 合并提交:`457d340d7b6499899555d523f3e23ae497d71e62`(main,no-ff);与任务分支内容一致,无合并冲突。
|
||||
- main 集成回归:`pnpm test` 105 文件/1558 项通过;最终实现的 typecheck、build:docs 与五契约 tarball 已通过,合并未改变实现或产物。
|
||||
- 用户已授权推送 origin/main;本记录随 main 推送。实际同步以推送后远端回读 SHA 与 git status 为准。
|
||||
- 卡状态 accepted,无待修复阻断;ColorPicker 仍私有,下一任务不自动启动。
|
||||
@@ -304,3 +304,11 @@ CSS/variants 仅加 hv- 前缀并保留 Apache-2.0 来源;弹层 origin/placem
|
||||
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:读取 `packages/react/src/components/color-field`、`color-input-group` 的 index/实现、ColorField 基线测试、两套 CSS/tv、中文 `(colors)/color-field.mdx` 和引用的全部 13 个演示(顺序见任务卡 sources)。复用此前私有字段/颜色适配与源 CSS;本轮公开具名部件/变体/文档,不复制 React hook、不执行 React,不新增底座/依赖。
|
||||
|
||||
variants 保留 ce90ea3 结构并加 hv-;原 CSS 来源及 Apache 声明保留。唯一布局适配是在 `.hv-color-input-group__input` 增加 min-width:0,修正原生 Vue input 在 100px 通道组内的固有最小宽度及后缀越界;浏览器几何和兼容差异见 [COLOR-FIELD 结果](tasks/results/COLOR-FIELD.md)。上游 render 换标签通过 Vue as/attrs 实现,渲染状态通过作用域插槽/styleFn 暴露。
|
||||
|
||||
## COLOR-SWATCH-PICKER ColorSwatchPicker(2026-10-27)
|
||||
|
||||
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/color-swatch-picker/{index.ts,color-swatch-picker.tsx}`、`packages/react/tests/components/color-swatch-picker/color-swatch-picker.test.tsx`、`packages/styles/components/color-swatch-picker.css`、`packages/styles/src/components/color-swatch-picker/color-swatch-picker.styles.ts`,中文 `(colors)/color-swatch-picker.mdx` 与 `demos/cn/color-swatch-picker` 全部 10 例(basic/variants/sizes/disabled/stack-layout/default-value/controlled/custom-indicator/render-function/custom-styles)。
|
||||
|
||||
CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源,`size/variant/layout` 默认 `md/circle/grid` 与全部 BEM 类名保持基线。两处最小适配已记录:1) 指示器明暗规则的上游嵌套选择器 `&[data-light-color="true"] & > *` 永远匹配不到自身节点,改为 `> *` 直接子级(浏览器实测浅色 swatch 勾选为黑色);2) swatch 保留 ColorSwatch 的透明棋盘底纹(上游该视觉由 RAC ColorSwatch 内联样式提供,picker 的 `__swatch` CSS 本身没有棋盘)。默认勾选 SVG(`polyline 2.5 6 5 8.5 9.5 3`)为固定源图标移植。
|
||||
|
||||
行为契约直接审计固定依赖的 npm 官方发布源码(`react-aria-components@1.21.1` 的 ColorSwatchPicker/ColorSwatch/ListBox、`react-stately` useColorPickerState/useMultipleSelectionState、`react-aria` useSelectableCollection/useSelectableItem/useOption/ListKeyboardDelegate/DOMLayoutDelegate/useColorSwatch),没有安装或执行 React、没有移植其 hook。要点:listbox/option 单选、selectionBehavior 默认 toggle(焦点与选择分离)、disallowEmptySelection、默认值 `#000000`、`setColor(null)` 被忽略、选择键为 `color.toString("hexa")`、grid 的方向键按 DOM 几何跨换行行移动而左右按顺序、stack 布局左右键交还浏览器、无边界循环、typeahead/页跳与本地化默认名 `colorSwatchPicker`。React `render` 映射为 `as` + 原生 attrs + 作用域插槽;感知色名、name/form 提交与 required/validate 字段 API 未移植,作为明确差异记录。来源与差异见 [任务结果](tasks/results/COLOR-SWATCH-PICKER.md)。
|
||||
|
||||
@@ -101,3 +101,18 @@ ColorField/Root、共享 InputGroup 与字段具名别名、公共 Props/slots/e
|
||||
完整 API 映射、13例核销、复现与边界见 [COLOR-FIELD 结果](tasks/results/COLOR-FIELD.md)。未执行SSR/水合/Nuxt服务端、逐像素/完整读屏/真机矩阵;系统IME未完整验收。
|
||||
|
||||
COLOR-FIELD 集成:用户于2026-10-27授权合并与推送,合并SHA `ec350c5f4e92d7dc7c9ccdc7e3e3ae9bfa231170`。集成后相关组件页明确仅Picker家族仍为私有颜色协议,保留既有文档断言;全量103文件/1517项、文档构建通过。未重复无变化的类型/tarball/浏览器专项。
|
||||
|
||||
## COLOR-SWATCH-PICKER(2026-10-27)
|
||||
|
||||
ColorSwatchPicker/Root、Item、Swatch、Indicator、colorSwatchPickerVariants 与固定源中文 10 例完成。由主会话亲自实施与自测,未委派其他 AI,未宣称独立复核。
|
||||
|
||||
- 任务定向 10 文件/117 项通过(含新 color-swatch-picker 2 文件/31 项),加 docs-shell 后 11 文件/129 项;`pnpm typecheck`、`pnpm build:docs` 通过(保留既有大 chunk 提示,不是组件 SSR 验收)。
|
||||
- `node scripts/check-package.mjs color-swatch-picker color-swatch color-foundation color-picker-protocol color-field`:最终 tarball 独立安装、五具名导出与 Root 别名、variants 运行时类名、ESM/CSS token(含 data-light-color 与棋盘)、strict NodeNext/bundler 类型正反例、SFC Props/插槽/实例类型通过;声明不泄漏 Reka 类型;`color-field` 的 absent 仅移除 ColorSwatchPicker,ColorPicker 私有边界保留。
|
||||
- 真实浏览器(Chrome headless,1280×655 视口):文档 5173(cwd=apps/docs)15 个实际选择器/10 个预览渲染正确;真实鼠标点击选择并聚焦(鼠标无焦点环);Enter/Space 选择、方向键只移动焦点不选择;RTL 120px 网格 ArrowDown 跨换行行到同列(#D946EF→#06B6D4)、ArrowRight 按 RTL 顺序、End/Home、边界不循环;stack 上下按顺序、左右无效、跳过禁用项、PageDown 跳末项;Tab 进入聚焦已选项且 data-focused/data-focus-visible=true、漫游 tabindex 正确。
|
||||
- 透明度/明暗:rgba/透明 swatch 计算样式含 repeating-conic 棋盘;白色 swatch `data-light-color=true` 且勾选计算色为黑、深色为白(上游选择器缺陷适配后实测);选中项勾选 scale 1、未选中 scale 0;重复颜色保留两个独立 option,选一个两者均显示选中。浅/深主题切换后选中项 --field-shadow 实际变化、swatch 色值不变。
|
||||
- 临时表单/owner 页(同一开发服务器,验后删除):省略自身值时继承私有 ColorPicker owner;真实点击后隐藏值/FormData 更新为 `rgba(217, 70, 239, 1)`(单一 name=color 条目),受控父级拒绝后 FormData 与 aria-selected 保持接受值,表单 reset 恢复隐藏值与 DOM 选中态。
|
||||
- 限制:截图工具需要可见的桌面窗口,本会话不可用;改以计算样式/几何/真实事件结果为证。窄屏没有视口缩放工具,换行行为用 120px 约束容器(同一 flex-wrap 机制)验证。禁用项 pointer-events:none,真实点击工具报不可点击(等价于用户点击穿透),键盘跳过与禁用选择另有单测覆盖。
|
||||
|
||||
COLOR-SWATCH-PICKER 复核修复(2026-10-27):独立复核四项交互缺陷(右键误选、动态禁用丢 Tab 入口、按压状态残留、click-only 激活无效)已修复,另修复浏览器验证中发现的“按下夺焦清按压状态”。定向 6 项激活生命周期回归、全量 105 文件/1554 项、typecheck、build:docs 与五契约 tarball 全部通过;真实文档页复核主键按下/释放的 `data-pressed` 生命周期、中键忽略、右键保留原生菜单且不选中、`detail=0` click-only 选中。问题表与逐项证据见 [任务结果](tasks/results/COLOR-SWATCH-PICKER.md);状态保持 implemented,待增量复核,未合 main、未 push。
|
||||
|
||||
COLOR-SWATCH-PICKER 最终接手验收(2026-10-27):窗口失焦/指针取消统一清除按压与兼容 click 去重归属,修复 `3c8473d`。原问题全部关闭,组件34项、全量105文件/1558项、typecheck、build:docs、五契约最终tarball通过;真实浏览器中验证受控拒绝后 window blur DOM 事件取消与第一次 click-only 重试通过,未宣称实际系统切窗验收。状态 accepted,已获合入/推送授权,准确集成状态见任务结果。
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
/* Adapted from HeroUI ce90ea3 (packages/styles/components/color-swatch-picker.css),
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. Modified: hv- class prefix.
|
||||
* Baseline adaptations recorded in docs/tasks/results/COLOR-SWATCH-PICKER.md:
|
||||
* 1. The light-color rule is corrected to target the indicator's own children;
|
||||
* the upstream nested `&[data-light-color] & > *` never matches its own node.
|
||||
* 2. The swatch keeps the ColorSwatch transparency checkerboard: the upstream
|
||||
* picker relies on RAC ColorSwatch inline styles for the plain color fill. */
|
||||
/* ==========================================================================
|
||||
ColorSwatchPicker - A list of color swatches for selection
|
||||
========================================================================== */
|
||||
|
||||
/* Base styles */
|
||||
.hv-color-swatch-picker {
|
||||
@apply flex flex-wrap items-center gap-2;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Item - Individual swatch picker item
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply relative flex size-8 items-center justify-center rounded-2xl border-2 border-transparent outline-none no-highlight;
|
||||
|
||||
/* Cursor */
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
border-color 100ms var(--ease-out),
|
||||
box-shadow 100ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible,
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Selected state */
|
||||
&[data-selected="true"] {
|
||||
border-color: var(--color-swatch-current);
|
||||
box-shadow: var(--field-shadow);
|
||||
/* Shrink the swatch to reveal the white gap */
|
||||
.hv-color-swatch-picker__swatch {
|
||||
transform: scale(0.77);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Swatch - The color swatch visual
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply block size-full;
|
||||
|
||||
/* Inherit border-radius from item */
|
||||
border-radius: inherit;
|
||||
|
||||
/* Checkered background pattern for transparency (ColorSwatch baseline). */
|
||||
background:
|
||||
linear-gradient(var(--color-swatch-current), var(--color-swatch-current)),
|
||||
repeating-conic-gradient(#efefef 0% 25%, #f7f7f7 0% 50%) 50% / 16px 16px;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition: transform 100ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Indicator - Checkmark indicator for selected state
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-swatch-picker__indicator {
|
||||
@apply pointer-events-none absolute inset-0 z-10 flex items-center justify-center;
|
||||
|
||||
/* Checkmark SVG styles - default to white for dark backgrounds */
|
||||
& > * {
|
||||
@apply size-1/3 text-white;
|
||||
|
||||
/* Start scaled down - use translateZ(0) for GPU acceleration */
|
||||
transform: scale(0) translateZ(0);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
transition: transform 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Use black checkmark on light backgrounds (adapted selector, see header). */
|
||||
&[data-light-color="true"] > * {
|
||||
@apply text-black;
|
||||
}
|
||||
|
||||
/* Scale up when parent item is selected */
|
||||
.hv-color-swatch-picker__item[data-selected="true"] & > * {
|
||||
transform: scale(1) translateZ(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Layout variants
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-swatch-picker--grid {
|
||||
/* Default is already grid (flex-wrap) - no additional styles needed */
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker--stack {
|
||||
@apply flex-col;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Size variants
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-swatch-picker--xs {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply size-4 rounded-lg border;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker--sm {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply size-6 rounded-xl border-2;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker--md {
|
||||
.hv-color-swatch-picker__item {
|
||||
/* No styles as this is the default size */
|
||||
}
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker--lg {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply size-9 rounded-3xl border-3;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-color-swatch-picker--xl {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply size-10 rounded-3xl border-3;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Shape variants
|
||||
========================================================================== */
|
||||
|
||||
/* Circle variant (default) - no additional styles needed */
|
||||
.hv-color-swatch-picker--circle .hv-color-swatch-picker__item {
|
||||
/* Default is already circle - radius set per size */
|
||||
}
|
||||
|
||||
/* Square variant */
|
||||
.hv-color-swatch-picker--square {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply rounded-xl;
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
&[data-selected="true"] {
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Square variant - item radius for xs */
|
||||
.hv-color-swatch-picker--square.hv-color-swatch-picker--xs {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply rounded-md;
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-md;
|
||||
}
|
||||
&[data-selected="true"] {
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-md;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Square variant - item radius for sm */
|
||||
.hv-color-swatch-picker--square.hv-color-swatch-picker--sm {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply rounded-lg;
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
&[data-selected="true"] {
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-md;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Square variant - item radius for md (default) */
|
||||
.hv-color-swatch-picker--square.hv-color-swatch-picker--md {
|
||||
/* No styles as this is the default size */
|
||||
}
|
||||
|
||||
/* Square variant - item radius for lg */
|
||||
.hv-color-swatch-picker--square.hv-color-swatch-picker--lg {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply rounded-xl;
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
&[data-selected="true"] {
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Square variant - item radius for xl */
|
||||
.hv-color-swatch-picker--square.hv-color-swatch-picker--xl {
|
||||
.hv-color-swatch-picker__item {
|
||||
@apply rounded-xl;
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
&[data-selected="true"] {
|
||||
.hv-color-swatch-picker__swatch {
|
||||
@apply rounded-lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,3 +186,6 @@
|
||||
|
||||
/* Public ColorSwatch (COLOR-SWATCH). */
|
||||
@import "./components/color-swatch.css" layer(components);
|
||||
|
||||
/* Public ColorSwatchPicker (COLOR-SWATCH-PICKER). */
|
||||
@import "./components/color-swatch-picker.css" layer(components);
|
||||
|
||||
@@ -1828,6 +1828,60 @@ export const colorSwatchVariants = tv({
|
||||
|
||||
export type ColorSwatchVariants = VariantProps<typeof colorSwatchVariants>;
|
||||
|
||||
/** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */
|
||||
export const colorSwatchPickerVariants = tv({
|
||||
defaultVariants: {
|
||||
layout: "grid",
|
||||
size: "md",
|
||||
variant: "circle",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-color-swatch-picker",
|
||||
indicator: "hv-color-swatch-picker__indicator",
|
||||
item: "hv-color-swatch-picker__item",
|
||||
swatch: "hv-color-swatch-picker__swatch",
|
||||
},
|
||||
variants: {
|
||||
layout: {
|
||||
grid: {
|
||||
base: "hv-color-swatch-picker--grid",
|
||||
},
|
||||
stack: {
|
||||
base: "hv-color-swatch-picker--stack",
|
||||
},
|
||||
},
|
||||
size: {
|
||||
lg: {
|
||||
base: "hv-color-swatch-picker--lg",
|
||||
},
|
||||
md: {
|
||||
base: "hv-color-swatch-picker--md",
|
||||
},
|
||||
sm: {
|
||||
base: "hv-color-swatch-picker--sm",
|
||||
},
|
||||
xl: {
|
||||
base: "hv-color-swatch-picker--xl",
|
||||
},
|
||||
xs: {
|
||||
base: "hv-color-swatch-picker--xs",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
circle: {
|
||||
base: "hv-color-swatch-picker--circle",
|
||||
},
|
||||
square: {
|
||||
base: "hv-color-swatch-picker--square",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type ColorSwatchPickerVariants = VariantProps<
|
||||
typeof colorSwatchPickerVariants
|
||||
>;
|
||||
|
||||
/** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */
|
||||
export const colorAreaVariants = tv({
|
||||
defaultVariants: {
|
||||
|
||||
@@ -0,0 +1,416 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
computed,
|
||||
mergeProps,
|
||||
provide,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
watch,
|
||||
} from "vue";
|
||||
import { useEventListener } from "@vueuse/core";
|
||||
import { colorSwatchPickerVariants } from "@heroui-vue/styles";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { useColorState } from "../color/model";
|
||||
import { parseColor, type Color, type ColorValue } from "../color/value";
|
||||
import { useCollectionRegistry } from "../collection/registry";
|
||||
import {
|
||||
colorSwatchPickerKey,
|
||||
type ColorSwatchPickerKey,
|
||||
type ColorSwatchPickerMember,
|
||||
} from "./context";
|
||||
import { createColorSwatchPickerDelegate } from "./navigation";
|
||||
import type {
|
||||
ColorSwatchPickerLayout,
|
||||
ColorSwatchPickerRenderProps,
|
||||
ColorSwatchPickerShape,
|
||||
ColorSwatchPickerSize,
|
||||
ColorSwatchPickerSlots,
|
||||
} from "./types";
|
||||
|
||||
defineOptions({ inheritAttrs: false, name: "ColorSwatchPicker" });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 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; defaults to `#000000` like the fixed source. */
|
||||
defaultValue?: ColorValue | null;
|
||||
layout?: ColorSwatchPickerLayout;
|
||||
size?: ColorSwatchPickerSize;
|
||||
variant?: ColorSwatchPickerShape;
|
||||
isDisabled?: boolean;
|
||||
/** Alias for `isDisabled`. */
|
||||
disabled?: boolean;
|
||||
/** Library extension: blocks selection without leaving the tab order. */
|
||||
isReadOnly?: boolean;
|
||||
dir?: "ltr" | "rtl";
|
||||
/** Render a different root element; corresponds to the upstream render prop. */
|
||||
as?: string;
|
||||
}>(),
|
||||
{
|
||||
modelValue: undefined,
|
||||
value: undefined,
|
||||
defaultValue: undefined,
|
||||
layout: "grid",
|
||||
size: "md",
|
||||
variant: "circle",
|
||||
isDisabled: false,
|
||||
disabled: false,
|
||||
isReadOnly: false,
|
||||
dir: undefined,
|
||||
as: "div",
|
||||
},
|
||||
);
|
||||
|
||||
defineSlots<ColorSwatchPickerSlots>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: Color];
|
||||
change: [value: Color];
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const config = useConfig();
|
||||
const locale = computed(() => config?.locale.value ?? "en-US");
|
||||
const dir = computed<"ltr" | "rtl">(
|
||||
() => props.dir ?? config?.dir.value ?? "ltr",
|
||||
);
|
||||
|
||||
const state = useColorState(props, {
|
||||
fallback: () => parseColor("#000000"),
|
||||
inherit: true,
|
||||
provide: true,
|
||||
change: (value) => {
|
||||
if (!value) return;
|
||||
emit("update:modelValue", value);
|
||||
emit("change", value);
|
||||
},
|
||||
});
|
||||
|
||||
const registry = useCollectionRegistry<ColorSwatchPickerMember>();
|
||||
let sequence = 0;
|
||||
const nextKey = () => ++sequence;
|
||||
const ordered = () => registry.ordered();
|
||||
const enabled = () => (state.disabled.value ? [] : registry.available());
|
||||
|
||||
const rootElement = shallowRef<HTMLElement>();
|
||||
const focused = shallowRef<ColorSwatchPickerKey>();
|
||||
const within = shallowRef(false);
|
||||
const focusVisible = shallowRef(false);
|
||||
const pressed = shallowRef<ColorSwatchPickerKey>();
|
||||
|
||||
function cancelPress() {
|
||||
pressed.value = undefined;
|
||||
for (const member of ordered()) member.cancelPress();
|
||||
}
|
||||
|
||||
// Window blur need not blur the active element. Cancel both visual press state
|
||||
// and click suppression at the owner; VueUse removes the listener on unmount.
|
||||
useEventListener(
|
||||
() => rootElement.value?.ownerDocument.defaultView,
|
||||
"blur",
|
||||
cancelPress,
|
||||
);
|
||||
|
||||
/**
|
||||
* Selection compares derived hexa keys like the fixed source. The accepted
|
||||
* value keeps its own space and precision and is never rewritten to match.
|
||||
*/
|
||||
const acceptedKey = computed(() =>
|
||||
state.value.value ? state.value.value.toString("hexa") : undefined,
|
||||
);
|
||||
const selected = (color: Color) =>
|
||||
acceptedKey.value !== undefined &&
|
||||
color.toString("hexa") === acceptedKey.value;
|
||||
|
||||
const itemDisabled = (key: ColorSwatchPickerKey) =>
|
||||
state.disabled.value ||
|
||||
!!ordered().find((member) => member.key() === key)?.disabled();
|
||||
|
||||
const delegate = createColorSwatchPickerDelegate({
|
||||
container: () => rootElement.value,
|
||||
members: () => enabled(),
|
||||
layout: () => props.layout,
|
||||
dir: () => dir.value,
|
||||
locale: () => locale.value,
|
||||
});
|
||||
|
||||
function focusItem(key: ColorSwatchPickerKey) {
|
||||
const member = enabled().find((item) => item.key() === key);
|
||||
if (!member) return;
|
||||
focused.value = key;
|
||||
const element = member.element();
|
||||
element?.focus({ preventScroll: true });
|
||||
element?.scrollIntoView?.({ block: "nearest" });
|
||||
}
|
||||
|
||||
function activate(key: ColorSwatchPickerKey, event: Event) {
|
||||
if (event.defaultPrevented) return;
|
||||
if (state.disabled.value || state.readOnly.value) return;
|
||||
const member = ordered().find((item) => item.key() === key);
|
||||
if (!member || member.disabled()) return;
|
||||
const color = member.color();
|
||||
// The fixed source emits nothing when the selection key does not change.
|
||||
if (selected(color)) return;
|
||||
state.request(color);
|
||||
}
|
||||
|
||||
function entryKey(from: Element | null | undefined) {
|
||||
const items = enabled();
|
||||
if (!items.length) return undefined;
|
||||
const backward = !!(
|
||||
from &&
|
||||
rootElement.value &&
|
||||
rootElement.value.compareDocumentPosition(from) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING
|
||||
);
|
||||
const selectedKeys = items
|
||||
.filter((item) => selected(item.color()))
|
||||
.map((item) => item.key());
|
||||
return (
|
||||
(backward ? selectedKeys.at(-1) : selectedKeys[0]) ??
|
||||
(backward ? items.at(-1)?.key() : items[0]?.key())
|
||||
);
|
||||
}
|
||||
|
||||
function matchesFocusVisible(target: EventTarget | null) {
|
||||
try {
|
||||
return (
|
||||
target instanceof Element && target.matches(":focus-visible")
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function onRootFocus(event: FocusEvent) {
|
||||
within.value = true;
|
||||
focusVisible.value = matchesFocusVisible(event.target);
|
||||
if (event.target !== rootElement.value) return;
|
||||
const key =
|
||||
focused.value ?? entryKey(event.relatedTarget as Element | null);
|
||||
if (key !== undefined) focusItem(key);
|
||||
}
|
||||
|
||||
function onRootFocusout(event: FocusEvent) {
|
||||
if (rootElement.value?.contains(event.relatedTarget as Node | null)) return;
|
||||
within.value = false;
|
||||
focusVisible.value = false;
|
||||
pressed.value = undefined;
|
||||
}
|
||||
|
||||
let search = "";
|
||||
let lastSearch = 0;
|
||||
|
||||
function onRootKeydown(event: KeyboardEvent) {
|
||||
if (event.defaultPrevented || event.isComposing || event.keyCode === 229)
|
||||
return;
|
||||
if (state.disabled.value) return;
|
||||
if (!enabled().length) return;
|
||||
const current = focused.value;
|
||||
const step = (forward: boolean) => {
|
||||
if (current === undefined)
|
||||
return forward ? delegate.firstKey() : delegate.lastKey();
|
||||
return forward ? delegate.keyBelow(current) : delegate.keyAbove(current);
|
||||
};
|
||||
let target: ColorSwatchPickerKey | undefined;
|
||||
switch (event.key) {
|
||||
case "Home":
|
||||
case "End":
|
||||
target = event.key === "Home" ? delegate.firstKey() : delegate.lastKey();
|
||||
if (target !== undefined) {
|
||||
event.preventDefault();
|
||||
focusItem(target);
|
||||
}
|
||||
return;
|
||||
case "ArrowDown":
|
||||
case "ArrowUp":
|
||||
target = step(event.key === "ArrowDown");
|
||||
break;
|
||||
case "ArrowRight":
|
||||
case "ArrowLeft": {
|
||||
if (current === undefined) {
|
||||
const first = delegate.firstKey();
|
||||
if (first !== undefined) {
|
||||
event.preventDefault();
|
||||
focusItem(first);
|
||||
}
|
||||
return;
|
||||
}
|
||||
target =
|
||||
event.key === "ArrowRight"
|
||||
? delegate.keyRightOf(current)
|
||||
: delegate.keyLeftOf(current);
|
||||
break;
|
||||
}
|
||||
case "PageDown":
|
||||
case "PageUp":
|
||||
target =
|
||||
current === undefined
|
||||
? undefined
|
||||
: delegate.pageKey(current, event.key === "PageDown");
|
||||
break;
|
||||
case "Enter":
|
||||
case " ":
|
||||
if (event.repeat) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (current !== undefined) activate(current, event);
|
||||
event.preventDefault();
|
||||
return;
|
||||
default:
|
||||
target = undefined;
|
||||
}
|
||||
if (target !== undefined) {
|
||||
event.preventDefault();
|
||||
focusItem(target);
|
||||
return;
|
||||
}
|
||||
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
||||
if (event.key.length !== 1 || event.key === " ") return;
|
||||
const now = Date.now();
|
||||
search = now - lastSearch > 1000 ? event.key : search + event.key;
|
||||
lastSearch = now;
|
||||
const query = [...search].every((character) => character === search[0])
|
||||
? search[0]!
|
||||
: search;
|
||||
const match = delegate.keyForSearch(query, current);
|
||||
if (match !== undefined) {
|
||||
event.preventDefault();
|
||||
focusItem(match);
|
||||
}
|
||||
}
|
||||
|
||||
// A removed or disabled item cannot stay focused; the listbox keeps one legal
|
||||
// tab entry (the root or a usable item) and never drops focus to the document.
|
||||
watch(
|
||||
() =>
|
||||
[
|
||||
state.disabled.value,
|
||||
registry
|
||||
.ordered()
|
||||
.map((member) => `${String(member.key())}:${member.disabled()}`)
|
||||
.join(","),
|
||||
].join("|"),
|
||||
() => {
|
||||
for (const member of ordered()) {
|
||||
if (state.disabled.value || member.disabled()) member.cancelPress();
|
||||
}
|
||||
const usable = (key: ColorSwatchPickerKey | undefined) =>
|
||||
key !== undefined &&
|
||||
enabled().some((item) => item.key() === key && !itemDisabled(key));
|
||||
if (pressed.value !== undefined && !usable(pressed.value))
|
||||
pressed.value = undefined;
|
||||
if (focused.value === undefined || usable(focused.value)) return;
|
||||
focused.value = undefined;
|
||||
focusVisible.value = false;
|
||||
const root = rootElement.value;
|
||||
if (root?.contains(document.activeElement)) root.focus();
|
||||
},
|
||||
);
|
||||
|
||||
const classes = computed(() =>
|
||||
colorSwatchPickerVariants({
|
||||
layout: props.layout,
|
||||
size: props.size,
|
||||
variant: props.variant,
|
||||
}),
|
||||
);
|
||||
|
||||
const slotState = computed<ColorSwatchPickerRenderProps>(() => ({
|
||||
color: state.value.value,
|
||||
isEmpty: ordered().length === 0,
|
||||
isDisabled: state.disabled.value,
|
||||
isReadOnly: state.readOnly.value,
|
||||
isFocused: within.value,
|
||||
layout: props.layout,
|
||||
}));
|
||||
|
||||
function defaultLabel() {
|
||||
return locale.value.toLowerCase().startsWith("zh")
|
||||
? "颜色色块选择器"
|
||||
: "Color swatch picker";
|
||||
}
|
||||
|
||||
function rootAttrs() {
|
||||
return mergeProps(attrs, {
|
||||
role: "listbox",
|
||||
"data-slot": "color-swatch-picker",
|
||||
class: [classes.value.base(), attrs.class],
|
||||
dir: dir.value,
|
||||
tabindex: state.disabled.value || focused.value !== undefined ? -1 : 0,
|
||||
"aria-label": attrs["aria-label"] ?? defaultLabel(),
|
||||
"aria-orientation": "vertical",
|
||||
"aria-disabled": state.disabled.value || undefined,
|
||||
"aria-readonly": state.readOnly.value || undefined,
|
||||
"data-disabled": state.disabled.value || undefined,
|
||||
"data-readonly": state.readOnly.value || undefined,
|
||||
"data-focused": within.value || undefined,
|
||||
"data-focus-visible": (within.value && focusVisible.value) || undefined,
|
||||
onFocusin: onRootFocus,
|
||||
onFocusout: onRootFocusout,
|
||||
onPointercancel: cancelPress,
|
||||
onKeydown: onRootKeydown,
|
||||
onMousedown: () => {
|
||||
focusVisible.value = false;
|
||||
},
|
||||
onMouseup: (event: MouseEvent) => {
|
||||
if (event.button === 0) pressed.value = undefined;
|
||||
},
|
||||
onKeyupCapture: () => {
|
||||
pressed.value = undefined;
|
||||
},
|
||||
ref: (node: unknown) => {
|
||||
rootElement.value =
|
||||
node instanceof HTMLElement
|
||||
? node
|
||||
: ((node as { $el?: HTMLElement } | null)?.$el ?? undefined);
|
||||
},
|
||||
} as Record<string, unknown>);
|
||||
}
|
||||
|
||||
provide(colorSwatchPickerKey, {
|
||||
state,
|
||||
classes,
|
||||
layout: computed(() => props.layout),
|
||||
dir,
|
||||
disabled: computed(() => state.disabled.value),
|
||||
nextKey,
|
||||
register: registry.register,
|
||||
selected,
|
||||
itemDisabled,
|
||||
focused,
|
||||
focusWithin: within,
|
||||
focusVisible,
|
||||
pressed,
|
||||
noteFocus: (key) => {
|
||||
focused.value = key;
|
||||
},
|
||||
noteBlur: (key) => {
|
||||
// Press release is owned by the item's mouse/leave handlers: a blur caused
|
||||
// by a new press must not clear the new press state.
|
||||
if (focused.value !== key) return;
|
||||
focusVisible.value = false;
|
||||
},
|
||||
focusItem,
|
||||
activate,
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
element: rootElement,
|
||||
focus: () => {
|
||||
const key = focused.value ?? entryKey(undefined);
|
||||
if (key !== undefined) focusItem(key);
|
||||
else rootElement.value?.focus();
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" v-bind="rootAttrs()">
|
||||
<slot v-bind="slotState" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, mergeProps, useAttrs } from "vue";
|
||||
import {
|
||||
colorSwatchPickerKey,
|
||||
useColorSwatchPickerItem,
|
||||
} from "./context";
|
||||
import type { ColorSwatchPickerIndicatorSlots } from "./types";
|
||||
|
||||
defineOptions({ inheritAttrs: false, name: "ColorSwatchPickerIndicator" });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** Render a different root element; corresponds to the upstream render prop. */
|
||||
as?: string;
|
||||
}>(),
|
||||
{ as: "span" },
|
||||
);
|
||||
|
||||
defineSlots<ColorSwatchPickerIndicatorSlots>();
|
||||
|
||||
const item = useColorSwatchPickerItem();
|
||||
const picker = inject(colorSwatchPickerKey, undefined);
|
||||
const attrs = useAttrs();
|
||||
const state = item.state;
|
||||
|
||||
/** Relative luminance over 0.5 means a light swatch needs the dark checkmark. */
|
||||
const isLightColor = computed(() => {
|
||||
const rgb = item.state.value.color.toFormat("rgb");
|
||||
return (
|
||||
(0.2126 * rgb.getChannelValue("red") +
|
||||
0.7152 * rgb.getChannelValue("green") +
|
||||
0.0722 * rgb.getChannelValue("blue")) /
|
||||
255 >
|
||||
0.5
|
||||
);
|
||||
});
|
||||
|
||||
function indicatorAttrs() {
|
||||
return mergeProps(attrs, {
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "color-swatch-picker-indicator",
|
||||
"data-light-color": isLightColor.value ? "true" : undefined,
|
||||
class: [picker?.classes.value.indicator(), attrs.class],
|
||||
} as Record<string, unknown>);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" v-bind="indicatorAttrs()">
|
||||
<slot v-bind="state">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
data-slot="color-swatch-picker-checkmark"
|
||||
fill="none"
|
||||
role="presentation"
|
||||
stroke="currentColor"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="1.5"
|
||||
viewBox="0 0 12 12"
|
||||
>
|
||||
<polyline points="2.5 6 5 8.5 9.5 3" />
|
||||
</svg>
|
||||
</slot>
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,201 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
computed,
|
||||
mergeProps,
|
||||
provide,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
useId,
|
||||
} from "vue";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import {
|
||||
colorSwatchPickerItemKey,
|
||||
useColorSwatchPicker,
|
||||
} from "./context";
|
||||
import { copyColor, parseColor, type Color, type ColorValue } from "../color/value";
|
||||
import type {
|
||||
ColorSwatchPickerItemRenderProps,
|
||||
ColorSwatchPickerItemSlots,
|
||||
} from "./types";
|
||||
|
||||
defineOptions({ inheritAttrs: false, name: "ColorSwatchPickerItem" });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** Candidate color; omitted or empty renders the transparent swatch. */
|
||||
color?: ColorValue | null;
|
||||
isDisabled?: boolean;
|
||||
/** Render a different root element; corresponds to the upstream render prop. */
|
||||
as?: string;
|
||||
}>(),
|
||||
{
|
||||
color: undefined,
|
||||
isDisabled: false,
|
||||
as: "div",
|
||||
},
|
||||
);
|
||||
|
||||
defineSlots<ColorSwatchPickerItemSlots>();
|
||||
|
||||
const picker = useColorSwatchPicker();
|
||||
const attrs = useAttrs();
|
||||
const config = useConfig();
|
||||
const generatedId = useId();
|
||||
const element = shallowRef<HTMLElement>();
|
||||
const hovered = shallowRef(false);
|
||||
const key = picker.nextKey();
|
||||
const TRANSPARENT = parseColor("#0000");
|
||||
|
||||
const itemColor = computed<Color>(
|
||||
() =>
|
||||
(props.color == null || props.color === ""
|
||||
? null
|
||||
: copyColor(props.color)) ?? TRANSPARENT,
|
||||
);
|
||||
|
||||
function isZh() {
|
||||
return (config?.locale.value ?? "en-US").toLowerCase().startsWith("zh");
|
||||
}
|
||||
|
||||
function accessibleName() {
|
||||
const explicit = attrs["aria-label"];
|
||||
if (explicit != null) return String(explicit);
|
||||
const color = itemColor.value;
|
||||
if (color.getChannelValue("alpha") === 0) return isZh() ? "透明" : "transparent";
|
||||
return color.toString(
|
||||
color.getChannelValue("alpha") === 1 ? "hex" : "hexa",
|
||||
);
|
||||
}
|
||||
|
||||
/** The compatibility click of an already activated press must not re-propose. */
|
||||
const pressActivated = shallowRef(false);
|
||||
|
||||
picker.register({
|
||||
key: () => key,
|
||||
element: () => element.value,
|
||||
color: () => itemColor.value,
|
||||
cancelPress,
|
||||
textValue: () => accessibleName(),
|
||||
disabled: () => !!props.isDisabled,
|
||||
});
|
||||
|
||||
const state = computed<ColorSwatchPickerItemRenderProps>(() => {
|
||||
const isDisabled = picker.itemDisabled(key);
|
||||
const isFocused = picker.focusWithin.value && picker.focused.value === key;
|
||||
return {
|
||||
color: itemColor.value,
|
||||
isSelected: picker.selected(itemColor.value),
|
||||
isDisabled,
|
||||
isFocused,
|
||||
isFocusVisible: isFocused && picker.focusVisible.value,
|
||||
isPressed: picker.pressed.value === key,
|
||||
isHovered: hovered.value,
|
||||
};
|
||||
});
|
||||
|
||||
provide(colorSwatchPickerItemKey, { key, state });
|
||||
|
||||
function activateFrom(event: Event) {
|
||||
picker.activate(key, event);
|
||||
element.value?.focus({ preventScroll: true });
|
||||
picker.noteFocus(key);
|
||||
}
|
||||
|
||||
function onMousedown(event: MouseEvent) {
|
||||
// Only the primary button activates; secondary buttons keep their native
|
||||
// behaviour (context menu, autoscroll).
|
||||
if (event.button !== 0) return;
|
||||
pressActivated.value = true;
|
||||
if (state.value.isDisabled) {
|
||||
// Keep focus from moving onto a disabled option.
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
picker.pressed.value = key;
|
||||
activateFrom(event);
|
||||
}
|
||||
|
||||
function onClick(event: MouseEvent) {
|
||||
// Real pointer clicks already activated on press (detail > 0). Click-only
|
||||
// activations from assistive technology arrive without a press and with
|
||||
// detail 0, and still honour cancelable clicks and rejection retries.
|
||||
if (pressActivated.value) {
|
||||
pressActivated.value = false;
|
||||
return;
|
||||
}
|
||||
if (event.detail > 0) return;
|
||||
if (state.value.isDisabled) return;
|
||||
picker.pressed.value = undefined;
|
||||
activateFrom(event);
|
||||
}
|
||||
|
||||
function releasePress() {
|
||||
if (picker.pressed.value === key) picker.pressed.value = undefined;
|
||||
}
|
||||
|
||||
function cancelPress() {
|
||||
pressActivated.value = false;
|
||||
releasePress();
|
||||
}
|
||||
|
||||
function itemAttrs() {
|
||||
return mergeProps(attrs, {
|
||||
role: "option",
|
||||
id: attrs.id == null ? generatedId : String(attrs.id),
|
||||
tabindex: state.value.isDisabled
|
||||
? undefined
|
||||
: picker.focused.value === key
|
||||
? 0
|
||||
: -1,
|
||||
"aria-selected": state.value.isSelected,
|
||||
"aria-disabled": state.value.isDisabled || undefined,
|
||||
"aria-label": accessibleName(),
|
||||
"data-slot": "color-swatch-picker-item",
|
||||
"data-selected": state.value.isSelected || undefined,
|
||||
"data-disabled": state.value.isDisabled || undefined,
|
||||
"data-hovered": state.value.isHovered || undefined,
|
||||
"data-focused": state.value.isFocused || undefined,
|
||||
"data-focus-visible": state.value.isFocusVisible || undefined,
|
||||
"data-pressed": state.value.isPressed || undefined,
|
||||
class: [picker.classes.value.item(), attrs.class],
|
||||
style: [
|
||||
{
|
||||
"--color-swatch-current": itemColor.value.toString("css"),
|
||||
},
|
||||
attrs.style,
|
||||
],
|
||||
ref: (node: unknown) => {
|
||||
element.value =
|
||||
node instanceof HTMLElement
|
||||
? node
|
||||
: ((node as { $el?: HTMLElement } | null)?.$el ?? undefined);
|
||||
},
|
||||
onFocus: () => picker.noteFocus(key),
|
||||
onBlur: () => {
|
||||
cancelPress();
|
||||
picker.noteBlur(key);
|
||||
},
|
||||
onMousedown,
|
||||
onClick,
|
||||
onMouseup: (event: MouseEvent) => {
|
||||
if (event.button !== 0) return;
|
||||
releasePress();
|
||||
},
|
||||
onMouseenter: () => {
|
||||
hovered.value = true;
|
||||
},
|
||||
onMouseleave: () => {
|
||||
hovered.value = false;
|
||||
cancelPress();
|
||||
},
|
||||
} as Record<string, unknown>);
|
||||
}
|
||||
|
||||
defineExpose({ element });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" v-bind="itemAttrs()">
|
||||
<slot v-bind="state" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, mergeProps, useAttrs } from "vue";
|
||||
import {
|
||||
colorSwatchPickerKey,
|
||||
useColorSwatchPickerItem,
|
||||
} from "./context";
|
||||
import { copyColor, type Color, type ColorValue } from "../color/value";
|
||||
|
||||
defineOptions({ inheritAttrs: false, name: "ColorSwatchPickerSwatch" });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** Defaults to the enclosing item's color. */
|
||||
color?: ColorValue | null;
|
||||
/** Localized accessible color name; overrides the generated description. */
|
||||
colorName?: string;
|
||||
as?: string;
|
||||
}>(),
|
||||
{
|
||||
color: undefined,
|
||||
colorName: undefined,
|
||||
as: "div",
|
||||
},
|
||||
);
|
||||
|
||||
const item = useColorSwatchPickerItem();
|
||||
const picker = inject(colorSwatchPickerKey, undefined);
|
||||
const attrs = useAttrs();
|
||||
|
||||
const resolved = computed<Color>(() => {
|
||||
const raw = props.color;
|
||||
if (raw != null && raw !== "") return copyColor(raw)!;
|
||||
return item.state.value.color;
|
||||
});
|
||||
|
||||
function autoName() {
|
||||
const color = resolved.value;
|
||||
if (color.getChannelValue("alpha") === 0) return "transparent";
|
||||
return color.toString(
|
||||
color.getChannelValue("alpha") === 1 ? "hex" : "hexa",
|
||||
);
|
||||
}
|
||||
|
||||
function swatchAttrs() {
|
||||
const css = resolved.value.toString("css");
|
||||
return mergeProps(attrs, {
|
||||
role: "img",
|
||||
"data-slot": "color-swatch-picker-swatch",
|
||||
"aria-label": [props.colorName ?? autoName(), attrs["aria-label"] ?? ""]
|
||||
.filter(Boolean)
|
||||
.join(", "),
|
||||
class: [picker?.classes.value.swatch(), attrs.class],
|
||||
style: [
|
||||
{
|
||||
backgroundColor: css,
|
||||
forcedColorAdjust: "none",
|
||||
"--color-swatch-current": css,
|
||||
} as Record<string, string>,
|
||||
attrs.style,
|
||||
],
|
||||
} as Record<string, unknown>);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" v-bind="swatchAttrs()" />
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
inject,
|
||||
type ComputedRef,
|
||||
type InjectionKey,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import type { ColorState } from "../color/model";
|
||||
import type { Color } from "../color/value";
|
||||
import type { ColorSwatchPickerLayout } from "./types";
|
||||
|
||||
/**
|
||||
* Structural item identity. Candidate colors may repeat or be equivalent, so a
|
||||
* color string is never the key and items are never merged.
|
||||
*/
|
||||
export type ColorSwatchPickerKey = number;
|
||||
|
||||
export interface ColorSwatchPickerMember {
|
||||
key: () => ColorSwatchPickerKey;
|
||||
element: () => HTMLElement | undefined;
|
||||
color: () => Color;
|
||||
/** Cancel this item's press and compatibility-click ownership. */
|
||||
cancelPress: () => void;
|
||||
/** Accessible name used for type-to-select matching. */
|
||||
textValue: () => string;
|
||||
disabled: () => boolean;
|
||||
}
|
||||
|
||||
/** Slot class names resolved once on the root. */
|
||||
export interface ColorSwatchPickerClasses {
|
||||
base: () => string;
|
||||
item: () => string;
|
||||
swatch: () => string;
|
||||
indicator: () => string;
|
||||
}
|
||||
|
||||
export interface ColorSwatchPickerContext {
|
||||
/** The single accepted color source; items never own one. */
|
||||
state: ColorState;
|
||||
classes: ComputedRef<ColorSwatchPickerClasses>;
|
||||
layout: ComputedRef<ColorSwatchPickerLayout>;
|
||||
dir: ComputedRef<"ltr" | "rtl">;
|
||||
disabled: ComputedRef<boolean>;
|
||||
nextKey: () => ColorSwatchPickerKey;
|
||||
register: (member: ColorSwatchPickerMember) => () => void;
|
||||
/** Selection compares derived hexa keys; the accepted value is never rewritten. */
|
||||
selected: (color: Color) => boolean;
|
||||
itemDisabled: (key: ColorSwatchPickerKey) => boolean;
|
||||
focused: Ref<ColorSwatchPickerKey | undefined>;
|
||||
focusWithin: Ref<boolean>;
|
||||
focusVisible: Ref<boolean>;
|
||||
pressed: Ref<ColorSwatchPickerKey | undefined>;
|
||||
noteFocus: (key: ColorSwatchPickerKey) => void;
|
||||
noteBlur: (key: ColorSwatchPickerKey) => void;
|
||||
focusItem: (key: ColorSwatchPickerKey) => void;
|
||||
/** Pointer press selection; cancelable native events are honoured. */
|
||||
activate: (key: ColorSwatchPickerKey, event: Event) => void;
|
||||
}
|
||||
|
||||
export const colorSwatchPickerKey: InjectionKey<ColorSwatchPickerContext> =
|
||||
Symbol("hv-color-swatch-picker");
|
||||
|
||||
export interface ColorSwatchPickerItemContext {
|
||||
key: ColorSwatchPickerKey;
|
||||
state: ComputedRef<import("./types").ColorSwatchPickerItemRenderProps>;
|
||||
}
|
||||
|
||||
export const colorSwatchPickerItemKey: InjectionKey<ColorSwatchPickerItemContext> =
|
||||
Symbol("hv-color-swatch-picker-item");
|
||||
|
||||
export function useColorSwatchPicker() {
|
||||
const context = inject(colorSwatchPickerKey, undefined);
|
||||
if (!context)
|
||||
throw new Error("ColorSwatchPickerItem requires ColorSwatchPicker.");
|
||||
return context;
|
||||
}
|
||||
|
||||
/** Item parts read the nearest item; no metadata is probed from wrappers. */
|
||||
export function useColorSwatchPickerItem() {
|
||||
const context = inject(colorSwatchPickerItemKey, undefined);
|
||||
if (!context)
|
||||
throw new Error(
|
||||
"ColorSwatchPickerSwatch and ColorSwatchPickerIndicator require ColorSwatchPickerItem.",
|
||||
);
|
||||
return context;
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import type {
|
||||
ColorSwatchPickerKey,
|
||||
ColorSwatchPickerMember,
|
||||
} from "./context";
|
||||
|
||||
interface Rect {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
/** Container-relative item geometry, matching the fixed source delegate. */
|
||||
export function relativeRect(
|
||||
container: HTMLElement,
|
||||
item: HTMLElement,
|
||||
): Rect {
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
const rect = item.getBoundingClientRect();
|
||||
return {
|
||||
x: rect.left - containerRect.left - container.clientLeft + container.scrollLeft,
|
||||
y: rect.top - containerRect.top - container.clientTop + container.scrollTop,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
};
|
||||
}
|
||||
|
||||
function isScrollable(element: HTMLElement) {
|
||||
return (
|
||||
element.scrollHeight > element.clientHeight + 1 ||
|
||||
element.scrollWidth > element.clientWidth + 1
|
||||
);
|
||||
}
|
||||
|
||||
export interface ColorSwatchPickerDelegateOptions {
|
||||
container: () => HTMLElement | undefined;
|
||||
/** Enabled members in DOM order. */
|
||||
members: () => readonly ColorSwatchPickerMember[];
|
||||
layout: () => "grid" | "stack";
|
||||
dir: () => "ltr" | "rtl";
|
||||
locale: () => string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed-source keyboard delegate: order movement along the row, geometry
|
||||
* movement across wrapped grid rows, no focus wrapping at the boundaries.
|
||||
*/
|
||||
export function createColorSwatchPickerDelegate(
|
||||
options: ColorSwatchPickerDelegateOptions,
|
||||
) {
|
||||
const rectOf = (key: ColorSwatchPickerKey) => {
|
||||
const container = options.container();
|
||||
const member = options.members().find((item) => item.key() === key);
|
||||
const element = member?.element();
|
||||
if (!container || !container.isConnected || !element) return undefined;
|
||||
return relativeRect(container, element);
|
||||
};
|
||||
const order = () => options.members().map((item) => item.key());
|
||||
const indexOf = (key: ColorSwatchPickerKey) => order().indexOf(key);
|
||||
const nextKey = (key: ColorSwatchPickerKey) => {
|
||||
const keys = order();
|
||||
return keys[indexOf(key) + 1];
|
||||
};
|
||||
const previousKey = (key: ColorSwatchPickerKey) => {
|
||||
const keys = order();
|
||||
return keys[indexOf(key) - 1];
|
||||
};
|
||||
/** Skip while the candidate shares the row or misses the column. */
|
||||
const isSameRow = (start: Rect, candidate: Rect) =>
|
||||
start.y === candidate.y || start.x !== candidate.x;
|
||||
const isSameColumn = (start: Rect, candidate: Rect) =>
|
||||
start.x === candidate.x || start.y !== candidate.y;
|
||||
|
||||
function findKey(
|
||||
key: ColorSwatchPickerKey,
|
||||
next: (key: ColorSwatchPickerKey) => ColorSwatchPickerKey | undefined,
|
||||
shouldSkip: (start: Rect, candidate: Rect) => boolean,
|
||||
) {
|
||||
const start = rectOf(key);
|
||||
if (!start) return undefined;
|
||||
let current = next(key);
|
||||
while (current !== undefined) {
|
||||
const candidate = rectOf(current);
|
||||
if (!candidate) return undefined;
|
||||
if (!shouldSkip(start, candidate)) return current;
|
||||
current = next(current);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Column-reverse containers move in reverse document order. */
|
||||
function isReversed(key: ColorSwatchPickerKey) {
|
||||
const current = rectOf(key);
|
||||
if (!current) return false;
|
||||
const next = nextKey(key);
|
||||
if (next !== undefined) {
|
||||
const nextRect = rectOf(next);
|
||||
return !!nextRect && current.y > nextRect.y;
|
||||
}
|
||||
const previous = previousKey(key);
|
||||
if (previous !== undefined) {
|
||||
const previousRect = rectOf(previous);
|
||||
return !!previousRect && previousRect.y > current.y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function keyBelow(key: ColorSwatchPickerKey) {
|
||||
if (options.layout() === "grid")
|
||||
return findKey(key, nextKey, isSameRow);
|
||||
return isReversed(key) ? previousKey(key) : nextKey(key);
|
||||
}
|
||||
function keyAbove(key: ColorSwatchPickerKey) {
|
||||
if (options.layout() === "grid")
|
||||
return findKey(key, previousKey, isSameRow);
|
||||
return isReversed(key) ? nextKey(key) : previousKey(key);
|
||||
}
|
||||
function keyRightOf(key: ColorSwatchPickerKey) {
|
||||
if (options.layout() !== "grid") return undefined;
|
||||
return options.dir() === "rtl" ? previousKey(key) : nextKey(key);
|
||||
}
|
||||
function keyLeftOf(key: ColorSwatchPickerKey) {
|
||||
if (options.layout() !== "grid") return undefined;
|
||||
return options.dir() === "ltr" ? previousKey(key) : nextKey(key);
|
||||
}
|
||||
function firstKey() {
|
||||
return order()[0];
|
||||
}
|
||||
function lastKey() {
|
||||
return order().at(-1);
|
||||
}
|
||||
|
||||
function pageKey(key: ColorSwatchPickerKey, forward: boolean) {
|
||||
const container = options.container();
|
||||
const start = rectOf(key);
|
||||
if (!container || !start) return undefined;
|
||||
if (!isScrollable(container)) return forward ? lastKey() : firstKey();
|
||||
const visible = {
|
||||
height: container.clientHeight,
|
||||
};
|
||||
const contentHeight = container.scrollHeight;
|
||||
const pageY = forward
|
||||
? Math.min(contentHeight, start.y - start.height + visible.height)
|
||||
: Math.max(0, start.y + start.height - visible.height);
|
||||
let current: ColorSwatchPickerKey | undefined = key;
|
||||
let currentRect: Rect | undefined = start;
|
||||
while (
|
||||
current !== undefined &&
|
||||
currentRect &&
|
||||
(forward ? currentRect.y < pageY : currentRect.y > pageY)
|
||||
) {
|
||||
current = forward ? keyBelow(current) : keyAbove(current);
|
||||
currentRect = current === undefined ? undefined : rectOf(current);
|
||||
}
|
||||
return current ?? (forward ? lastKey() : firstKey());
|
||||
}
|
||||
|
||||
function keyForSearch(search: string, fromKey?: ColorSwatchPickerKey) {
|
||||
const keys = order();
|
||||
const collator = new Intl.Collator(options.locale(), {
|
||||
usage: "search",
|
||||
sensitivity: "base",
|
||||
});
|
||||
let index =
|
||||
fromKey === undefined ? 0 : Math.max(0, keys.indexOf(fromKey));
|
||||
while (index < keys.length) {
|
||||
const member = options.members().find((item) => item.key() === keys[index]);
|
||||
const text = member?.textValue() ?? "";
|
||||
if (
|
||||
text &&
|
||||
collator.compare(text.slice(0, search.length), search) === 0
|
||||
)
|
||||
return keys[index];
|
||||
index++;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
keyBelow,
|
||||
keyAbove,
|
||||
keyLeftOf,
|
||||
keyRightOf,
|
||||
firstKey,
|
||||
lastKey,
|
||||
pageKey,
|
||||
keyForSearch,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import type { VNodeChild } from "vue";
|
||||
import type { Color } from "../color/value";
|
||||
import type ColorSwatchPicker from "./ColorSwatchPicker.vue";
|
||||
import type ColorSwatchPickerItem from "./ColorSwatchPickerItem.vue";
|
||||
|
||||
/** Visual arrangement only; the listbox orientation stays vertical. */
|
||||
export type ColorSwatchPickerLayout = "grid" | "stack";
|
||||
export type ColorSwatchPickerSize = "xs" | "sm" | "md" | "lg" | "xl";
|
||||
export type ColorSwatchPickerShape = "circle" | "square";
|
||||
|
||||
/**
|
||||
* Scoped slot state of ColorSwatchPickerItem and ColorSwatchPickerIndicator.
|
||||
* Selection is the accepted color state; focus is separate item state.
|
||||
*/
|
||||
export interface ColorSwatchPickerItemRenderProps {
|
||||
/** The candidate color of this item. */
|
||||
color: Color;
|
||||
/** Whether this item's color matches the accepted color. */
|
||||
isSelected: boolean;
|
||||
isDisabled: boolean;
|
||||
isFocused: boolean;
|
||||
isFocusVisible: boolean;
|
||||
isPressed: boolean;
|
||||
isHovered: boolean;
|
||||
}
|
||||
|
||||
/** Scoped slot state of the ColorSwatchPicker root. */
|
||||
export interface ColorSwatchPickerRenderProps {
|
||||
/** Accepted color; `null` only when a controlled value explicitly clears it. */
|
||||
color: Color | null;
|
||||
isEmpty: boolean;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
isFocused: boolean;
|
||||
layout: ColorSwatchPickerLayout;
|
||||
}
|
||||
|
||||
export interface ColorSwatchPickerSlots {
|
||||
default?: (state: ColorSwatchPickerRenderProps) => VNodeChild;
|
||||
}
|
||||
|
||||
export interface ColorSwatchPickerItemSlots {
|
||||
default?: (state: ColorSwatchPickerItemRenderProps) => VNodeChild;
|
||||
}
|
||||
|
||||
export interface ColorSwatchPickerIndicatorSlots {
|
||||
default?: (state: ColorSwatchPickerItemRenderProps) => VNodeChild;
|
||||
}
|
||||
|
||||
/** Root instance surface; no owner or transaction state is exposed. */
|
||||
export type ColorSwatchPickerExpose = Pick<
|
||||
InstanceType<typeof ColorSwatchPicker>,
|
||||
"element" | "focus"
|
||||
>;
|
||||
|
||||
export type ColorSwatchPickerItemExpose = Pick<
|
||||
InstanceType<typeof ColorSwatchPickerItem>,
|
||||
"element"
|
||||
>;
|
||||
@@ -1227,6 +1227,37 @@ export type {
|
||||
ColorSwatchStyleFn,
|
||||
} from "./types";
|
||||
|
||||
export {
|
||||
default as ColorSwatchPicker,
|
||||
default as ColorSwatchPickerRoot,
|
||||
} from "./components/color-swatch-picker/ColorSwatchPicker.vue";
|
||||
export { default as ColorSwatchPickerItem } from "./components/color-swatch-picker/ColorSwatchPickerItem.vue";
|
||||
export { default as ColorSwatchPickerSwatch } from "./components/color-swatch-picker/ColorSwatchPickerSwatch.vue";
|
||||
export { default as ColorSwatchPickerIndicator } from "./components/color-swatch-picker/ColorSwatchPickerIndicator.vue";
|
||||
export {
|
||||
colorSwatchPickerVariants,
|
||||
type ColorSwatchPickerVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ColorSwatchPickerIndicatorProps,
|
||||
ColorSwatchPickerItemProps,
|
||||
ColorSwatchPickerProps,
|
||||
ColorSwatchPickerRootProps,
|
||||
ColorSwatchPickerSwatchProps,
|
||||
} from "./types";
|
||||
export type {
|
||||
ColorSwatchPickerExpose,
|
||||
ColorSwatchPickerIndicatorSlots,
|
||||
ColorSwatchPickerItemExpose,
|
||||
ColorSwatchPickerItemRenderProps,
|
||||
ColorSwatchPickerItemSlots,
|
||||
ColorSwatchPickerLayout,
|
||||
ColorSwatchPickerRenderProps,
|
||||
ColorSwatchPickerShape,
|
||||
ColorSwatchPickerSize,
|
||||
ColorSwatchPickerSlots,
|
||||
} from "./components/color-swatch-picker/types";
|
||||
|
||||
export {
|
||||
default as TimeField,
|
||||
default as TimeFieldRoot,
|
||||
|
||||
@@ -923,6 +923,24 @@ export type {
|
||||
ColorSwatchStyleFn,
|
||||
} from "./components/color-swatch/types";
|
||||
|
||||
import type ColorSwatchPicker from "./components/color-swatch-picker/ColorSwatchPicker.vue";
|
||||
import type ColorSwatchPickerItem from "./components/color-swatch-picker/ColorSwatchPickerItem.vue";
|
||||
import type ColorSwatchPickerSwatch from "./components/color-swatch-picker/ColorSwatchPickerSwatch.vue";
|
||||
import type ColorSwatchPickerIndicator from "./components/color-swatch-picker/ColorSwatchPickerIndicator.vue";
|
||||
export type ColorSwatchPickerProps = InstanceType<
|
||||
typeof ColorSwatchPicker
|
||||
>["$props"];
|
||||
export type ColorSwatchPickerRootProps = ColorSwatchPickerProps;
|
||||
export type ColorSwatchPickerItemProps = InstanceType<
|
||||
typeof ColorSwatchPickerItem
|
||||
>["$props"];
|
||||
export type ColorSwatchPickerSwatchProps = InstanceType<
|
||||
typeof ColorSwatchPickerSwatch
|
||||
>["$props"];
|
||||
export type ColorSwatchPickerIndicatorProps = InstanceType<
|
||||
typeof ColorSwatchPickerIndicator
|
||||
>["$props"];
|
||||
|
||||
export type TimeFieldProps = InstanceType<
|
||||
(typeof import("./components/time-field/TimeField.vue"))["default"]
|
||||
>["$props"];
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
} from "../packages/vue/src";
|
||||
import Basic from "../apps/docs/demos/color-swatch-picker-basic.vue";
|
||||
import Variants from "../apps/docs/demos/color-swatch-picker-variants.vue";
|
||||
import Sizes from "../apps/docs/demos/color-swatch-picker-sizes.vue";
|
||||
import Disabled from "../apps/docs/demos/color-swatch-picker-disabled.vue";
|
||||
import StackLayout from "../apps/docs/demos/color-swatch-picker-stack-layout.vue";
|
||||
import DefaultValue from "../apps/docs/demos/color-swatch-picker-default-value.vue";
|
||||
import Controlled from "../apps/docs/demos/color-swatch-picker-controlled.vue";
|
||||
import CustomIndicator from "../apps/docs/demos/color-swatch-picker-custom-indicator.vue";
|
||||
import RenderFunction from "../apps/docs/demos/color-swatch-picker-render-function.vue";
|
||||
import CustomStyles from "../apps/docs/demos/color-swatch-picker-custom-styles.vue";
|
||||
|
||||
const mounted: ReturnType<typeof mount>[] = [];
|
||||
function render(component: Parameters<typeof mount>[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",
|
||||
"variants",
|
||||
"sizes",
|
||||
"disabled",
|
||||
"stack-layout",
|
||||
"default-value",
|
||||
"controlled",
|
||||
"custom-indicator",
|
||||
"render-function",
|
||||
"custom-styles",
|
||||
];
|
||||
|
||||
const BASELINE = [
|
||||
"#F43F5E",
|
||||
"#D946EF",
|
||||
"#8B5CF6",
|
||||
"#3B82F6",
|
||||
"#06B6D4",
|
||||
"#10B981",
|
||||
"#84CC16",
|
||||
];
|
||||
|
||||
const items = (w: ReturnType<typeof mount>) =>
|
||||
w.findAll<HTMLElement>("[data-slot=color-swatch-picker-item]");
|
||||
|
||||
describe("ColorSwatchPicker documentation demos", () => {
|
||||
it("keeps the ten pinned previews in the upstream order", () => {
|
||||
const document = readFileSync(
|
||||
"apps/docs/components/color-swatch-picker.md",
|
||||
"utf8",
|
||||
);
|
||||
const names = [
|
||||
...document.matchAll(
|
||||
/<ComponentPreview name="color-swatch-picker-([^"]+)"/g,
|
||||
),
|
||||
].map((match) => match[1]);
|
||||
expect(names).toEqual(previews);
|
||||
for (const name of previews) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/color-swatch-picker-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
expect(source).toContain("<template>");
|
||||
expect(source).toContain('from "@heroui-vue/components"');
|
||||
expect(source).not.toContain("className");
|
||||
}
|
||||
});
|
||||
|
||||
it("renders the basic preset palette", () => {
|
||||
const w = render(Basic);
|
||||
expect(w.findAllComponents(ColorSwatchPicker)).toHaveLength(1);
|
||||
expect(w.findAllComponents(ColorSwatchPickerItem)).toHaveLength(7);
|
||||
expect(w.findAllComponents(ColorSwatchPickerSwatch)).toHaveLength(7);
|
||||
expect(w.findAllComponents(ColorSwatchPickerIndicator)).toHaveLength(7);
|
||||
expect(
|
||||
items(w).map((item) =>
|
||||
(item.find("[data-slot=color-swatch-picker-swatch]").element as HTMLElement)
|
||||
.style.backgroundColor,
|
||||
),
|
||||
).toEqual([
|
||||
"rgb(244, 63, 94)",
|
||||
"rgb(217, 70, 239)",
|
||||
"rgb(139, 92, 246)",
|
||||
"rgb(59, 130, 246)",
|
||||
"rgb(6, 182, 212)",
|
||||
"rgb(16, 185, 129)",
|
||||
"rgb(132, 204, 22)",
|
||||
]);
|
||||
for (const color of BASELINE) {
|
||||
expect(items(w).some((item) => item.attributes("aria-label") === color.toUpperCase()))
|
||||
.toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("maps variants, sizes, layout and disabled states to baseline classes", () => {
|
||||
const variants = render(Variants);
|
||||
const roots = variants
|
||||
.findAll<HTMLElement>("[data-slot=color-swatch-picker]")
|
||||
.map((node) => node.classes());
|
||||
expect(roots[0]).toContain("hv-color-swatch-picker--circle");
|
||||
expect(roots[1]).toContain("hv-color-swatch-picker--square");
|
||||
|
||||
const sizes = render(Sizes);
|
||||
expect(
|
||||
sizes
|
||||
.findAll<HTMLElement>("[data-slot=color-swatch-picker]")
|
||||
.map((node) =>
|
||||
["xs", "sm", "md", "lg", "xl"].find((size) =>
|
||||
node.classes().includes(`hv-color-swatch-picker--${size}`),
|
||||
),
|
||||
),
|
||||
).toEqual(["xs", "sm", "md", "lg", "xl"]);
|
||||
|
||||
const stack = render(StackLayout);
|
||||
expect(
|
||||
stack
|
||||
.get<HTMLElement>("[data-slot=color-swatch-picker]")
|
||||
.classes(),
|
||||
).toContain("hv-color-swatch-picker--stack");
|
||||
|
||||
const disabled = render(Disabled);
|
||||
expect(items(disabled)).toHaveLength(7);
|
||||
for (const item of items(disabled)) {
|
||||
expect(item.attributes("aria-disabled")).toBe("true");
|
||||
expect(item.attributes("data-disabled")).toBe("true");
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the default value, controlled value and real slot state", async () => {
|
||||
const initial = render(DefaultValue);
|
||||
expect(
|
||||
items(initial).map((item) => item.attributes("aria-selected")),
|
||||
).toEqual([
|
||||
"false",
|
||||
"false",
|
||||
"true",
|
||||
"false",
|
||||
"false",
|
||||
"false",
|
||||
"false",
|
||||
]);
|
||||
|
||||
const controlled = render(Controlled);
|
||||
expect(
|
||||
controlled.get("p span").text(),
|
||||
).toBe("#F43F5E");
|
||||
items(controlled)[2]!.trigger("mousedown");
|
||||
await controlled.vm.$nextTick();
|
||||
expect(controlled.get("p span").text()).toBe("#8B5CF6");
|
||||
|
||||
const slots = render(RenderFunction);
|
||||
const root = slots.get<HTMLElement>("[data-slot=color-swatch-picker]");
|
||||
expect(root.attributes("data-custom")).toBe("foo");
|
||||
expect(items(slots)[2]!.attributes("aria-selected")).toBe("false");
|
||||
expect(
|
||||
items(slots)[2]!
|
||||
.find("[data-slot=color-swatch-picker-swatch]")
|
||||
.attributes("data-picker-layout"),
|
||||
).toBe("grid");
|
||||
});
|
||||
|
||||
it("replaces the default checkmark and styles the custom container", () => {
|
||||
const custom = render(CustomIndicator);
|
||||
expect(
|
||||
custom.findAll("[data-slot=color-swatch-picker-checkmark]"),
|
||||
).toHaveLength(0);
|
||||
expect(custom.findAll("svg")).toHaveLength(7);
|
||||
|
||||
const styled = render(CustomStyles);
|
||||
const root = styled.get<HTMLElement>("[data-slot=color-swatch-picker]");
|
||||
expect(root.classes()).toEqual(
|
||||
expect.arrayContaining([
|
||||
"rounded-2xl",
|
||||
"bg-surface",
|
||||
"hv-color-swatch-picker--square",
|
||||
]),
|
||||
);
|
||||
expect(items(styled)[2]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
|
||||
it("documents the Vue API, slot states and recorded differences", () => {
|
||||
const document = readFileSync(
|
||||
"apps/docs/components/color-swatch-picker.md",
|
||||
"utf8",
|
||||
);
|
||||
expect(document).toContain("title: ColorSwatchPicker 颜色色块选择器");
|
||||
expect(document).toContain("`modelValue`");
|
||||
expect(document).toContain("`defaultValue`");
|
||||
expect(document).toContain("`layout`");
|
||||
expect(document).toContain("`size`");
|
||||
expect(document).toContain("`variant`");
|
||||
expect(document).toContain("### Render Props");
|
||||
expect(document).toContain("isSelected");
|
||||
expect(document).toContain("listbox");
|
||||
expect(document).toContain("hexa");
|
||||
expect(document).toContain("可访问名称差异");
|
||||
expect(document).toContain("感知色名");
|
||||
expect(document).toContain("不新增这些字段 API");
|
||||
expect(document).not.toMatch(/\|\s*`className`\s*\|/);
|
||||
});
|
||||
|
||||
it("adds ColorSwatchPicker to the shared navigation", () => {
|
||||
const navigation = readFileSync(
|
||||
"apps/docs/.vitepress/theme/navigation.ts",
|
||||
"utf8",
|
||||
);
|
||||
expect(navigation).toContain("ColorSwatchPicker 颜色色块选择器");
|
||||
expect(navigation).toContain('url: "/components/color-swatch-picker"');
|
||||
expect(navigation).toContain('category: "colors"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,941 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef } from "vue";
|
||||
import {
|
||||
Color,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerIndicator,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerRoot,
|
||||
ColorSwatchPickerSwatch,
|
||||
ConfigProvider,
|
||||
colorSwatchPickerVariants,
|
||||
parseColor,
|
||||
} from "../packages/vue/src";
|
||||
import { serializeColorValue } from "../packages/vue/src/components/color/submission";
|
||||
import type {
|
||||
ColorSwatchPickerExpose,
|
||||
ColorSwatchPickerRenderProps,
|
||||
} from "../packages/vue/src";
|
||||
import Picker from "../packages/vue/src/components/color-picker/ColorPicker.vue";
|
||||
|
||||
const mounted: ReturnType<typeof mount>[] = [];
|
||||
function render(
|
||||
component: Parameters<typeof mount>[0],
|
||||
options: Parameters<typeof mount>[1] = {},
|
||||
) {
|
||||
const w = mount(component, { attachTo: document.body, ...options });
|
||||
mounted.push(w);
|
||||
return w;
|
||||
}
|
||||
afterEach(() => {
|
||||
mounted.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const COLORS = ["#F43F5E", "#D946EF", "#8B5CF6"];
|
||||
|
||||
function picker(
|
||||
props: Record<string, unknown> = {},
|
||||
colors: string[] = COLORS,
|
||||
itemProps: Record<string, unknown> | ((c: string, i: number) => Record<string, unknown>) = {},
|
||||
) {
|
||||
return render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ attrs: props, colors, itemProps }),
|
||||
template: `
|
||||
<ColorSwatchPicker v-bind="attrs">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="(c, index) in colors"
|
||||
:key="index"
|
||||
:color="c"
|
||||
v-bind="typeof itemProps === 'function' ? itemProps(c, index) : itemProps"
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function items(w: ReturnType<typeof mount>) {
|
||||
return w.findAll<HTMLElement>("[data-slot=color-swatch-picker-item]");
|
||||
}
|
||||
|
||||
function press(item: ReturnType<typeof items>[number]) {
|
||||
item.element.dispatchEvent(
|
||||
new MouseEvent("mousedown", { bubbles: true, cancelable: true }),
|
||||
);
|
||||
}
|
||||
|
||||
function keydown(element: Element, key: string, init: KeyboardEventInit = {}) {
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
...init,
|
||||
});
|
||||
element.dispatchEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/** jsdom has no layout; grid movement needs explicit rects (browser evidence
|
||||
* in docs/tasks/results/COLOR-SWATCH-PICKER.md is authoritative). */
|
||||
function withGeometry(w: ReturnType<typeof mount>, columns = 3, size = 32) {
|
||||
const root = w.get<HTMLElement>("[data-slot=color-swatch-picker]").element;
|
||||
vi.spyOn(root, "getBoundingClientRect").mockReturnValue({
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: columns * size,
|
||||
height: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
right: columns * size,
|
||||
bottom: 100,
|
||||
toJSON: () => ({}),
|
||||
} as DOMRect);
|
||||
items(w).forEach((item, index) => {
|
||||
const x = (index % columns) * size;
|
||||
const y = Math.floor(index / columns) * size;
|
||||
vi.spyOn(item.element, "getBoundingClientRect").mockReturnValue({
|
||||
left: x,
|
||||
top: y,
|
||||
width: size,
|
||||
height: size,
|
||||
x,
|
||||
y,
|
||||
right: x + size,
|
||||
bottom: y + size,
|
||||
toJSON: () => ({}),
|
||||
} as DOMRect);
|
||||
});
|
||||
return w;
|
||||
}
|
||||
|
||||
describe("ColorSwatchPicker composition and baseline DOM", () => {
|
||||
it("exposes the five named exports sharing one root implementation", () => {
|
||||
expect(ColorSwatchPicker).toBe(ColorSwatchPickerRoot);
|
||||
const w = picker();
|
||||
const root = w.get<HTMLElement>("[data-slot=color-swatch-picker]");
|
||||
expect(root.attributes("role")).toBe("listbox");
|
||||
expect(root.attributes("aria-orientation")).toBe("vertical");
|
||||
expect(root.classes()).toEqual(
|
||||
expect.arrayContaining([
|
||||
"hv-color-swatch-picker",
|
||||
"hv-color-swatch-picker--md",
|
||||
"hv-color-swatch-picker--circle",
|
||||
"hv-color-swatch-picker--grid",
|
||||
]),
|
||||
);
|
||||
expect(items(w)).toHaveLength(3);
|
||||
const first = items(w)[0]!;
|
||||
expect(first.attributes("role")).toBe("option");
|
||||
expect(first.attributes("aria-selected")).toBe("false");
|
||||
expect(first.attributes("aria-label")).toBe("#F43F5E");
|
||||
expect(first.element.style.getPropertyValue("--color-swatch-current")).toBe(
|
||||
"rgb(244, 63, 94)",
|
||||
);
|
||||
expect(first.classes()).toContain("hv-color-swatch-picker__item");
|
||||
const swatch = w.get<HTMLElement>("[data-slot=color-swatch-picker-swatch]");
|
||||
expect(swatch.attributes("role")).toBe("img");
|
||||
expect(swatch.element.style.backgroundColor).toBe("rgb(244, 63, 94)");
|
||||
const indicator = w.get<HTMLElement>(
|
||||
"[data-slot=color-swatch-picker-indicator]",
|
||||
);
|
||||
expect(indicator.attributes("aria-hidden")).toBe("true");
|
||||
expect(
|
||||
indicator.find("[data-slot=color-swatch-picker-checkmark]").exists(),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("maps size, shape and layout variants to the ported modifiers", () => {
|
||||
expect(colorSwatchPickerVariants({ size: "xl" }).base()).toContain(
|
||||
"hv-color-swatch-picker--xl",
|
||||
);
|
||||
expect(colorSwatchPickerVariants({ variant: "square" }).item()).toBe(
|
||||
"hv-color-swatch-picker__item",
|
||||
);
|
||||
const w = picker({ size: "lg", variant: "square", layout: "stack" });
|
||||
const root = w.get<HTMLElement>("[data-slot=color-swatch-picker]");
|
||||
expect(root.classes()).toEqual(
|
||||
expect.arrayContaining([
|
||||
"hv-color-swatch-picker--lg",
|
||||
"hv-color-swatch-picker--square",
|
||||
"hv-color-swatch-picker--stack",
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the fixed default accessible names and explicit overrides", () => {
|
||||
const w = picker();
|
||||
expect(
|
||||
w.get("[data-slot=color-swatch-picker]").attributes("aria-label"),
|
||||
).toBe("Color swatch picker");
|
||||
const zh = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ConfigProvider,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
template: `
|
||||
<ConfigProvider locale="zh-CN">
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem color="#fff8">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</ConfigProvider>`,
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
zh.get("[data-slot=color-swatch-picker]").attributes("aria-label"),
|
||||
).toBe("颜色色块选择器");
|
||||
expect(items(zh)[0]!.attributes("aria-label")).toBe("#FFFFFF88");
|
||||
|
||||
const explicit = picker({ "aria-label": "Color presets" });
|
||||
expect(
|
||||
explicit.get("[data-slot=color-swatch-picker]").attributes("aria-label"),
|
||||
).toBe("Color presets");
|
||||
const named = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
template: `
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem color="#0000" aria-label="透明色">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
expect(items(named)[0]!.attributes("aria-label")).toBe("透明色");
|
||||
});
|
||||
|
||||
it("decides indicator contrast from the item color luminance", () => {
|
||||
const w = picker({}, ["#FFFFFF", "#000000"]);
|
||||
const indicators = w.findAll<HTMLElement>(
|
||||
"[data-slot=color-swatch-picker-indicator]",
|
||||
);
|
||||
expect(indicators[0]!.attributes("data-light-color")).toBe("true");
|
||||
expect(indicators[1]!.attributes("data-light-color")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("requires the parent parts and keeps item identity structural", () => {
|
||||
expect(() =>
|
||||
mount(ColorSwatchPickerItem, { props: { color: "#000" } }),
|
||||
).toThrow(/ColorSwatchPickerItem requires ColorSwatchPicker/);
|
||||
expect(() => mount(ColorSwatchPickerSwatch)).toThrow(
|
||||
/require ColorSwatchPickerItem/,
|
||||
);
|
||||
const w = picker({}, ["#F43F5E", "#F43F5E"]);
|
||||
expect(items(w)).toHaveLength(2);
|
||||
expect(items(w)[0]!.element).not.toBe(items(w)[1]!.element);
|
||||
const exposed = w.getComponent(ColorSwatchPicker)
|
||||
.vm as unknown as ColorSwatchPickerExpose;
|
||||
expect(exposed.element).toBe(
|
||||
w.get("[data-slot=color-swatch-picker]").element,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ColorSwatchPicker selection", () => {
|
||||
it("selects on pointer press and emits the candidate color unchanged", async () => {
|
||||
const w = picker();
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[1]!);
|
||||
await w.vm.$nextTick();
|
||||
const emitted = root.emitted("update:modelValue")!;
|
||||
expect(emitted).toHaveLength(1);
|
||||
expect((emitted[0]![0] as Color).toString("hex")).toBe("#D946EF");
|
||||
expect(root.emitted("change")).toHaveLength(1);
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("true");
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("false");
|
||||
expect(items(w)[1]!.attributes("data-selected")).toBe("true");
|
||||
});
|
||||
|
||||
it("keeps the candidate's own color space instead of rewriting it", () => {
|
||||
const w = picker({}, ["hsl(210, 100%, 50%)"]);
|
||||
press(items(w)[0]!);
|
||||
const value = w
|
||||
.getComponent(ColorSwatchPicker)
|
||||
.emitted("update:modelValue")![0]![0] as Color;
|
||||
expect(value.getColorSpace()).toBe("hsl");
|
||||
expect(value.toString("hex").toLowerCase()).toBe("#007fff");
|
||||
});
|
||||
|
||||
it("never emits when re-selecting the accepted color and honours cancelable presses", async () => {
|
||||
const w = picker({ defaultValue: COLORS[1] });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[1]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toBeUndefined();
|
||||
|
||||
const cancelled = picker(
|
||||
{ defaultValue: COLORS[1] },
|
||||
COLORS,
|
||||
{ onMousedown: (event: MouseEvent) => event.preventDefault() },
|
||||
);
|
||||
press(items(cancelled)[0]!);
|
||||
await cancelled.vm.$nextTick();
|
||||
expect(
|
||||
cancelled.getComponent(ColorSwatchPicker).emitted("update:modelValue"),
|
||||
).toBeUndefined();
|
||||
expect(items(cancelled)[1]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
|
||||
it("blocks selection from disabled items and a disabled root", () => {
|
||||
const w = picker({}, COLORS, (_c: string, index: number) => ({
|
||||
isDisabled: index === 1,
|
||||
}));
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
expect(items(w)[1]!.attributes("aria-disabled")).toBe("true");
|
||||
expect(items(w)[1]!.attributes("data-disabled")).toBe("true");
|
||||
expect(items(w)[1]!.attributes("tabindex")).toBeUndefined();
|
||||
press(items(w)[1]!);
|
||||
expect(root.emitted("update:modelValue")).toBeUndefined();
|
||||
|
||||
const off = picker({ isDisabled: true });
|
||||
expect(
|
||||
off.get("[data-slot=color-swatch-picker]").attributes("aria-disabled"),
|
||||
).toBe("true");
|
||||
press(items(off)[0]!);
|
||||
expect(
|
||||
off.getComponent(ColorSwatchPicker).emitted("update:modelValue"),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps the accepted state when a controlled parent rejects, then retries", async () => {
|
||||
const value = shallowRef(parseColor("#F43F5E"));
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ value }),
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<ColorSwatchPicker :model-value="value">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="(c, index) in colors"
|
||||
:key="index"
|
||||
:color="c"
|
||||
>
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[2]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("false");
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("true");
|
||||
// Same proposal again after the rejection: the change retries.
|
||||
press(items(w)[2]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(2);
|
||||
value.value = parseColor("#8B5CF6");
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
|
||||
it("treats equivalent formats as the fixed hexa key without rewriting values", () => {
|
||||
const red = parseColor("#8B5CF6");
|
||||
const hsl = red.toFormat("hsl").toString("hsl");
|
||||
const w = picker({ defaultValue: "rgb(139, 92, 246)" }, [hsl, "#8B5CF6"]);
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("true");
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("true");
|
||||
|
||||
// Alpha is compared at the fixed 8-bit scale only for matching.
|
||||
const alpha = picker({ defaultValue: "rgba(0, 0, 255, 0.5)" }, [
|
||||
"#0000FF80",
|
||||
]);
|
||||
expect(items(alpha)[0]!.attributes("aria-selected")).toBe("true");
|
||||
|
||||
// Gray hues collapse through the RGB key while the value keeps its hue.
|
||||
const gray = picker({ defaultValue: "hsl(120, 0%, 50%)" }, ["#808080"]);
|
||||
expect(items(gray)[0]!.attributes("aria-selected")).toBe("true");
|
||||
|
||||
// Different bytes never match, no matter how close.
|
||||
const near = picker({ defaultValue: "#8B5CF6" }, ["#8B5CF7"]);
|
||||
expect(items(near)[0]!.attributes("aria-selected")).toBe("false");
|
||||
});
|
||||
|
||||
it("records the documented empty-value and dynamic candidate behaviour", async () => {
|
||||
// No initial value: the fixed default is #000000 and nothing is picked.
|
||||
const w = picker({}, ["#FFFFFF"]);
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("false");
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("true");
|
||||
|
||||
const cleared = picker({ modelValue: null });
|
||||
expect(
|
||||
items(cleared).every(
|
||||
(item) => item.attributes("aria-selected") === "false",
|
||||
),
|
||||
).toBe(true);
|
||||
|
||||
const missing = picker({ defaultValue: "#F43F5E" }, ["#D946EF"]);
|
||||
expect(items(missing)[0]!.attributes("aria-selected")).toBe("false");
|
||||
|
||||
const colors = shallowRef([...COLORS]);
|
||||
const dyn = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ colors }),
|
||||
template: `
|
||||
<ColorSwatchPicker default-value="#8B5CF6">
|
||||
<ColorSwatchPickerItem v-for="c in colors" :key="c" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
expect(items(dyn)[2]!.attributes("aria-selected")).toBe("true");
|
||||
// Removing the selected candidate keeps the accepted color.
|
||||
colors.value = [COLORS[0]!, COLORS[1]!];
|
||||
await dyn.vm.$nextTick();
|
||||
expect(items(dyn)).toHaveLength(2);
|
||||
expect(
|
||||
items(dyn).every((item) => item.attributes("aria-selected") === "false"),
|
||||
).toBe(true);
|
||||
colors.value = [];
|
||||
await dyn.vm.$nextTick();
|
||||
expect(items(dyn)).toHaveLength(0);
|
||||
expect(
|
||||
dyn.get("[data-slot=color-swatch-picker]").attributes("role"),
|
||||
).toBe("listbox");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ColorSwatchPicker focus and keyboard", () => {
|
||||
it("keeps a single tab stop and marshals the entry focus", async () => {
|
||||
const w = picker({ defaultValue: COLORS[1] });
|
||||
const root = w.get<HTMLElement>("[data-slot=color-swatch-picker]");
|
||||
expect(root.attributes("tabindex")).toBe("0");
|
||||
expect(items(w).map((item) => item.attributes("tabindex"))).toEqual([
|
||||
"-1",
|
||||
"-1",
|
||||
"-1",
|
||||
]);
|
||||
(
|
||||
w.getComponent(ColorSwatchPicker).vm as unknown as ColorSwatchPickerExpose
|
||||
).focus();
|
||||
await w.vm.$nextTick();
|
||||
expect(document.activeElement).toBe(items(w)[1]!.element);
|
||||
expect(root.attributes("tabindex")).toBe("-1");
|
||||
expect(items(w).map((item) => item.attributes("tabindex"))).toEqual([
|
||||
"-1",
|
||||
"0",
|
||||
"-1",
|
||||
]);
|
||||
expect(items(w)[1]!.attributes("data-focused")).toBe("true");
|
||||
expect(root.attributes("data-focused")).toBe("true");
|
||||
});
|
||||
|
||||
it("moves focus without selecting and selects only on Enter/Space", async () => {
|
||||
const w = picker({ layout: "stack" });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
items(w)[0]!.element.focus();
|
||||
keydown(items(w)[0]!.element, "ArrowDown");
|
||||
await w.vm.$nextTick();
|
||||
expect(document.activeElement).toBe(items(w)[1]!.element);
|
||||
expect(root.emitted("update:modelValue")).toBeUndefined();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("false");
|
||||
keydown(items(w)[1]!.element, "Enter");
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("true");
|
||||
keydown(items(w)[1]!.element, " ");
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("true");
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("walks, jumps and stops at the boundaries without wrapping", () => {
|
||||
const w = picker({ layout: "stack" });
|
||||
items(w)[0]!.element.focus();
|
||||
keydown(items(w)[0]!.element, "End");
|
||||
expect(document.activeElement).toBe(items(w)[2]!.element);
|
||||
const atEnd = keydown(items(w)[2]!.element, "ArrowDown");
|
||||
expect(document.activeElement).toBe(items(w)[2]!.element);
|
||||
expect(atEnd.defaultPrevented).toBe(false);
|
||||
keydown(items(w)[2]!.element, "Home");
|
||||
expect(document.activeElement).toBe(items(w)[0]!.element);
|
||||
});
|
||||
|
||||
it("uses order movement horizontally in grid and ignores it in stack", () => {
|
||||
const grid = withGeometry(picker());
|
||||
items(grid)[1]!.element.focus();
|
||||
keydown(items(grid)[1]!.element, "ArrowRight");
|
||||
expect(document.activeElement).toBe(items(grid)[2]!.element);
|
||||
keydown(items(grid)[2]!.element, "ArrowLeft");
|
||||
expect(document.activeElement).toBe(items(grid)[1]!.element);
|
||||
|
||||
const stack = picker({ layout: "stack" });
|
||||
items(stack)[1]!.element.focus();
|
||||
const event = keydown(items(stack)[1]!.element, "ArrowRight");
|
||||
expect(document.activeElement).toBe(items(stack)[1]!.element);
|
||||
expect(event.defaultPrevented).toBe(false);
|
||||
keydown(items(stack)[1]!.element, "ArrowDown");
|
||||
expect(document.activeElement).toBe(items(stack)[2]!.element);
|
||||
});
|
||||
|
||||
it("moves across wrapped grid rows by geometry and reverses in RTL", () => {
|
||||
const w = withGeometry(
|
||||
picker(
|
||||
{},
|
||||
["#F43F5E", "#D946EF", "#8B5CF6", "#3B82F6", "#06B6D4", "#10B981"],
|
||||
),
|
||||
);
|
||||
items(w)[1]!.element.focus();
|
||||
keydown(items(w)[1]!.element, "ArrowDown");
|
||||
expect(document.activeElement).toBe(items(w)[4]!.element);
|
||||
keydown(items(w)[4]!.element, "ArrowUp");
|
||||
expect(document.activeElement).toBe(items(w)[1]!.element);
|
||||
// No item shares the column below index 3 in a 3x2 grid.
|
||||
items(w)[3]!.element.focus();
|
||||
keydown(items(w)[3]!.element, "ArrowDown");
|
||||
expect(document.activeElement).toBe(items(w)[3]!.element);
|
||||
|
||||
const rtl = picker({ dir: "rtl" });
|
||||
items(rtl)[1]!.element.focus();
|
||||
keydown(items(rtl)[1]!.element, "ArrowRight");
|
||||
expect(document.activeElement).toBe(items(rtl)[0]!.element);
|
||||
keydown(items(rtl)[0]!.element, "ArrowLeft");
|
||||
expect(document.activeElement).toBe(items(rtl)[1]!.element);
|
||||
});
|
||||
|
||||
it("skips disabled items, jumps pages and types to focus", () => {
|
||||
const w = picker({ layout: "stack" }, COLORS, (_c: string, index: number) => ({
|
||||
isDisabled: index === 1,
|
||||
}));
|
||||
items(w)[0]!.element.focus();
|
||||
keydown(items(w)[0]!.element, "ArrowDown");
|
||||
expect(document.activeElement).toBe(items(w)[2]!.element);
|
||||
keydown(items(w)[2]!.element, "PageUp");
|
||||
expect(document.activeElement).toBe(items(w)[0]!.element);
|
||||
keydown(items(w)[0]!.element, "PageDown");
|
||||
expect(document.activeElement).toBe(items(w)[2]!.element);
|
||||
|
||||
const typed = picker({ layout: "stack" }, ["#F43F5E", "#D946EF"], (_c: string, index: number) => ({
|
||||
"aria-label": index === 1 ? "品红" : "珊瑚红",
|
||||
}));
|
||||
items(typed)[0]!.element.focus();
|
||||
keydown(items(typed)[0]!.element, "品");
|
||||
expect(document.activeElement).toBe(items(typed)[1]!.element);
|
||||
});
|
||||
|
||||
it("returns focus to the listbox when the focused item goes away", async () => {
|
||||
const colors = shallowRef([...COLORS]);
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ colors }),
|
||||
template: `
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem v-for="c in colors" :key="c" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
items(w)[1]!.element.focus();
|
||||
colors.value = [COLORS[0]!, COLORS[2]!];
|
||||
await w.vm.$nextTick();
|
||||
expect(
|
||||
w.get<HTMLElement>("[data-slot=color-swatch-picker]").attributes(
|
||||
"tabindex",
|
||||
),
|
||||
).toBe("0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ColorSwatchPicker scoped slots", () => {
|
||||
it("passes real item state to the item and indicator slots", async () => {
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<ColorSwatchPicker default-value="#8B5CF6">
|
||||
<ColorSwatchPickerItem
|
||||
v-for="(c, index) in colors"
|
||||
:key="index"
|
||||
:color="c"
|
||||
v-slot="state"
|
||||
>
|
||||
<ColorSwatchPickerSwatch :data-selected-state="state.isSelected" />
|
||||
<ColorSwatchPickerIndicator>
|
||||
<span data-custom-check>{{ state.color.toString('hex') }}</span>
|
||||
</ColorSwatchPickerIndicator>
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
const states = items(w).map((item) => ({
|
||||
selected: item
|
||||
.find("[data-slot=color-swatch-picker-swatch]")
|
||||
.attributes("data-selected-state"),
|
||||
check: item.find("[data-custom-check]").text(),
|
||||
}));
|
||||
expect(states).toEqual([
|
||||
{ selected: "false", check: "#F43F5E" },
|
||||
{ selected: "false", check: "#D946EF" },
|
||||
{ selected: "true", check: "#8B5CF6" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("exposes the root render state", async () => {
|
||||
let seen: ColorSwatchPickerRenderProps | undefined;
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ capture: (state: ColorSwatchPickerRenderProps) => { seen = state; } }),
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<ColorSwatchPicker v-slot="root" default-value="#8B5CF6" is-disabled>
|
||||
<span data-probe>{{ capture(root) }}</span>
|
||||
<ColorSwatchPickerItem v-for="(c, index) in colors" :key="index" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>`,
|
||||
}),
|
||||
);
|
||||
await w.vm.$nextTick();
|
||||
expect(seen).toMatchObject({
|
||||
isEmpty: false,
|
||||
isDisabled: true,
|
||||
isReadOnly: false,
|
||||
layout: "grid",
|
||||
});
|
||||
expect(seen!.color?.toString("hex")).toBe("#8B5CF6");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ColorSwatchPicker owner composition", () => {
|
||||
function composition(attrs = "") {
|
||||
return render(
|
||||
defineComponent({
|
||||
components: {
|
||||
Picker,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<form>
|
||||
<Picker name="color" default-value="#8B5CF6" ${attrs}>
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem v-for="(c, index) in colors" :key="index" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</Picker>
|
||||
</form>`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
it("inherits the owner color without a second state source", async () => {
|
||||
const w = composition();
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
const values = () =>
|
||||
new FormData(w.get("form").element as HTMLFormElement).getAll("color");
|
||||
expect(values()).toEqual([serializeColorValue(parseColor("#F43F5E"))]);
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("true");
|
||||
// Exactly one named submission while the picker children are mounted.
|
||||
expect(w.element.querySelectorAll("input[name=color]")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps an explicit own value and switches ownership dynamically", async () => {
|
||||
const own = composition('value="#D946EF"');
|
||||
expect(items(own)[1]!.attributes("aria-selected")).toBe("true");
|
||||
const controlled = shallowRef<string | undefined>(undefined);
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
Picker,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({
|
||||
controlled,
|
||||
own: () => (controlled.value ? { value: controlled.value } : {}),
|
||||
}),
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<Picker default-value="#8B5CF6">
|
||||
<ColorSwatchPicker v-bind="own()">
|
||||
<ColorSwatchPickerItem v-for="(c, index) in colors" :key="index" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</Picker>`,
|
||||
}),
|
||||
);
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
controlled.value = "#F43F5E";
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("true");
|
||||
controlled.value = undefined;
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
|
||||
it("restores the owner DOM after a form reset even when a rejection kept the value", async () => {
|
||||
const value = shallowRef(parseColor("#8B5CF6"));
|
||||
const w = render(
|
||||
defineComponent({
|
||||
components: {
|
||||
Picker,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
},
|
||||
setup: () => ({ value }),
|
||||
data: () => ({ colors: COLORS }),
|
||||
template: `
|
||||
<form>
|
||||
<Picker name="color" :value="value">
|
||||
<ColorSwatchPicker>
|
||||
<ColorSwatchPickerItem v-for="(c, index) in colors" :key="index" :color="c">
|
||||
<ColorSwatchPickerSwatch />
|
||||
<ColorSwatchPickerIndicator />
|
||||
</ColorSwatchPickerItem>
|
||||
</ColorSwatchPicker>
|
||||
</Picker>
|
||||
</form>`,
|
||||
}),
|
||||
);
|
||||
const native = w.get<HTMLInputElement>("input[type=hidden]");
|
||||
const accepted = serializeColorValue(parseColor("#8B5CF6"));
|
||||
expect(native.element.value).toBe(accepted);
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
// The parent rejects: the accepted value and DOM stay put.
|
||||
expect(native.element.value).toBe(accepted);
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
expect(items(w)[0]!.attributes("aria-selected")).toBe("false");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
expect(native.element.value).toBe(accepted);
|
||||
expect(items(w)[2]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("ColorSwatchPicker activation lifecycle and dynamic focus", () => {
|
||||
it("ignores secondary mouse buttons", async () => {
|
||||
const w = picker();
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 2 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(w.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toBeUndefined();
|
||||
// Middle-button counter-example: never a selection gesture either.
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 1 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(w.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toBeUndefined();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("false");
|
||||
expect(items(w)[1]!.attributes("data-pressed")).toBeUndefined();
|
||||
});
|
||||
it("clears pressed state after the primary mouse release", async () => {
|
||||
const w = picker();
|
||||
press(items(w)[0]!);
|
||||
items(w)[0]!.element.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBeUndefined();
|
||||
// A release elsewhere inside the listbox clears the state as well.
|
||||
press(items(w)[1]!);
|
||||
w.get("[data-slot=color-swatch-picker]").element.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[1]!.attributes("data-pressed")).toBeUndefined();
|
||||
// Dragging out cancels the press before any release.
|
||||
press(items(w)[2]!);
|
||||
items(w)[2]!.trigger("mouseleave");
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[2]!.attributes("data-pressed")).toBeUndefined();
|
||||
// A press that steals focus from another item keeps its own press state.
|
||||
items(w)[1]!.element.focus();
|
||||
await w.vm.$nextTick();
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBe("true");
|
||||
items(w)[0]!.element.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBeUndefined();
|
||||
});
|
||||
it("keeps an enabled tab entry after dynamically disabling the focused item", async () => {
|
||||
const off = shallowRef(false);
|
||||
const w = render(defineComponent({
|
||||
components: { ColorSwatchPicker, ColorSwatchPickerItem },
|
||||
setup: () => ({ off }),
|
||||
template: `<ColorSwatchPicker><ColorSwatchPickerItem color="#F43F5E" :is-disabled="off"/><ColorSwatchPickerItem color="#D946EF"/></ColorSwatchPicker>`,
|
||||
}));
|
||||
items(w)[0]!.element.focus();
|
||||
await w.vm.$nextTick();
|
||||
off.value = true;
|
||||
await w.vm.$nextTick();
|
||||
await w.vm.$nextTick();
|
||||
const root = w.get("[data-slot=color-swatch-picker]");
|
||||
const enabledTabEntries = [root, ...items(w)].filter(node => node.attributes("tabindex") === "0" && node.attributes("aria-disabled") !== "true");
|
||||
expect(enabledTabEntries).toHaveLength(1);
|
||||
// Focus is not lost to the document while the entry is rebuilt.
|
||||
expect(document.activeElement).not.toBe(document.body);
|
||||
// Re-enabling the item keeps a single legal entry again.
|
||||
off.value = false;
|
||||
await w.vm.$nextTick();
|
||||
await w.vm.$nextTick();
|
||||
expect([root, ...items(w)].filter(node => node.attributes("tabindex") === "0" && node.attributes("aria-disabled") !== "true")).toHaveLength(1);
|
||||
});
|
||||
it("keeps legal tab entries for all-disabled items and a disabled root", async () => {
|
||||
const off = shallowRef(false);
|
||||
const w = render(defineComponent({
|
||||
components: { ColorSwatchPicker, ColorSwatchPickerItem },
|
||||
setup: () => ({ off }),
|
||||
template: `<ColorSwatchPicker :is-disabled="off"><ColorSwatchPickerItem color="#F43F5E" is-disabled/><ColorSwatchPickerItem color="#D946EF" is-disabled/></ColorSwatchPicker>`,
|
||||
}));
|
||||
const root = w.get("[data-slot=color-swatch-picker]");
|
||||
// Every option disabled: the listbox itself stays the single entry.
|
||||
expect([root, ...items(w)].filter(node => node.attributes("tabindex") === "0" && node.attributes("aria-disabled") !== "true")).toHaveLength(1);
|
||||
// A disabled root leaves the tab order entirely, then restores one entry.
|
||||
off.value = true;
|
||||
await w.vm.$nextTick();
|
||||
expect([root, ...items(w)].filter(node => node.attributes("tabindex") === "0")).toHaveLength(0);
|
||||
off.value = false;
|
||||
await w.vm.$nextTick();
|
||||
expect([root, ...items(w)].filter(node => node.attributes("tabindex") === "0" && node.attributes("aria-disabled") !== "true")).toHaveLength(1);
|
||||
});
|
||||
it("supports click-only activation used by assistive technology", async () => {
|
||||
const w = picker();
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("true");
|
||||
});
|
||||
it("keeps press ownership so normal clicks never re-propose", async () => {
|
||||
const w = picker();
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[1]!);
|
||||
// The compatibility click of the press does not emit a second proposal.
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 1 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
// Click-only activation stays cancelable and skips disabled items.
|
||||
const cancelled = picker({}, COLORS, { onClick: (event: MouseEvent) => event.preventDefault() });
|
||||
items(cancelled)[0]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await cancelled.vm.$nextTick();
|
||||
expect(cancelled.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toBeUndefined();
|
||||
const disabled = picker({}, COLORS, (_c: string, index: number) => ({ isDisabled: index === 1 }));
|
||||
items(disabled)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await disabled.vm.$nextTick();
|
||||
expect(disabled.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("ColorSwatchPicker activation cancellation boundaries", () => {
|
||||
it("clears pressed state when the browser window loses focus", async () => {
|
||||
const w = picker();
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBe("true");
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBeUndefined();
|
||||
});
|
||||
it("allows click-only retry after a press is cancelled by window blur", async () => {
|
||||
const w = picker({ modelValue: COLORS[0] });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[1]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
it("keeps cancellation scoped to the targeted picker", async () => {
|
||||
const first = picker();
|
||||
const second = picker({ modelValue: COLORS[0] });
|
||||
press(items(first)[1]!);
|
||||
press(items(second)[1]!);
|
||||
await second.vm.$nextTick();
|
||||
first.get("[data-slot=color-swatch-picker]").element.dispatchEvent(new Event("pointercancel", { bubbles: true }));
|
||||
await second.vm.$nextTick();
|
||||
expect(items(second)[1]!.attributes("data-pressed")).toBe("true");
|
||||
// Cancelling the first owner must not clear the second's click suppression.
|
||||
items(second)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await second.vm.$nextTick();
|
||||
expect(second.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toHaveLength(1);
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
await second.vm.$nextTick();
|
||||
expect(items(second)[1]!.attributes("data-pressed")).toBeUndefined();
|
||||
items(second)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await second.vm.$nextTick();
|
||||
expect(second.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
it("allows repeated click-only proposals after controlled rejection", async () => {
|
||||
const w = picker({ modelValue: COLORS[0] });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("false");
|
||||
}
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -182,6 +182,61 @@ for (const id of process.argv.slice(2)) {
|
||||
"ColorSwatch declarations leak Reka types",
|
||||
);
|
||||
}
|
||||
if (id === "color-swatch-picker") {
|
||||
assert(lib.ColorSwatchPicker === lib.ColorSwatchPickerRoot);
|
||||
assert(lib.ColorSwatchPickerItem);
|
||||
assert(lib.ColorSwatchPickerSwatch);
|
||||
assert(lib.ColorSwatchPickerIndicator);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.base()
|
||||
.includes("hv-color-swatch-picker"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants({ layout: "stack", variant: "square" })
|
||||
.base()
|
||||
.includes("hv-color-swatch-picker--stack"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants({ size: "xs" })
|
||||
.item() === "hv-color-swatch-picker__item",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.swatch() === "hv-color-swatch-picker__swatch",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.indicator() === "hv-color-swatch-picker__indicator",
|
||||
);
|
||||
const pickerDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-swatch-picker/ColorSwatchPicker.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
const itemDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-swatch-picker/ColorSwatchPickerItem.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
assert(
|
||||
!pickerDts.includes("reka-ui"),
|
||||
"ColorSwatchPicker declarations leak Reka types",
|
||||
);
|
||||
assert(
|
||||
!itemDts.includes("reka-ui"),
|
||||
"ColorSwatchPickerItem declarations leak Reka types",
|
||||
);
|
||||
}
|
||||
if (id === "color-slider") {
|
||||
assert(lib.ColorSlider === lib.ColorSliderRoot);
|
||||
assert(lib.ColorSliderOutput);
|
||||
|
||||
@@ -372,6 +372,27 @@
|
||||
"repeating-conic-gradient"
|
||||
]
|
||||
},
|
||||
"color-swatch-picker": {
|
||||
"exports": [
|
||||
"ColorSwatchPicker",
|
||||
"ColorSwatchPickerRoot",
|
||||
"ColorSwatchPickerItem",
|
||||
"ColorSwatchPickerSwatch",
|
||||
"ColorSwatchPickerIndicator",
|
||||
"colorSwatchPickerVariants"
|
||||
],
|
||||
"css": [
|
||||
".hv-color-swatch-picker",
|
||||
".hv-color-swatch-picker--stack",
|
||||
".hv-color-swatch-picker--square",
|
||||
".hv-color-swatch-picker--xl",
|
||||
".hv-color-swatch-picker__item",
|
||||
".hv-color-swatch-picker__swatch",
|
||||
".hv-color-swatch-picker__indicator",
|
||||
"data-light-color",
|
||||
"repeating-conic-gradient"
|
||||
]
|
||||
},
|
||||
"time-field": {
|
||||
"exports": [
|
||||
"TimeField",
|
||||
@@ -488,6 +509,6 @@
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorPicker", "ColorSwatchPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerRoot,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
ColorSwatchPickerIndicator,
|
||||
colorSwatchPickerVariants,
|
||||
parseColor,
|
||||
type ColorSwatchPickerProps,
|
||||
type ColorSwatchPickerRootProps,
|
||||
type ColorSwatchPickerItemProps,
|
||||
type ColorSwatchPickerSwatchProps,
|
||||
type ColorSwatchPickerIndicatorProps,
|
||||
type ColorSwatchPickerExpose,
|
||||
type ColorSwatchPickerItemExpose,
|
||||
type ColorSwatchPickerItemRenderProps,
|
||||
type ColorSwatchPickerItemSlots,
|
||||
type ColorSwatchPickerIndicatorSlots,
|
||||
type ColorSwatchPickerLayout,
|
||||
type ColorSwatchPickerRenderProps,
|
||||
type ColorSwatchPickerShape,
|
||||
type ColorSwatchPickerSize,
|
||||
type ColorSwatchPickerSlots,
|
||||
type ColorSwatchPickerVariants,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const props: ColorSwatchPickerProps = {
|
||||
modelValue: parseColor("#123456"),
|
||||
value: "#abcdef",
|
||||
defaultValue: null,
|
||||
layout: "stack",
|
||||
size: "xl",
|
||||
variant: "square",
|
||||
isDisabled: false,
|
||||
disabled: false,
|
||||
isReadOnly: true,
|
||||
dir: "rtl",
|
||||
as: "div",
|
||||
};
|
||||
const root: ColorSwatchPickerRootProps = props;
|
||||
const item: ColorSwatchPickerItemProps = {
|
||||
color: "hsl(210, 100%, 50%)",
|
||||
isDisabled: true,
|
||||
as: "div",
|
||||
};
|
||||
const swatch: ColorSwatchPickerSwatchProps = {
|
||||
color: parseColor("#f008"),
|
||||
colorName: "海洋蓝",
|
||||
as: "span",
|
||||
};
|
||||
const indicator: ColorSwatchPickerIndicatorProps = { as: "span" };
|
||||
const slots: ColorSwatchPickerSlots = {
|
||||
default: (s) => [h("span", {}, [s.color?.toString("hex"), String(s.layout)])],
|
||||
};
|
||||
const itemSlots: ColorSwatchPickerItemSlots = {
|
||||
default: (s: ColorSwatchPickerItemRenderProps) => [
|
||||
h("span", s.isSelected ? s.color.toString("hexa") : "none"),
|
||||
],
|
||||
};
|
||||
const indicatorSlots: ColorSwatchPickerIndicatorSlots = itemSlots;
|
||||
const state: ColorSwatchPickerRenderProps = {
|
||||
color: null,
|
||||
isEmpty: false,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isFocused: false,
|
||||
layout: "grid",
|
||||
};
|
||||
const itemState: ColorSwatchPickerItemRenderProps = {
|
||||
color: parseColor("#8B5CF6"),
|
||||
isSelected: true,
|
||||
isDisabled: false,
|
||||
isFocused: true,
|
||||
isFocusVisible: true,
|
||||
isPressed: false,
|
||||
isHovered: false,
|
||||
};
|
||||
const variant: ColorSwatchPickerVariants = {
|
||||
layout: "grid",
|
||||
size: "md",
|
||||
variant: "circle",
|
||||
};
|
||||
const layout: ColorSwatchPickerLayout = "stack";
|
||||
const size: ColorSwatchPickerSize = "xs";
|
||||
const shape: ColorSwatchPickerShape = "square";
|
||||
colorSwatchPickerVariants(variant).swatch();
|
||||
|
||||
h(ColorSwatchPicker, {
|
||||
...props,
|
||||
"onUpdate:modelValue": (value) => value.toString("hex"),
|
||||
onChange: (value) => value.toString("hexa"),
|
||||
});
|
||||
h(ColorSwatchPickerRoot, root);
|
||||
h(ColorSwatchPickerItem, item);
|
||||
h(ColorSwatchPickerSwatch, swatch);
|
||||
h(ColorSwatchPickerIndicator, indicator);
|
||||
declare const picker: InstanceType<typeof ColorSwatchPicker>;
|
||||
picker.focus();
|
||||
picker.element?.focus();
|
||||
const exposed: ColorSwatchPickerExpose = picker;
|
||||
declare const row: InstanceType<typeof ColorSwatchPickerItem>;
|
||||
row.element?.focus();
|
||||
const itemExposed: ColorSwatchPickerItemExpose = row;
|
||||
|
||||
// @ts-expect-error invalid model
|
||||
const bad: ColorSwatchPickerProps = { modelValue: 123 };
|
||||
// @ts-expect-error invalid layout
|
||||
const badLayout: ColorSwatchPickerProps = { layout: "carousel" };
|
||||
// @ts-expect-error invalid size
|
||||
const badSize: ColorSwatchPickerProps = { size: "huge" };
|
||||
// @ts-expect-error invalid variant
|
||||
h(ColorSwatchPicker, { variant: "pill" });
|
||||
// @ts-expect-error actual public component rejects invalid model
|
||||
h(ColorSwatchPicker, { modelValue: 123 });
|
||||
// @ts-expect-error item color must be a color value
|
||||
const badColor: ColorSwatchPickerItemProps = { color: 123 };
|
||||
// @ts-expect-error no public transaction or owner state
|
||||
picker.state.begin();
|
||||
// @ts-expect-error item state is exposed through slots only
|
||||
row.selectedKeys;
|
||||
void [
|
||||
slots,
|
||||
itemSlots,
|
||||
indicatorSlots,
|
||||
state,
|
||||
itemState,
|
||||
exposed,
|
||||
itemExposed,
|
||||
bad,
|
||||
badLayout,
|
||||
badSize,
|
||||
badColor,
|
||||
layout,
|
||||
size,
|
||||
shape,
|
||||
];
|
||||
Reference in New Issue
Block a user