Compare commits
5 Commits
1c943efe74
...
7287318d86
| Author | SHA1 | Date | |
|---|---|---|---|
| 7287318d86 | |||
| ec350c5f4e | |||
| 71b8c77ba8 | |||
| 6a7a89be6b | |||
| 108a120c81 |
@@ -95,6 +95,11 @@ export const componentItems: DocsItem[] = [
|
||||
url: "/components/color-area",
|
||||
category: "colors",
|
||||
},
|
||||
{
|
||||
title: "ColorField 颜色输入框",
|
||||
url: "/components/color-field",
|
||||
category: "colors",
|
||||
},
|
||||
{
|
||||
title: "ColorSlider 颜色滑块",
|
||||
url: "/components/color-slider",
|
||||
|
||||
@@ -178,4 +178,4 @@ Vue 版写作 `ColorAreaThumb`(对应上游 `ColorArea.Thumb`)。
|
||||
|
||||
## 相关组件
|
||||
|
||||
本批次公开 ColorArea 与 ColorSwatch。ColorField、ColorInputGroup、ColorPicker、ColorSlider 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
---
|
||||
title: ColorField 颜色输入框
|
||||
description: 支持 Hex 与颜色通道编辑的颜色输入字段,支持标签、描述与验证
|
||||
component: color-field
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<ColorField default-value="#0485F7" name="color">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch color="#0485F7" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>选择你的颜色</Description>
|
||||
<FieldError />
|
||||
</ColorField>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="color-field-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<ColorField default-value="#0485F7" name="color">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch color="#0485F7" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>选择你的颜色</Description>
|
||||
<FieldError />
|
||||
</ColorField>
|
||||
</template>
|
||||
```
|
||||
|
||||
> **ColorField** 将标签、颜色输入、描述与错误合并为单个无障碍组件。
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
ColorFieldGroup 组件支持两种视觉变体:
|
||||
|
||||
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
|
||||
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
|
||||
|
||||
<ComponentPreview name="color-field-variants" />
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 [Surface](/components/surface) 组件内使用时,在 ColorFieldGroup 上使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="color-field-on-surface" />
|
||||
|
||||
### 带描述
|
||||
|
||||
<ComponentPreview name="color-field-with-description" />
|
||||
|
||||
### 必填字段
|
||||
|
||||
<ComponentPreview name="color-field-required" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="color-field-disabled" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="color-field-full-width" />
|
||||
|
||||
### 表单校验
|
||||
|
||||
将 `isInvalid` 与 `FieldError` 一起使用以显示验证消息。
|
||||
|
||||
<ComponentPreview name="color-field-invalid" />
|
||||
|
||||
### 分量编辑
|
||||
|
||||
ColorField 支持通过设置 `colorSpace` 与 `channel` 属性编辑单个颜色通道(hue、saturation、lightness、red、green、blue、alpha)。
|
||||
|
||||
<ComponentPreview name="color-field-channel-editing" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
控制值以与其他组件或状态管理同步。
|
||||
|
||||
<ComponentPreview name="color-field-controlled" />
|
||||
|
||||
### 表单示例
|
||||
|
||||
包含验证与提交处理的完整表单示例。
|
||||
|
||||
<ComponentPreview name="color-field-form-example" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
上游 `render` 的元素替换使用 `as` 和透传属性实现;Vue 默认作用域插槽提供实时字段状态,`styleFn` 可依据状态计算样式。
|
||||
|
||||
<ComponentPreview name="color-field-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="color-field-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
ColorField 默认样式较少。覆盖 `.hv-color-field` 类以自定义容器样式。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-color-field {
|
||||
@apply flex flex-col gap-1;
|
||||
|
||||
&[data-invalid="true"],
|
||||
&[aria-invalid="true"] {
|
||||
[data-slot="description"] {
|
||||
@apply hidden;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply w-fit;
|
||||
}
|
||||
|
||||
[data-slot="description"] {
|
||||
@apply px-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
- `.hv-color-field` – 最小样式的根容器(`flex flex-col gap-1`)
|
||||
|
||||
> **Note:** 子组件([Label](/components/label)、[Description](/components/description)、[FieldError](/components/field-error))有各自的 CSS 类与样式。请参阅各自文档了解自定义选项。ColorFieldGroup 样式见下方 API 参考。
|
||||
|
||||
### 交互状态
|
||||
|
||||
ColorField 根据状态自动管理以下 data 属性:
|
||||
|
||||
- **Invalid**:`[data-invalid="true"]` 或 `[aria-invalid="true"]` - 无效时自动隐藏 description slot
|
||||
- **Required**:`[data-required="true"]` - `isRequired` 为 true 时应用
|
||||
- **Disabled**:`[data-disabled="true"]` - `isDisabled` 为 true 时应用
|
||||
- **Focus Within**:`[data-focus-within="true"]` - 任一子 input 聚焦时应用
|
||||
|
||||
## API 参考
|
||||
|
||||
### ColorField
|
||||
|
||||
`ColorFieldRoot` 是 `ColorField` 的别名;Vue 使用具名部件与 `v-model`,颜色复用本库 `Color`。不声明继承全部 React Aria 属性。
|
||||
|
||||
| Prop / 事件 | 类型 | 默认值 | 描述 |
|
||||
| -------------------------------- | ------------------------------------------ | ---------------------- | ----------------------------------------------------------------------------------- |
|
||||
| `modelValue` / `v-model` | `ColorValue \| null` | - | 受控接受值;ColorValue 为本库 Color 或颜色字符串 |
|
||||
| `value` | `ColorValue \| null` | - | 低优先级受控别名 |
|
||||
| `defaultValue` | `ColorValue \| null` | `null` | 非受控初始值,捕获一次 |
|
||||
| `channel` | `ColorChannel` | - | 未指定时编辑 Hex;否则编辑 hue/saturation/lightness/brightness/red/green/blue/alpha |
|
||||
| `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | 推断 | 通道使用空间,见下方说明 |
|
||||
| `fullWidth` | `boolean` | `false` | 根容器占满宽度 |
|
||||
| `isRequired` | `boolean` | `false` | 必填;原生或 ARIA 校验 |
|
||||
| `isInvalid` | `boolean` | `false` | 外部错误状态 |
|
||||
| `validate` | `(value: Color \| null) => ValidateResult` | - | 返回 true/null/undefined 表示有效,false/字符串/字符串数组表示无效 |
|
||||
| `validationBehavior` | `"native" \| "aria"` | `"native"` / Form | 原生约束阻止提交,或仅提供 ARIA 错误 |
|
||||
| `isDisabled` / `disabled` | `boolean` | `false` | 禁用;disabled 是本库别名 |
|
||||
| `isReadOnly` | `boolean` | `false` | 可聚焦、可选中,不能编辑 |
|
||||
| `isWheelDisabled` | `boolean` | `false` | 禁止滚轮调整 |
|
||||
| `name` / `form` | `string` | - | 原生提交名 / 外部表单 id |
|
||||
| `id` | `string` | 自动生成 | 分配给真实 Input;Input 自身 id 优先 |
|
||||
| `autoFocus` / `autoComplete` | `boolean` / `string` | `false` / `"off"` | 自动聚焦 / 原生自动完成 |
|
||||
| `locale` | `string` | ConfigProvider / en-US | 通道数字与单位格式 |
|
||||
| `as` | `string` | `"div"` | 更换根标签;传入 data-*、class、原生属性支持自定义根元素 |
|
||||
| `style` / `styleFn` | `StyleValue` 或状态函数 / 状态函数 | - | styleFn 在 style 之后合并;class 使用 Vue class 绑定 |
|
||||
| `@update:modelValue` / `@change` | `(color: Color \| null) => void` | - | 提交颜色提案;父级可以拒绝;不支持 changeEnd |
|
||||
|
||||
`modelValue`(包括显式 null)优先于 `value`,受控值优先于 `defaultValue`。全部自身值属性省略时继承最近颜色 owner,这是本库组合扩展;显式 null 清空独立字段。父级拒绝提案后恢复接受值,并允许同一提案再次输入。
|
||||
|
||||
无通道时只接受 3/6 位 Hex,可省略 #,显示规范化大写 Hex;解析格式范围不等于字段文本格式范围。颜色解析错误按公共 parseColor 边界抛错。空文本提交 null,非法/不完整草稿失焦后恢复;Enter 提交草稿并保留原生表单提交,Esc 撤销草稿。IME 候选确认期间不提交;此处只有合成 composition 回归与桌面输入检查,不代表完整系统输入法验收。
|
||||
|
||||
通道模式使用现有通道解析:RGB 通道用 rgb、lightness 用 hsl、brightness 用 hsb;hue/saturation 在显式 rgb 时转 hsl,其他情况保留指定或接受值的 HSL/HSB 空间,alpha 保留原空间。与固定依赖可能要求显式空间不同,本库保留既有推断/纠正扩展;Props 分别约束 channel 和 colorSpace 的枚举,不额外声明二者判别联合。
|
||||
|
||||
通道文本显示本地化数值和单位:hue 带 °,百分比带 %。自然步长为 RGB/hue/百分比 1,alpha 模型步长 .01;输入按自然步长取整并按范围夹限。未编辑的格式化显示不会反写完整颜色精度。上/下方向键单步,Shift 或 PageUp/Down 使用通道页步长,Home/End 到边界;Hex 对应 24 位整数步长 1/10。获得焦点后纵向滚轮向下递增,向上递减;isWheelDisabled、禁用、只读和 preventDefault 阻止调整。
|
||||
|
||||
### 表单提交与验证
|
||||
|
||||
Hex 使用命名的可见文本 input:直接构造 `FormData` 会读到编辑中的原生草稿;通常 Enter/失焦先提交或恢复草稿,再由表单提交。此行为保留固定字段协议,不能把编辑中 FormData 称为接受颜色。通道模式只命名一个隐藏 input,提交接受通道数值:hue/RGB 为自然数值,saturation/lightness/brightness 和 alpha 为 0–1。通道显示与提交采用自然步长的舍入值,完整颜色对象仍保留未修改精度。
|
||||
|
||||
原生必填、validate、Form validationErrors、FieldError、外部 form 和 reset 复用共享字段设施;禁用字段不参与提交,只读保留提交。校验判断颜色接受值;单独读取 FormData 不会主动运行校验。受控 reset 不强制父级改变模型,会把实际 DOM 恢复为当前接受值;非受控 reset 恢复捕获初值。ColorField 不额外提交整个 owner 颜色,Picker 私有组合的完整颜色提交由 owner 负责。
|
||||
|
||||
### Composition Components
|
||||
|
||||
| Vue 部件 | 对应上游 | 属性与行为 |
|
||||
| -------------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `ColorFieldGroup` | ColorField.Group | 同 ColorInputGroup/ColorInputGroupRoot;variant primary(默认)/secondary、fullWidth、as、role、style/styleFn;空白点击聚焦 Input,交互前后缀保留焦点 |
|
||||
| `ColorFieldInput` | ColorField.Input | 同 ColorInputGroupInput;原生 input 属性、事件、class/style;Root 内绑定颜色草稿,不使用另一个文本 v-model |
|
||||
| `ColorFieldPrefix` | ColorField.Prefix | 同 ColorInputGroupPrefix;as 默认 div,其余原生属性与默认插槽 |
|
||||
| `ColorFieldSuffix` | ColorField.Suffix | 同 ColorInputGroupSuffix;as 默认 div,其余原生属性与默认插槽 |
|
||||
| `Label` / `Description` / `FieldError` | 同名组件 | 关联真实输入的 id、描述与错误;无需另建字段状态 |
|
||||
|
||||
一个 ColorField 支持一个 Input;重复挂载 Input 抛错。没有 Input 时根和内容仍可渲染,但没有可编辑/可聚焦的字段。普通 DOM/Fragment 和已知 Group 的插槽可预取输入元数据;未知组件包装不执行 setup/render 探测,其 Input 挂载后注册属性,异步包装应显式传入 Root 的 id/name/form 等公共属性。
|
||||
|
||||
ColorInputGroup 独立使用时是普通文本组(role=group);Input 可用字符串 v-model/defaultValue。字段内 Group 默认 role=presentation。Root 的 ARIA 和输入事件发给真实 Input,普通 data-*、class/style 发给根;Input 事件与 Root 事件合并,外部取消先于内部行为。原生事件遵循冒泡规则。`aria-label/labelledby/describedby/details`、Label 和动态辅助文本保留关联。可通过 ConfigProvider 的 dir 或 HTML dir 继承 RTL 布局。
|
||||
|
||||
### Render Props
|
||||
|
||||
| 插槽状态 | 类型 | 含义 |
|
||||
| -------------------------------------------------------- | --------------- | --------------------------------- |
|
||||
| `value` | `Color \| null` | 当前接受颜色 |
|
||||
| `isDisabled` / `isReadOnly` / `isRequired` / `isInvalid` | `boolean` | 实际字段状态 |
|
||||
| `isFocused` / `isFocusWithin` / `isFocusVisible` | `boolean` | 真实 Input/子元素焦点及焦点可见性 |
|
||||
| `validationErrors` | `string[]` | 当前可见错误 |
|
||||
|
||||
Group 默认插槽与 styleFn 提供 isDisabled/isInvalid/isFocusWithin/isHovered。Root 实例提供 `focus()`、`element`(真实 Input)与 `color`(接受值);Group 提供 element(根 DOM)与 focus(),Input 提供 element、focus()、select()。不暴露私有 owner、事务 token 或整个字段控制器。不提供 asChild;上游 render 换标签由 as/attrs 实现。
|
||||
|
||||
### Color Types
|
||||
|
||||
```ts
|
||||
import {
|
||||
parseColor,
|
||||
type Color,
|
||||
type ColorFieldProps,
|
||||
} from "@heroui-vue/components";
|
||||
const color: Color = parseColor("#3B82F6");
|
||||
const props: ColorFieldProps = { defaultValue: color, name: "color" };
|
||||
color.toString("hex");
|
||||
color.getChannelValue("red");
|
||||
```
|
||||
|
||||
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。ColorPicker/ColorSwatchPicker 尚未公开。
|
||||
|
||||
## ColorField.Group Styling
|
||||
|
||||
使用 `.hv-color-input-group`、`__input`、`__prefix`、`__suffix` 定制各节点;primary/secondary/full-width 修饰符与上游视觉数值一致。根容器为 `.hv-color-field`。Group 负责 hover/focus-within/invalid/disabled 的样式,Input 自身去掉默认边框和焦点轮廓;焦点环展示在 Group。状态必须写在实际匹配 CSS 的节点。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-color-input-group {
|
||||
border-radius: var(--radius-field);
|
||||
}
|
||||
.hv-color-input-group__input {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关组件
|
||||
|
||||
[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)。
|
||||
@@ -281,4 +281,4 @@ ColorSlider 实现 ARIA slider 模式,提供:
|
||||
|
||||
## 相关组件
|
||||
|
||||
本批次公开 ColorArea、ColorSwatch 与 ColorSlider。ColorField、ColorInputGroup、ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -152,4 +152,4 @@ ColorSwatch 组件使用以下 CSS 类([查看源码样式](https://github.com
|
||||
|
||||
## 相关组件
|
||||
|
||||
本批次公开 ColorArea 与 ColorSwatch。ColorField、ColorInputGroup、ColorPicker、ColorSlider 与 ColorSwatchPicker 仍为私有颜色协议,尚未提供公共页面。
|
||||
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#0485F7"));
|
||||
</script>
|
||||
<template>
|
||||
<ColorField class="w-[280px]" name="color" v-model="color">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch :color="color ?? undefined" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldSuffix,
|
||||
ColorSwatch,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#7F007F"));
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<p class="text-sm text-muted">分别编辑 HSL 通道:</p>
|
||||
<div class="flex gap-4">
|
||||
<ColorField
|
||||
channel="hue"
|
||||
class="w-[100px]"
|
||||
color-space="hsl"
|
||||
name="hue"
|
||||
v-model="color"
|
||||
>
|
||||
<Label>色相</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<ColorField
|
||||
channel="saturation"
|
||||
class="w-[100px]"
|
||||
color-space="hsl"
|
||||
name="saturation"
|
||||
v-model="color"
|
||||
>
|
||||
<Label>饱和度</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
<ColorFieldSuffix>
|
||||
<span class="text-sm text-muted">%</span>
|
||||
</ColorFieldSuffix>
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<ColorField
|
||||
channel="lightness"
|
||||
class="w-[100px]"
|
||||
color-space="hsl"
|
||||
name="lightness"
|
||||
v-model="color"
|
||||
>
|
||||
<Label>明度</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
<ColorFieldSuffix>
|
||||
<span class="text-sm text-muted">%</span>
|
||||
</ColorFieldSuffix>
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<ColorSwatch :color="color ?? undefined" size="md" />
|
||||
<span class="text-sm">
|
||||
当前:{{ color ? color.toString("hex") : "(空)" }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
Button,
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Description,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
const value = shallowRef<Color | null>(parseColor("#0485F7"));
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField class="w-[280px]" name="color" v-model="value">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch :color="value ?? undefined" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>
|
||||
当前值:{{ value ? value.toString("hex") : "(空)" }}
|
||||
</Description>
|
||||
</ColorField>
|
||||
<div class="flex gap-2">
|
||||
<Button variant="tertiary" @click="value = parseColor('#EF4444')">
|
||||
设为红色
|
||||
</Button>
|
||||
<Button variant="tertiary" @click="value = parseColor('#10B981')">
|
||||
设为绿色
|
||||
</Button>
|
||||
<Button variant="tertiary" @click="value = null">清空</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Description,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#6366F1"));
|
||||
</script>
|
||||
<template>
|
||||
<ColorField
|
||||
class="w-full max-w-xs gap-1.5"
|
||||
name="accent-color"
|
||||
v-model="color"
|
||||
>
|
||||
<Label class="font-medium text-foreground">强调色</Label>
|
||||
<Description>应用于按钮、链接和焦点环。</Description>
|
||||
<ColorFieldGroup
|
||||
class="rounded-xl bg-default shadow-none focus-within:ring-2 focus-within:ring-accent/15"
|
||||
variant="secondary"
|
||||
>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch class="rounded-md" :color="color ?? undefined" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput
|
||||
class="font-mono text-sm text-foreground placeholder:text-muted"
|
||||
/>
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField
|
||||
isDisabled
|
||||
class="w-[280px]"
|
||||
default-value="#0485F7"
|
||||
name="color"
|
||||
>
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>该颜色字段已禁用</Description>
|
||||
</ColorField>
|
||||
<ColorField isDisabled class="w-[280px]" name="color-empty">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput placeholder="#000000" />
|
||||
</ColorFieldGroup>
|
||||
<Description>该颜色字段已禁用</Description>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef, onBeforeUnmount } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
Button,
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Description,
|
||||
Form,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
const value = shallowRef<Color | null>(null);
|
||||
const isSubmitting = shallowRef(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
function handleSubmit() {
|
||||
if (!value.value || isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
timer = setTimeout(() => {
|
||||
console.log("已提交颜色:", { color: value.value?.toString("hex") });
|
||||
value.value = null;
|
||||
isSubmitting.value = false;
|
||||
}, 1500);
|
||||
}
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
</script>
|
||||
<template>
|
||||
<Form class="flex w-[280px] flex-col gap-4" @submit.prevent="handleSubmit">
|
||||
<ColorField
|
||||
fullWidth
|
||||
isRequired
|
||||
class="w-full"
|
||||
name="brand-color"
|
||||
v-model="value"
|
||||
>
|
||||
<Label>品牌色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch :color="value ?? undefined" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput placeholder="#000000" />
|
||||
</ColorFieldGroup>
|
||||
<Description>选择品牌主色</Description>
|
||||
</ColorField>
|
||||
<Button
|
||||
class="w-full"
|
||||
:is-disabled="!value"
|
||||
:is-pending="isSubmitting"
|
||||
type="submit"
|
||||
variant="primary"
|
||||
>
|
||||
{{ isSubmitting ? "保存中…" : "保存颜色" }}
|
||||
</Button>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="w-[400px] space-y-4">
|
||||
<ColorField fullWidth default-value="#10B981" name="color">
|
||||
<Label>品牌色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<ColorField fullWidth default-value="#8B5CF6" name="color-with-suffix">
|
||||
<Label>主题色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
FieldError,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField isInvalid isRequired class="w-[280px]" name="color">
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput placeholder="#000000" />
|
||||
</ColorFieldGroup>
|
||||
<FieldError>请输入有效的十六进制颜色</FieldError>
|
||||
</ColorField>
|
||||
<ColorField isInvalid class="w-[280px]" name="invalid-color">
|
||||
<Label>背景色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput default-value="not-a-color" />
|
||||
</ColorFieldGroup>
|
||||
<FieldError>颜色格式无效,请使用十六进制(例如 #FF5733)</FieldError>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Description,
|
||||
Label,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Surface class="w-[320px] p-4">
|
||||
<ColorField default-value="#3B82F6" name="color">
|
||||
<Label>主题色</Label>
|
||||
<ColorFieldGroup variant="secondary">
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>选择你的主题色</Description>
|
||||
</ColorField>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import type { Color } from "@heroui-vue/components";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorSwatch,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#0485F7"));
|
||||
</script>
|
||||
<template>
|
||||
<ColorField
|
||||
class="w-[280px]"
|
||||
name="color"
|
||||
as="div"
|
||||
data-custom="foo"
|
||||
v-slot="{ isFocused }"
|
||||
v-model="color"
|
||||
>
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup
|
||||
as="div"
|
||||
data-custom="foo"
|
||||
:data-field-focused="isFocused || undefined"
|
||||
>
|
||||
<ColorFieldPrefix>
|
||||
<ColorSwatch :color="color ?? undefined" size="xs" />
|
||||
</ColorFieldPrefix>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField isRequired class="w-[280px]" name="color">
|
||||
<Label>品牌色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput placeholder="#000000" />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<ColorField isRequired class="w-[280px]" name="theme-color">
|
||||
<Label>主题色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput placeholder="#000000" />
|
||||
</ColorFieldGroup>
|
||||
<Description>必填项</Description>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField class="w-[280px]" default-value="#0485F7" name="primary-color">
|
||||
<Label>主要变体</Label>
|
||||
<ColorFieldGroup variant="primary">
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<ColorField
|
||||
class="w-[280px]"
|
||||
default-value="#F43F5E"
|
||||
name="secondary-color"
|
||||
>
|
||||
<Label>次要变体</Label>
|
||||
<ColorFieldGroup variant="secondary">
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
Description,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorField class="w-[280px]" default-value="#3B82F6" name="color">
|
||||
<Label>主色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>输入品牌主色</Description>
|
||||
</ColorField>
|
||||
<ColorField class="w-[280px]" default-value="#F59E0B" name="accent-color">
|
||||
<Label>强调色</Label>
|
||||
<ColorFieldGroup>
|
||||
<ColorFieldInput />
|
||||
</ColorFieldGroup>
|
||||
<Description>用于高亮与行动按钮</Description>
|
||||
</ColorField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,14 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import ColorField from "../../../packages/vue/src/components/color-field/ColorField.vue";
|
||||
import ColorInputGroup from "../../../packages/vue/src/components/color-field/ColorInputGroup.vue";
|
||||
import ColorInputGroupInput from "../../../packages/vue/src/components/color-field/ColorInputGroupInput.vue";
|
||||
import Prefix from "../../../packages/vue/src/components/color-field/ColorInputGroupPrefix.vue";
|
||||
import Suffix from "../../../packages/vue/src/components/color-field/ColorInputGroupSuffix.vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorInputGroup,
|
||||
ColorInputGroupInput,
|
||||
ColorInputGroupPrefix as Prefix,
|
||||
ColorInputGroupSuffix as Suffix,
|
||||
parseColor,
|
||||
type Color,
|
||||
} from "@heroui-vue/components";
|
||||
import Picker from "../../../packages/vue/tests/fixtures/ColorPickerComposition.vue";
|
||||
import { parseColor } from "../../../packages/vue/src/components/color/value";
|
||||
import { Label, Description, FieldError, Button } from "@heroui-vue/components";
|
||||
const value = shallowRef(parseColor("#123456")),
|
||||
const rtl = shallowRef(false);
|
||||
const proposals = shallowRef(0);
|
||||
const value = shallowRef<Color | null>(parseColor("#123456")),
|
||||
submitted = shallowRef("尚未提交"),
|
||||
channelSubmitted = shallowRef("尚未提交");
|
||||
function submit(event: Event, channel = false) {
|
||||
@@ -20,11 +25,13 @@ function submit(event: Event, channel = false) {
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<main class="color-field-lab">
|
||||
<main class="color-field-lab" :dir="rtl ? 'rtl' : 'ltr'">
|
||||
<h1>颜色字段正式协议 · 内部验收</h1>
|
||||
<p>
|
||||
组合部件、原生关联、格式化通道、提交和共享颜色;公开导出与正式文档尚未接入。
|
||||
组合部件、原生关联、格式化通道、提交和共享颜色;本页通过公共导出验证正式字段;Picker
|
||||
保留内部组合夹具。
|
||||
</p>
|
||||
<Button @click="rtl = !rtl">切换 RTL</Button>
|
||||
<div class="color-field-grid">
|
||||
<section id="field-native">
|
||||
<h2>受控 Hex / 原生 Enter</h2>
|
||||
@@ -49,6 +56,25 @@ function submit(event: Event, channel = false) {
|
||||
<output>接受值:{{ value?.toString("hex") ?? "empty" }}</output>
|
||||
</form>
|
||||
</section>
|
||||
<section id="field-rejected">
|
||||
<h2>受控拒绝与重试</h2>
|
||||
<form @submit.prevent>
|
||||
<ColorField
|
||||
name="rejected"
|
||||
model-value="#123456"
|
||||
@change="proposals++"
|
||||
>
|
||||
<Label>拒绝颜色</Label>
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
<Button type="reset">重置拒绝字段</Button>
|
||||
<output>提案次数:{{ proposals }}</output>
|
||||
</form>
|
||||
<ColorField is-read-only default-value="#ABCDEF">
|
||||
<Label>只读颜色</Label>
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
</section>
|
||||
<section id="field-channel">
|
||||
<h2>百分数显示 / 小数提交</h2>
|
||||
<form @submit.prevent="submit($event, true)">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 已迁移(客户端) | ColorArea/ColorAreaRoot、ColorAreaThumb;showDots、colorSpace/RGB/HSL/HSB 与 18 个有序轴组合、共享 owner、受控拒绝、原生两轴提交/reset、locale/RTL、readOnly;7/7 基线例;Root render 映射 as/asChild,Thumb 映射 as,style 函数映射 styleFn;见 COLOR-AREA 结果 |
|
||||
| color-field | 私有组合协议已验证 | Root/Input及InputGroup前后缀、校验/关联、locale/草稿/IME/reset已验证;未公开包根、variants或正式13例,见COLOR-06。 |
|
||||
| color-field | 已迁移(客户端) | ColorField/Root、Group/Input/Prefix/Suffix 与共享 ColorInputGroup 家族、两套 variants;Hex/通道草稿、受控接受/拒绝、自然步长/locale、表单/校验/reset、焦点/ARIA、RTL;13/13 基线例;render→as/attrs,style函数→styleFn;Hex原生FormData可读取编辑草稿,见 COLOR-FIELD 结果;已合main |
|
||||
| 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 结果 |
|
||||
@@ -235,7 +235,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
|
||||
|
||||
## COLOR-06 颜色字段组合协议
|
||||
|
||||
ColorField/ColorInputGroup 内部 Root/Input/前后缀、校验/关联、独立文本组及正式字段显示/提交协议已验证;未公开包根、variants 或正式13例。通道字段以自然步长提交归一化数字,Hex 使用命名可见输入,完整接受颜色独立保留精度。原始底座修正和实际差异见 [COLOR-06](component-notes.md)。
|
||||
ColorField/ColorInputGroup 内部 Root/Input/前后缀、校验/关联、独立文本组及正式字段显示/提交协议已验证;未公开包根、variants 或正式13例。通道字段以自然步长提交归一化数字,Hex 使用命名可见输入,完整接受颜色独立保留精度。原始底座修正和实际差异见 [COLOR-06](component-notes.md)。其中 ColorField/InputGroup 已完成公共迁移并合入 main,含 variants 与13例,见 [COLOR-FIELD 结果](tasks/results/COLOR-FIELD.md)。
|
||||
|
||||
## COLOR-08 Picker 内部三部件
|
||||
|
||||
|
||||
+11
-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/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)
|
||||
|
||||
@@ -42,3 +42,13 @@ TimeField 复用 DateInputGroup 六部件和现有接受值/字段/Form 协议
|
||||
Time/CalendarDateTime/ZonedDateTime 保留值类型、日期、历法、zone 与未显示的精度。底座空模型事件会转换为 Time 并遗漏毫秒,适配层只将可编辑字段写回原值/placeholder,单一命名输入提交完整 ISO。min/max 比较本地时分秒(含毫秒),与底座按日期比较区分。Enter 通过共享字段的原生 form 触发 requestSubmit;真正 Segment 的取消事件先于底座执行。12 小时 hour 与 dayPeriod 的 ARIA 数值范围由时间适配层校正,时制/粒度/时区可见性更新后恢复到有效分段焦点。
|
||||
|
||||
React render 改 as/attrs,children 函数改作用域插槽;class/style 使用 Vue 绑定,Input 的 variant 放在 Group。没有扩展 Reka step API,没有声称继承全部 RAC props。整段本地化时间粘贴、系统 IME 与完整读屏/真机未验收;原生 ISO 输入边界有回归,不能等同于本地化分段粘贴。
|
||||
|
||||
## COLOR-FIELD(2026-10-27)
|
||||
|
||||
ColorField/ColorFieldRoot、ColorFieldGroup/Input/Prefix/Suffix 与共享 ColorInputGroup/Root/Input/Prefix/Suffix、Props/插槽/实例及 colorFieldVariants/colorInputGroupVariants 已公开,固定源中文 13 例全部迁移。只复用既有接受值、文本草稿和 field/Form 协议,没有另建颜色状态源;细节见 [组件文档](../apps/docs/components/color-field.md) 与 [结果](tasks/results/COLOR-FIELD.md)。
|
||||
|
||||
Hex 采用命名的可见文本 input,直接 FormData 能读取未提交草稿;Enter/blur 后提交或恢复到接受值。通道字段只命名隐藏数值 input,百分比和 alpha 采用 0–1 提交尺度;未编辑显示不反写完整颜色,提交值按自然步长舍入。接受值 null、受控拒绝重试、owner 继承和 reset 沿用既有协议。channel/colorSpace 保留独立枚举及空间推断/纠正扩展,不沿用 Slider 的判别联合。
|
||||
|
||||
补齐根 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 只有合成事件覆盖。
|
||||
|
||||
+4
-4
@@ -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 例。Field/InputGroup、Picker 组合协议仍有私有实现和回归夹具;ColorField/ColorPicker/ColorSwatchPicker尚未作为完整公共颜色家族发布。
|
||||
- 兼容矩阵目前85条(包含子部件与基础设施),文档有70个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
- 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个组件页面。矩阵中的“验证中”保留其原有限制,不升级为完整兼容。
|
||||
|
||||
## 尚未完成的公共家族
|
||||
|
||||
ColorField、ColorSwatchPicker、ColorPicker,共3项;已有私有内核不等于公共迁移完成。ColorInputGroup仍为私有协议;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收,ColorSlider 已随 COLOR-SLIDER 验收。
|
||||
ColorSwatchPicker、ColorPicker,共2项;已有私有内核不等于公共迁移完成。ColorField/ColorInputGroup 迁移结果见 [COLOR-FIELD](tasks/results/COLOR-FIELD.md),已合入 main;Color/parseColor公共边界已随COLOR-SWATCH验收,ColorArea 已随 COLOR-AREA 验收,ColorSlider 已随 COLOR-SLIDER 验收。
|
||||
|
||||
TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/TIME-FIELD.md);COLOR-SWATCH 见 [结果](tasks/results/COLOR-SWATCH.md),COLOR-AREA 见 [结果](tasks/results/COLOR-AREA.md),COLOR-SLIDER 见 [结果](tasks/results/COLOR-SLIDER.md)。RANGE-CALENDAR 结果见 [任务结果](tasks/results/RANGE-CALENDAR.md)。DATE-RANGE-PICKER 结果见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。后续由用户选择一项,在实际前置具备后创建任务卡;不自动并行推进。
|
||||
|
||||
@@ -22,7 +22,7 @@ TIME-FIELD 已完成公共迁移和客户端验收,见 [结果](tasks/results/
|
||||
|
||||
唯一Vue工作目录heroui-vue,一任务一分支、会话串行。b01/b02/b03已删除并解除Git登记;core内容已整合,是否保留该目录不影响运行。开发默认文档5173,playground按实际脚本;服务只在任务需要时启动,结束按用户要求停止。
|
||||
|
||||
已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前客户端全量回归101文件/1487项通过;本轮ColorSlider新增2文件/42项,任务定向13文件/205项通过;已通过独立复核并按用户授权合入 main,结果见任务文件。ColorArea 已通过独立复核并合入 main;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。
|
||||
已完成的单目录整合见 [结果](tasks/results/WORKSPACE-CONSOLIDATION.md)。当前 ColorField 全量客户端回归103文件/1517项、定向13文件/206项通过,新增2文件/30项;typecheck、文档构建与最终tarball八契约通过;由主会话独立实施和自测,未委派其他AI,已按用户授权合入main;本次同时授权推送origin/main,远端同步以git状态为准。此前ColorSlider已通过独立复核并按用户授权合入main。ColorArea 已通过独立复核并合入 main;SSR历史用例已删除。逐像素自动对比、完整读屏矩阵、真机矩阵及Nuxt集成暂不投入。维护清理的实际结果见 [MAINTENANCE](tasks/results/MAINTENANCE.md)。
|
||||
|
||||
## 按需入口
|
||||
|
||||
|
||||
+8
-11
@@ -1,15 +1,12 @@
|
||||
# 当前工作区交接
|
||||
|
||||
- 任务:COLOR-SLIDER 已通过独立复核并按用户授权合入 main,CS-R1/CS-R2/CS-R1b 已闭环;状态 accepted,无进行中任务;结果见 `docs/tasks/results/COLOR-SLIDER.md`。
|
||||
- 任务:COLOR-FIELD 已完成,用户已授权合入 main 并推送 origin/main;状态 accepted,无进行中任务。
|
||||
- 工作区/分支:heroui-vue / `main`。
|
||||
- 起点:`e487bcc8ecb18eb8b368fe232f8e83d3d38d291c`(含 COLOR-SLIDER 任务卡与 README 入口;父提交 `8a4e9f4` 为最低基线并含全部元数据前置)。
|
||||
- 实施提交:`ce6c43eb4752f1b244b70acbc384075aee8ec578`;补充测试提交:`d7dd2c2393a81f6a946c9d5518eaef6b66413984`;交付提交:`d96f501e3c26dd74deecaff6b54626984a135573`(本文件状态/结果提交;其后为补充测试与 SHA 记录提交)。
|
||||
- 复核修复提交:`ea881cbcf884771ba9a1505bad8a79053680d090`(CS-R1 SFC/公共组件判别联合、CS-R2 Thumb/Track 卸载清理与回归);`9f25bdb9edbefb4ff09d1e2d684a3ea153fe0af8`(CS-R1b 公共实例恢复 focus/color/element);复核记录提交:`b09a4b3`;合并提交:`8cf92a2c82938fa665054b6cd554abf62cb9b4ee`;用户已授权推送 origin/main,远端状态以 `git status -sb` 为准。
|
||||
- 验证:复核修复后全量 101 文件/1487 项、任务定向 13 文件/205 项、typecheck、build:docs、`check-package color-slider color-area color-swatch color-slider-foundation` 通过;真实 Chrome 5173 已检查 9 例、触摸捕获/取消/越界、键盘/Tab 焦点、浅深主题、RTL/垂直 RTL/受控拒绝/表单 reset,控制台无 warn/error。
|
||||
- 集成验证:合并后 `pnpm test` 101 文件/1487 项通过、`pnpm build:docs` 通过;本轮复核的 typecheck 与最终 tarball 四契约通过,未重复浏览器专项。
|
||||
- 复核问题:CS-R1、CS-R2 与 CS-R1b 已修复;实际模板/公共 props/实例类型正反例、Thumb/Track 条件卸载/重挂回归均已补齐。
|
||||
- 已知限制:固定源“无 value/defaultValue 抛错”保留并扩展 owner 继承;显式 null 按缺少值处理;省略 colorSpace 时私有通道内核会推断所需空间(固定源可能抛错);Output 默认文本使用 render 函数而非 children slot;`--track-background` 为可覆盖/可测试的额外内联变量;鼠标 pointer capture 不作为浏览器证据(鼠标捕获由 jsdom 覆盖,触屏捕获为真实浏览器);未做 SSR/逐像素/完整读屏/真机矩阵。
|
||||
- 预览:文档 5173,`/components/color-slider`;本轮启动的开发服务在验证后停止;playground 未启动。
|
||||
- 历史:DATE-RANGE-PICKER、DATE-PICKER、RANGE-CALENDAR、TIME-FIELD、COLOR-SWATCH、COLOR-AREA 已合入 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。
|
||||
|
||||
单目录串行;新会话先核对 git 状态和结果文件。支持范围统一见 AGENTS.md,不自动开始下一项任务。
|
||||
单目录串行;后续先检查实际git状态,不自动开始下一家族。
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<!-- task-metadata
|
||||
{
|
||||
"base": "1c943efe74cb6d1f4ef7ffa5a82bdf90f6f585ac",
|
||||
"upstream": "ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960",
|
||||
"status": "accepted",
|
||||
"requires": [
|
||||
"packages/vue/src/components/color/value.ts",
|
||||
"packages/vue/src/components/color/model.ts",
|
||||
"packages/vue/src/components/color/text.ts",
|
||||
"packages/vue/src/components/color-field/ColorField.vue",
|
||||
"packages/vue/src/components/color-field/useColorField.ts",
|
||||
"packages/vue/src/components/color-field/context.ts",
|
||||
"packages/vue/src/components/color-field/tree.ts",
|
||||
"packages/vue/src/components/color-field/ColorInputGroup.vue",
|
||||
"packages/vue/src/components/color-field/ColorInputGroupInput.vue",
|
||||
"packages/vue/src/components/color-field/ColorInputGroupPrefix.vue",
|
||||
"packages/vue/src/components/color-field/ColorInputGroupSuffix.vue",
|
||||
"packages/styles/components/color-field.css",
|
||||
"packages/styles/components/color-input-group.css",
|
||||
"tests/color-field-protocol.test.ts",
|
||||
"tests/color-input-foundation.test.ts",
|
||||
"tests/package/client-checks.json"
|
||||
],
|
||||
"sources": [
|
||||
"packages/react/src/components/color-field/index.ts",
|
||||
"packages/react/src/components/color-field/color-field.tsx",
|
||||
"packages/react/src/components/color-input-group/index.ts",
|
||||
"packages/react/src/components/color-input-group/color-input-group.tsx",
|
||||
"packages/react/tests/components/color-field/color-field.test.tsx",
|
||||
"packages/styles/components/color-field.css",
|
||||
"packages/styles/components/color-input-group.css",
|
||||
"packages/styles/src/components/color-field/color-field.styles.ts",
|
||||
"packages/styles/src/components/color-input-group/color-input-group.styles.ts",
|
||||
"apps/docs/content/docs/cn/react/components/(colors)/color-field.mdx",
|
||||
"apps/docs/src/demos/cn/color-field/index.ts",
|
||||
"apps/docs/src/demos/cn/color-field/basic.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/variants.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/on-surface.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/with-description.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/required.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/disabled.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/full-width.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/invalid.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/channel-editing.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/controlled.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/form-example.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/render-function.tsx",
|
||||
"apps/docs/src/demos/cn/color-field/custom-styles.tsx"
|
||||
],
|
||||
"checks": [
|
||||
"pnpm exec vitest run tests/color-field.test.ts tests/color-field-demos.test.ts tests/color-field-protocol.test.ts tests/color-input-foundation.test.ts tests/color-foundation.test.ts tests/color-area.test.ts tests/color-slider.test.ts tests/color-swatch.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-field color-field-protocol color-foundation color-picker-protocol color-slider-foundation color-area color-slider color-swatch"
|
||||
]
|
||||
}
|
||||
-->
|
||||
|
||||
# COLOR-FIELD:公共颜色输入框迁移
|
||||
|
||||
## 责任、目标与启动
|
||||
|
||||
本任务由当前主会话 AI 亲自迁移、编写文档、测试和浏览器验收,不委派子代理、不创建其他 AI 会话、不向其他会话派发实施。用户已于 2026-10-27 授权开始实施;完成前不代表通过验收。
|
||||
|
||||
选择 ColorField:Color/parseColor、ColorSwatch、ColorArea、ColorSlider 已公开,Field/InputGroup 已有私有实现,但仍缺公共导出、完整公共契约与固定源正式 13 例。先补齐文本编辑与表单边界,再推进 ColorPicker 的公开组合。ColorSwatchPicker 是独立选择集合任务,不混入本项。
|
||||
|
||||
1. 实施前读 AGENTS.md、tasks/README.md、ACTIVE.md、tests/README.md 和本卡;核对分支、HEAD、未提交内容和占用。规划时工作区干净、main HEAD 为元数据 base。
|
||||
2. 卡和 README 入口需先进入提交;从包含本卡和前置的实际提交建立 `feat/color-field-public`,记录完整起点 SHA。base 是最低祖先,不是已包含本卡的启动提交。规划阶段未切分支/占用;用户已授权实施,从含卡提交建立任务分支。完成后提交到该分支,不合 main、不 push。
|
||||
3. 运行 `node scripts/task-check.mjs COLOR-FIELD`;实施启动后才更新占用和状态。只在 heroui-vue 串行执行,不自动创建 clone/worktree。缺依赖显式 `pnpm install --frozen-lockfile`。
|
||||
4. 用 `git show <upstream>:<path>` 阅读全部 sources;核对固定版本继承的实际字段/数值能力,不能只按中文简表实现。参考仓库只读;构建保持独立。
|
||||
5. 阅读颜色和 field-form 决策、当前私有内核及测试;建立“固定源 API → Vue API → DOM/提交/状态 → 验证证据”映射。旧文档中的未公开记录以实际导出及最新结果为准。
|
||||
|
||||
## 公共范围与实施顺序
|
||||
|
||||
### 一、确定公开契约并打通 basic
|
||||
|
||||
- 导出 ColorField/ColorFieldRoot;ColorFieldGroup/Input/Prefix/Suffix 作为共享部件的具名别名,配套公开 ColorInputGroup/ColorInputGroupRoot/Input/Prefix/Suffix。各 Props、实际插槽/实例类型,以及 colorFieldVariants/colorInputGroupVariants 和类型一并交付。别名共用同一实现,不新造一套状态或 DOM。
|
||||
- 复用已有 Color、字段/Form 和共享 owner。明确 modelValue/value/defaultValue 优先级、null/空输入、属性省略时继承 owner、显式自身值覆盖,以及动态归属切换;草稿、提案与接受颜色分开,父拒绝后显示/预览/原生提交保持接受值,同一输入可再次提案。
|
||||
- 无 channel 编辑 Hex;有 channel 编辑对应颜色通道。逐项审计 channel/colorSpace 的默认、推断、非法组合、步长、范围、精度、locale 和提交尺度。不得照搬 Slider 的规则代替字段规则。必要约束同时验证实际 SFC、公共 Props 与发布类型。
|
||||
- basic 必须先完成 Label → Group → Prefix/Swatch → Input、Description/FieldError 的完整公开组合;确认编辑/提交/焦点/样式闭环后再补所有示例。
|
||||
|
||||
### 二、核销文本、通道与表单交互
|
||||
|
||||
- 覆盖编辑中间态、非法草稿、清空、Enter/blur 提交、Esc、粘贴、IME composition、外部值更新与 reset;未编辑的格式化显示不反写、不量化完整接受颜色,编辑一个通道保留其他通道与 alpha/灰色色相。
|
||||
- 通道模式验证方向键、PageUp/Down、Home/End 等固定版本实际支持的按键、步长、滚轮/isWheelDisabled、焦点和取消顺序;不额外承诺不存在的键盘功能。
|
||||
- name/form、required、isDisabled/isReadOnly、isInvalid、validate、validationBehavior 与 Form 错误关联复用现有协议。Hex 命名输入、通道数值提交和 alpha 尺度按固定运行时审计后明确记录;Hex 的原生命名文本输入允许 FormData 读取草稿(沿用既有协议);Enter/blur 后按接受值提交,文档不得将编辑期 FormData 称作接受颜色。通道提交只取接受数值。
|
||||
- 真实 FormData、外部 form、原生约束阻止提交、Enter 提交、reset/受控拒绝后真实 input.value 恢复、禁用排除均需证据。继承 owner 时避免重复完整颜色提交及重复 reset 所有权。
|
||||
- 明确 Root/Input 的 attrs、ARIA、原生事件、class/style 和 ref/focus 归属;覆盖 aria-label/labelledby/describedby/details、动态 Label/Description/FieldError、事件 preventDefault、自动聚焦、交互前后缀及 Group 空白点击聚焦。不得执行未知子组件 setup/render 来探测 Input。
|
||||
- 明确 Group 独立使用及缺少/重复 Input 的支持边界,沿用共享文本设施;React render/children/className/函数 style 转 as/asChild、作用域插槽、class/style/styleFn 时逐项说明,实例公开成员在发布声明中保留。
|
||||
- 在现有私有 Picker owner 下验证公共 Field/Area/Slider/Swatch 联动和受控拒绝;Picker 仍保持私有,本任务不提前公开 ColorPicker/ColorSwatchPicker。
|
||||
|
||||
### 三、迁移样式与全部文档
|
||||
|
||||
- 核对现有 hv-color-field/hv-color-input-group CSS 的来源、实际入口和状态节点,再适配 variants;保留 primary/secondary、fullWidth、Surface、前后缀、浅深主题、hover、focus-visible/focus-within、invalid、required、disabled、readonly、RTL 和适用 reduced-motion。
|
||||
- 新增 `/components/color-field`,标题“ColorField 颜色输入框”。按固定 mdx 顺序迁移 basic、variants、on-surface、with-description、required、disabled、full-width、invalid、channel-editing、controlled、form-example、render-function、custom-styles,共 13 例。文案/布局/默认值与基线一致,框架相关描述改为实际 Vue API。
|
||||
- 预览/复制/高亮共用同一 SFC,只用公共导出;render-function 例保留真实动态插槽。图标用官方 Tabler Vue。API/插槽/状态表沿用已有全宽布局。
|
||||
- 增量修改包根、样式导出、navigation.ts;新增公共行为/演示测试和 `tests/package/color-field-contract.ts`,登记 color-field 产物契约。旧 absent 列表只移除本次公开项,保留 Picker 私有边界。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
| 项目 | 验收条件 |
|
||||
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 公开使用 | 独立消费者从最终 tarball 导入全部部件、别名、类型和 variants;真实模板与实例 focus/element 类型可用,非法用法有类型反例 |
|
||||
| 值与草稿 | Hex/通道、接受/拒绝/重试、清空、IME、外部更新/切换 owner 不产生状态漂移;未编辑显示不损失颜色精度 |
|
||||
| 表单/校验 | 原生 FormData、required/validate、aria/native、Enter、reset、外部 form 与禁用排除符合记录的契约,无重复颜色提交 |
|
||||
| 组合/焦点 | Label 和辅助文本关联真实 Input;前后缀交互不被 Group 抢焦点;公共颜色部件共享 owner 正确,未公开家族不泄漏 |
|
||||
| 文档/视觉 | 13/13 固定示例可运行;Chrome 默认 5173 实查输入、键盘/Tab、滚轮、原生校验、浅深、Surface、错误、禁用、RTL、窄屏布局;记录操作与结论,非逐像素声明 |
|
||||
| 发布产物 | checks 所列定向测试、typecheck、build:docs、tarball ESM/CSS 及 bundler/NodeNext 类型正反例通过;共享修改补受影响字段回归 |
|
||||
|
||||
自动化命令唯一来源为头部 checks。新公共测试和 color-field 契约由实施新增,规划时尚不存在;不能省略后宣称通过。若改共享字段内核,按 tests/README.md 增加受影响使用者;集成时执行全量客户端回归。
|
||||
|
||||
真实浏览器先核对已有 5173 服务的目录和入口,不停止他人服务;启动或备用端口遵循 AGENTS.md。原生 IME/真机/读屏未实测的范围如实记录,合成 composition 回归不能充当系统输入法验收。
|
||||
|
||||
同步 compatibility/upstream/status/component-notes/verification 的本项事实,保留来源/Apache 声明;在 `docs/tasks/results/COLOR-FIELD.md` 按模板记录准确 SHA、API 映射、13 例核销、场景→证据和限制。既有过时事实只按实际证据纠正,其他家族不升级状态。
|
||||
|
||||
当前仅客户端,不开发、不运行 SSR/水合/Nuxt 服务端专项,不新增逐像素/完整读屏/真机矩阵工程。完成实施提交到本任务分支,未获授权不合 main、不 push。
|
||||
+12
-11
@@ -18,17 +18,18 @@
|
||||
|
||||
## 任务与元数据
|
||||
|
||||
| 卡 | 用途 |
|
||||
| ----------------------------------- | ------------------------------------ |
|
||||
| [COLOR-SWATCH](COLOR-SWATCH.md) | 公共颜色值/Swatch家族 |
|
||||
| [COLOR-AREA](COLOR-AREA.md) | 复用二维颜色内核的公共 ColorArea 迁移 |
|
||||
| [COLOR-SLIDER](COLOR-SLIDER.md) | 复用轨道/通道内核的公共颜色滑块与 9 例迁移 |
|
||||
| [TIME-FIELD](TIME-FIELD.md) | 复用日期/字段设施的时间字段 |
|
||||
| [RANGE-CALENDAR](RANGE-CALENDAR.md) | 公共范围日历客户端迁移 |
|
||||
| [DATE-PICKER](DATE-PICKER.md) | 复用日期/字段/弹层的公共日期选择器迁移 |
|
||||
| [DATE-RANGE-PICKER](DATE-RANGE-PICKER.md) | 复用范围日历、双端点字段与弹层的公共日期范围选择器迁移 |
|
||||
| [B02-REVIEW](B02-REVIEW.md) | 已验收公开组合的追溯入口,不自动重做 |
|
||||
| [MAINTENANCE](MAINTENANCE.md) | 本轮维护清理 |
|
||||
| 卡 | 用途 |
|
||||
| ----------------------------------------- | ----------------------------------------------------------- |
|
||||
| [COLOR-SWATCH](COLOR-SWATCH.md) | 公共颜色值/Swatch家族 |
|
||||
| [COLOR-AREA](COLOR-AREA.md) | 复用二维颜色内核的公共 ColorArea 迁移 |
|
||||
| [COLOR-SLIDER](COLOR-SLIDER.md) | 复用轨道/通道内核的公共颜色滑块与 9 例迁移 |
|
||||
| [COLOR-FIELD](COLOR-FIELD.md) | 当前主会话亲自迁移颜色字段及配套 InputGroup,含固定源 13 例 |
|
||||
| [TIME-FIELD](TIME-FIELD.md) | 复用日期/字段设施的时间字段 |
|
||||
| [RANGE-CALENDAR](RANGE-CALENDAR.md) | 公共范围日历客户端迁移 |
|
||||
| [DATE-PICKER](DATE-PICKER.md) | 复用日期/字段/弹层的公共日期选择器迁移 |
|
||||
| [DATE-RANGE-PICKER](DATE-RANGE-PICKER.md) | 复用范围日历、双端点字段与弹层的公共日期范围选择器迁移 |
|
||||
| [B02-REVIEW](B02-REVIEW.md) | 已验收公开组合的追溯入口,不自动重做 |
|
||||
| [MAINTENANCE](MAINTENANCE.md) | 本轮维护清理 |
|
||||
|
||||
每张卡顶部JSON头部注释(task-metadata)是base/upstream/status/requires/sources/checks的唯一来源;不另维护tasks.json或手写状态表。状态只在卡中更新。ACTIVE.md只记当前任务、分支、起点与接续入口;结果只记改动、证据和遗留事项。
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# COLOR-FIELD 交付 / 接续
|
||||
|
||||
- 分支:`feat/color-field-public`。
|
||||
- 起点:`108a120c81ac53c6a273422a1bb88cb5cfaec9e6`(含任务卡及全部前置;最低祖先 `1c943efe74cb6d1f4ef7ffa5a82bdf90f6f585ac`)。
|
||||
- 实施提交:`6a7a89be6b5b94e7d8a0778886453832f29d41f9`。
|
||||
- 固定源:HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。
|
||||
- 责任:当前主会话亲自完成源码、文档、测试与浏览器验收;未委派子代理/其他 AI,未创建或消息派发其他会话。实施交付时未合 main、未 push;用户随后授权合并与推送,见下方集成记录。这是实施自测记录,不声称独立复核。
|
||||
|
||||
## 改动与 API 映射
|
||||
|
||||
复用既有 color/model/text/channel、choice/field/Form 内核及 CSS,公开 ColorField 家族及共享 ColorInputGroup 部件;没有新增依赖、第二颜色状态源或 React 运行时。
|
||||
|
||||
| 固定源 / 能力 | Vue 公共 API / 实际 DOM | 验证位置 |
|
||||
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |
|
||||
| ColorField / Root | ColorField/ColorFieldRoot 同一组件;modelValue/value/defaultValue,空值为 null,输出本库 Color/null | color-field.test、原25项field-protocol、tarball契约 |
|
||||
| ColorField.Group/Input/Prefix/Suffix | ColorFieldGroup/Input/Prefix/Suffix 是 ColorInputGroup/Root/Input/Prefix/Suffix 对应别名,保持 color-input-group data-slot 与 hv BEM | 公共/演示测试、check-client别名断言、浏览器几何 |
|
||||
| variants / fullWidth / primary/secondary | colorFieldVariants、colorInputGroupVariants 及类型;保持源尺寸/间距/圆角/阴影 | tarball variants/CSS,13例及浅深浏览器 |
|
||||
| Hex / channel / colorSpace | 无channel为3/6位Hex草稿;有channel为本地化数值,按自然步长提交;完整接受颜色不由未编辑格式化显示反写 | input-foundation、field-protocol、HSL演示测试 |
|
||||
| value / onChange | v-model/update:modelValue、change 提案;受控拒绝恢复接受值且允许重试 | public/protocol及真实拒绝两次abc场景 |
|
||||
| required / validate / validationBehavior / name / form | 复用共享字段与原生可见input/通道隐藏input;外部form、reset、disabled/readOnly、Form错误关联 | field-protocol、真实required/reset/FormData |
|
||||
| ARIA / 标签 / 原生事件 | Root全部ARIA(补齐aria-details)及输入事件到真实Input;Label/Description/FieldError关联;其余attrs到根;取消先于编辑行为 | 公共ARIA动态测试、protocol事件次数/取消、浏览器错误焦点 |
|
||||
| children/render/className/style | Vue作用域插槽、as/attrs、class/style与styleFn;Root与Group可计算样式,实例保留focus/element,Root有color,Input有select | live slot/style测试、实际SFC类型夹具、发布实例契约 |
|
||||
|
||||
### 明确边界
|
||||
|
||||
- Hex 使用命名的可见文本 input,直接读取 FormData 会读到编辑中草稿;Enter/blur 后先提交或恢复。保留既有字段协议,未把草稿声称为接受颜色。通道使用一个隐藏命名input,只提交通道接受数值;百分比/alpha为0–1,提交精度按自然步长舍入。私有 Picker 的整颜色提交仍由 owner 负责。
|
||||
- 省略全部自身值属性时继承最近 owner,显式值覆盖;modelValue(含null)优先于value,非受控defaultValue捕获一次。继承、接受/拒绝、reset不另建状态。
|
||||
- channel/colorSpace 沿用既有字段的空间推断/纠正;分别约束枚举,不声称具有Slider的判别联合。推断及显式冲突的纠正属于保留扩展,与固定依赖可能要求显式空间不同。
|
||||
- 一个Root只支持一个Input;重复挂载抛错;无Input没有编辑/焦点能力。普通DOM/Fragment/已知Group插槽可预取元数据,未知包装仅在真实挂载后注册;不探测执行其setup/render。Root内Input的字符串v-model/defaultValue不作为另一颜色源;这些属性用于独立文本组。
|
||||
- render换标签用as/attrs,不提供asChild;children函数用作用域插槽,函数style可用styleFn。Root element是实际Input;Group element是组根。未暴露私有state/token。
|
||||
- 唯一CSS数值适配:ColorInputGroupInput加min-width:0。修正前100px通道组的原生Input约201.5–205.5px,后缀越界;修正后hue输入100px、百分比输入74.25px,后缀留在100px组内。其余固定源CSS数值不变;Apache声明保留。
|
||||
|
||||
## 13 个基线示例核销
|
||||
|
||||
入口 `/components/color-field`,实际21个字段。每例预览、复制与高亮使用同一SFC,只用公共导出;顺序与固定中文mdx一致。
|
||||
|
||||
| 示例 | 核销结果 |
|
||||
| ---------------- | ------------------------------------------------------------------------------- |
|
||||
| basic | #0485F7初值、Label/Prefix/Swatch;编辑22c55e失焦后#22C55E,预览rgb(34,197,94) |
|
||||
| variants | primary/secondary与两种基线颜色,真实修饰类 |
|
||||
| on-surface | Surface内secondary,主题色/描述一致 |
|
||||
| with-description | 两组基线标签、颜色和描述,关联真实input |
|
||||
| required | 两个必填空字段,placeholder与必填标记 |
|
||||
| disabled | 有值/空值两组均为原生disabled且说明存在 |
|
||||
| full-width | 两组fullWidth与400px固定基线演示容器 |
|
||||
| invalid | 两个错误状态及固定文案,aria-invalid关联 |
|
||||
| channel-editing | 三个100px HSL字段共享Color;hue90后另两通道100%/25%,色块/Hex同步;后缀几何修正 |
|
||||
| controlled | 红/绿/清空按钮同步input、Swatch与描述 |
|
||||
| form-example | 空值按钮禁用;颜色提交后“保存中…”并于1500ms后清空;加定时器卸载清理 |
|
||||
| render-function | as=div/data-custom=foo;实际作用域插槽根据isFocused更新Group属性 |
|
||||
| custom-styles | 基线secondary、圆角、字体、描述与色块类名保留 |
|
||||
|
||||
自动演示测试逐例检查Label指向Input,并验证实际编辑/联动/提交,不以文件数或HTML非空替代交互。无图标新增。
|
||||
|
||||
## 场景 → 证据
|
||||
|
||||
| 场景 | 复现/断言与实际结果 |
|
||||
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 公共API / Props / 实例 | `tests/color-field.test.ts` 10项;`tests/package/color-field-contract.ts`涵盖实际h()/Props的合法/非法模型、通道、空间、variant、validator及focus/element/color/select;`packages/vue/tests/fixtures/ColorFieldTypeContract.vue`含实际模板正反例和template ref |
|
||||
| 私有协议到公共回归 | 原field-protocol改从包根导入,25项断言保留;native事件取消/动态name/form/id/Label/Description/错误、受控reset、IME、输入替换均有回归;颜色共用内核未另行改写 |
|
||||
| 定向 | 任务checks的Vitest命令13文件/206项通过,见临时日志或直接按卡复现;含Area/Slider/Swatch/Picker和regressions/color |
|
||||
| 全量 | `pnpm test`:103文件/1517项通过(原1487项+本轮30项);无skip/排除新增 |
|
||||
| 类型 / 构建 | `pnpm typecheck`、`pnpm build:docs`通过;保留既有大chunk提示;构建不是组件SSR验收 |
|
||||
| 最终tarball | 任务卡八契约check-package通过,独立目录 `.../T/heroui-client-package-AwB8rj`;实际ESM/CSS/别名/variants、strict NodeNext/bundler正反类型,无源码alias;日志 `/private/tmp/color-field-package-final.log` |
|
||||
| 浏览器文档核心 | IAB真实浏览器,5173 `/components/color-field`,浅/深主题均检查;13预览/21字段、basic编辑失焦、Swatch同步、HSL90/91与色块联动、控件实际可点击/聚焦;输入组36px高、12px圆角,焦点环计算2px |
|
||||
| 浏览器几何 / 窄屏 | 100px通道组后缀不越界;390×844下页面scrollWidth=390、三张API表均350px,无横向拖动;1280×900检查桌面导航/通道布局。修正一处正文长导出名称连写导致的溢出,分别格式化名称后恢复正常 |
|
||||
| 受控拒绝 / 重试 / reset | 5174 `?color-field-protocol`(现有Lab改公共导入);拒绝颜色输入abc+Enter两次,提案次数2,input仍#123456;编辑#12后点重置,仍#123456 |
|
||||
| 原生校验 / Enter | 同页点击“校验”,空必填invalid=true/valid=false,焦点回真实input,aria-describedby含错误id,显示“请选择颜色。”;reset恢复Description并清除错误。品牌颜色输入aabbcc+Enter实际提交 `[["hex","#AABBCC"]]`;正式文档表单Enter出现“保存中…”后清空 |
|
||||
| 滚轮 / 提交 / 只读 / RTL | Lab饱和度50%聚焦后真实纵向滚轮变51%,提交得到 `[["saturation","0.51"]]`;只读#ABCDEF在ArrowUp后保持;切换RTL后main.dir和组计算direction均rtl |
|
||||
| 浏览器控制台 | 文档与Lab检查无warn/error;主题恢复到验前“跟随系统”,临时视口恢复默认 |
|
||||
|
||||
首次离线消费安装因TypeScript缓存缺包失败,随后联网运行成功;该环境失败没有记为通过。全量测试首次发现演示焦点测试在初始化元数据/refs稳定前抢先focus,测试改为等待挂载更新后再执行原生focus;没有删除或弱化原断言,随后全量通过。
|
||||
|
||||
## 交付与限制
|
||||
|
||||
文档5173为本任务启动,保留供用户预览;playground5174仅用于回归,验后停止。桌面截图临时证据:`/private/tmp/color-field-desktop.jpg`(深色通道与真实焦点环),另保存到本聊天visualizations目录;截图不是逐像素结论。
|
||||
|
||||
已完成本卡客户端实施与自测,无待补的本卡功能。ColorPicker/ColorSwatchPicker未公开;实施时未执行独立复核/合main/push;用户后续已授权合并与推送,集成记录见下。系统IME未完整验收,composition仅合成事件覆盖;不宣称真机、全读屏或自动逐像素通过。SSR/水合/Nuxt服务端不支持、不开发、不运行。
|
||||
|
||||
## 用户授权集成(2026-10-27)
|
||||
|
||||
用户明确要求“合了推送”。拉取 origin 后确认远端 main 为本任务祖先,工作区干净;无冲突合入 main,合并提交 `ec350c5f4e92d7dc7c9ccdc7e3e3ae9bfa231170`。
|
||||
|
||||
- 集成回归首次发现 ColorArea/ColorSlider 的既有文档检查要求保留“仍为私有颜色协议”措辞。将相关组件页的这句话明确限定为 ColorPicker/ColorSwatchPicker;ColorField 仍准确标为已公开,没有删改测试断言。
|
||||
- 修正后 `pnpm test`:103 文件/1517 项全部通过;`pnpm build:docs` 通过(保留已有大 chunk 提示)。只改文档措辞和集成状态,沿用实施时已通过的类型及最终 tarball 八契约,不重复浏览器专项。
|
||||
- 任务由用户授权集成,状态 accepted;没有追加其他 AI 或独立复核。用户已授权推送 origin/main,实际远端同步以最终 git status / 远端 SHA 确认为准。
|
||||
@@ -298,3 +298,9 @@ DatePicker CSS/variants 仅加 hv- 前缀,弹层 origin/placement 与进入退
|
||||
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/date-range-picker/{index.ts,date-range-picker.tsx}`、`packages/styles/components/date-range-picker.css`、`packages/styles/src/components/date-range-picker/date-range-picker.styles.ts`、中文 `(date-and-time)/date-range-picker.mdx` 与 `apps/docs/src/demos/cn/date-range-picker/` 全部 10 个页面预览;`index.ts` 额外导出的 release-input-container 中文页未引用,按非页面示例核对。同时对照 React Aria Components 1.21.1 发布的 DateRangePicker/DateRangeField/useDateRangePickerState 声明确认完整范围、时间范围与 `shouldCloseOnSelect` 语义,未安装或执行 React。
|
||||
|
||||
CSS/variants 仅加 hv- 前缀并保留 Apache-2.0 来源;弹层 origin/placement 与进入退出状态映射到 Reka,默认日历图标取自上游 `icons.tsx` 的 IconCalendar。Vue 侧复用既有接受值/字段/范围选择/日历视图/弹层设施:从 DateField owner 抽取双端点字段适配,RangeCalendar 增加可选继承接口;没有复制第二套范围状态或另一个接受值。固定源 `slot="start"/"end"` 改为 `DateFieldInput endpoint`;格式选项的 `w-full` 弹层在 Portal 自动宽度下映射为日历宽度加内边距。无新增依赖,构建不依赖相邻 React 仓库;差异、宽度适配和验证见 [组件文档](../apps/docs/components/date-range-picker.md) 与 [结果](tasks/results/DATE-RANGE-PICKER.md)。
|
||||
|
||||
## COLOR-FIELD 公共迁移(2026-10-27)
|
||||
|
||||
固定 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 暴露。
|
||||
|
||||
@@ -87,3 +87,17 @@ CDP 合成鼠标事件本身不保持 pointer capture(中性 div 复现),
|
||||
临时 RTL/受控拒绝/表单页面(同一开发服务器,验后删除)实测:RTL 初始 Thumb `left:100%`、背景 `to left`,点击 25% 得 270°、ArrowRight 降至 269°;垂直 RTL 初始 `top:100%`,点击顶部 25% 得 270°/`top:25%`;受控父级忽略两次提案后 input/Output/Thumb 均保持 0;表单提交 `hue=90`,reset 后 input 与 Output 恢复 30°/30°。未开展 SSR/水合/Nuxt、逐像素、完整读屏或真机矩阵;详情见 [任务结果](tasks/results/COLOR-SLIDER.md)。
|
||||
|
||||
复核 P2 修复:根组件判别联合通过 `component-type.ts` 的公共组件类型覆盖实际 SFC(模板 `@vue-expect-error` 正反例、tarball `$props`/`h()` 反例),末尾构造签名保留 `ColorSliderExpose` 的 `element`/`color`/`focus`,发布契约和模板 ref 正例覆盖;Thumb/Track 在条件卸载时按所有权清理共享元素并触发取消/释放捕获,新增仅 Thumb 与 Track 卸载/重挂回归。修复后任务定向 13 文件/205 项、全量 101 文件/1487 项、typecheck、build:docs 与四契约 tarball 检查通过。
|
||||
|
||||
## COLOR-FIELD(2026-10-27)
|
||||
|
||||
ColorField/Root、共享 InputGroup 与字段具名别名、公共 Props/slots/expose、两套 variants 和固定源中文 13 例完成。由主会话亲自实施与自测,未委派其他 AI;已按用户授权合入 main,不宣称独立复核。
|
||||
|
||||
- 全量 `pnpm test`:103 文件/1517 项通过;任务定向 13 文件/206 项通过;新增公共/演示 2 文件/30 项。
|
||||
- `pnpm typecheck`:通过,含实际 Vue 模板正反例及 template ref 实例成员;`pnpm build:docs` 通过,已有大 chunk 提示保留。
|
||||
- `check-package`:color-field、color-field-protocol、color-foundation、color-picker-protocol、color-slider-foundation、color-area、color-slider、color-swatch 八契约最终 tarball 的独立安装、ESM/CSS/别名/variants、strict NodeNext/bundler 类型正反例通过。初次离线因 TypeScript 缓存缺包失败,随后联网成功,不把失败记为通过。
|
||||
- 真实 IAB 浏览器:文档 5173 共21个实际字段/13个预览;Hex 编辑/失焦/色块同步,HSL联动与键盘,浅深/禁用/错误/焦点环;100px 通道组 Input 修正后为100px/74.25px,百分比后缀留在组内。390px 页面 scrollWidth=390、三张表均350px,无横向拖动;1280×900 桌面布局检查通过。
|
||||
- 现有 playground 5174 `?color-field-protocol` 改用公共导出:拒绝两次 abc 后提案次数2且显示#123456、reset恢复;原生required阻止提交并显示“请选择颜色。”,焦点回输入且ARIA包含错误ID,reset恢复Description;真实纵向滚轮50%→51%,提交 saturation=0.51;Enter提交hex=#AABBCC;readonly不变、dir继承rtl。控制台无warn/error。
|
||||
|
||||
完整 API 映射、13例核销、复现与边界见 [COLOR-FIELD 结果](tasks/results/COLOR-FIELD.md)。未执行SSR/水合/Nuxt服务端、逐像素/完整读屏/真机矩阵;系统IME未完整验收。
|
||||
|
||||
COLOR-FIELD 集成:用户于2026-10-27授权合并与推送,合并SHA `ec350c5f4e92d7dc7c9ccdc7e3e3ae9bfa231170`。集成后相关组件页明确仅Picker家族仍为私有颜色协议,保留既有文档断言;全量103文件/1517项、文档构建通过。未重复无变化的类型/tarball/浏览器专项。
|
||||
|
||||
@@ -53,7 +53,8 @@
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-input-group__input {
|
||||
@apply flex h-full flex-1 cursor-text items-center rounded-none border-0 bg-transparent px-3 py-2 text-base shadow-none outline-none sm:text-sm;
|
||||
/* Vue native input has a browser intrinsic minimum width; keep narrow channel inputs and affixes inside the group. */
|
||||
@apply flex min-w-0 h-full flex-1 cursor-text items-center rounded-none border-0 bg-transparent px-3 py-2 text-base shadow-none outline-none sm:text-sm;
|
||||
|
||||
/* Placeholder styling */
|
||||
&::placeholder {
|
||||
|
||||
@@ -1902,3 +1902,33 @@ export const rangeCalendarVariants = tv({
|
||||
});
|
||||
|
||||
export type RangeCalendarVariants = VariantProps<typeof rangeCalendarVariants>;
|
||||
|
||||
/** HeroUI 3.2.6 / ce90ea3, Apache-2.0; hv namespace only. */
|
||||
export const colorFieldVariants = tv({
|
||||
base: "hv-color-field",
|
||||
defaultVariants: { fullWidth: false },
|
||||
variants: { fullWidth: { false: "", true: "hv-color-field--full-width" } },
|
||||
});
|
||||
export type ColorFieldVariants = VariantProps<typeof colorFieldVariants>;
|
||||
export const colorInputGroupVariants = tv({
|
||||
defaultVariants: { fullWidth: false, variant: "primary" },
|
||||
slots: {
|
||||
base: "hv-color-input-group",
|
||||
input: "hv-color-input-group__input",
|
||||
prefix: "hv-color-input-group__prefix",
|
||||
suffix: "hv-color-input-group__suffix",
|
||||
},
|
||||
variants: {
|
||||
fullWidth: {
|
||||
false: {},
|
||||
true: { base: "hv-color-input-group--full-width" },
|
||||
},
|
||||
variant: {
|
||||
primary: { base: "hv-color-input-group--primary" },
|
||||
secondary: { base: "hv-color-input-group--secondary" },
|
||||
},
|
||||
},
|
||||
});
|
||||
export type ColorInputGroupVariants = VariantProps<
|
||||
typeof colorInputGroupVariants
|
||||
>;
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type VNodeChild,
|
||||
type VNode,
|
||||
} from "vue";
|
||||
import { colorFieldVariants } from "@heroui-vue/styles";
|
||||
import { useColorField } from "./useColorField";
|
||||
import type { ColorFieldProps, ColorFieldRenderState } from "./context";
|
||||
import type { Color } from "../color/value";
|
||||
@@ -45,6 +46,10 @@ const rendered = defineComponent({
|
||||
props: ["nodes"],
|
||||
setup: (p) => () => p.nodes as VNodeChild,
|
||||
});
|
||||
const ordinaryStyle = computed(() =>
|
||||
typeof props.style === "function" ? props.style(state.value) : props.style,
|
||||
);
|
||||
const computedStyle = computed(() => props.styleFn?.(state.value));
|
||||
const nativeEvents = new Set([
|
||||
"aria-label",
|
||||
"aria-labelledby",
|
||||
@@ -66,7 +71,9 @@ const nativeEvents = new Set([
|
||||
]);
|
||||
const rootAttrs = () =>
|
||||
Object.fromEntries(
|
||||
Object.entries(attrs).filter(([key]) => !nativeEvents.has(key)),
|
||||
Object.entries(attrs).filter(
|
||||
([key]) => !key.startsWith("aria-") && !nativeEvents.has(key),
|
||||
),
|
||||
);
|
||||
function focusin(event: FocusEvent) {
|
||||
focusWithin.value = true;
|
||||
@@ -83,6 +90,7 @@ function focusout(event: FocusEvent) {
|
||||
defineExpose({
|
||||
focus: () => control.input.value?.focus(),
|
||||
element: control.input,
|
||||
color: control.state.value,
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
@@ -90,13 +98,16 @@ defineExpose({
|
||||
:is="as"
|
||||
ref="root"
|
||||
v-bind="rootAttrs()"
|
||||
class="hv-color-field"
|
||||
:class="{ 'hv-color-field--full-width': fullWidth }"
|
||||
:class="colorFieldVariants({ fullWidth })"
|
||||
:style="[ordinaryStyle, computedStyle]"
|
||||
data-slot="color-field"
|
||||
:data-channel="channel ?? 'hex'"
|
||||
:data-disabled="disabled || undefined"
|
||||
:data-readonly="readonly || undefined"
|
||||
:data-required="required || undefined"
|
||||
:data-focused="focused || undefined"
|
||||
:data-focus-within="focusWithin || undefined"
|
||||
:data-focus-visible="focusVisible || undefined"
|
||||
:data-invalid="invalid || undefined"
|
||||
@focusin="focusin"
|
||||
@focusout="focusout"
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, shallowRef, useAttrs } from "vue";
|
||||
import type {
|
||||
ColorInputGroupBaseProps,
|
||||
ColorInputGroupRenderProps,
|
||||
} from "./types";
|
||||
import { colorInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { useColorFieldContext } from "./context";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { textFieldContextKey } from "../textfield/context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant?: "primary" | "secondary";
|
||||
fullWidth?: boolean;
|
||||
as?: string;
|
||||
role?: string;
|
||||
}>(),
|
||||
{ variant: "primary", as: "div" },
|
||||
);
|
||||
const props = withDefaults(defineProps<ColorInputGroupBaseProps>(), {
|
||||
variant: "primary",
|
||||
as: "div",
|
||||
});
|
||||
defineSlots<{
|
||||
default?: (state: ColorInputGroupRenderProps) => import("vue").VNode[];
|
||||
}>();
|
||||
const attrs = useAttrs(),
|
||||
field = useColorFieldContext(),
|
||||
text = inject(textFieldContextKey, undefined);
|
||||
@@ -29,6 +32,16 @@ const invalid = computed(
|
||||
attrs["aria-invalid"] === true ||
|
||||
attrs["aria-invalid"] === "true",
|
||||
);
|
||||
const state = computed(() => ({
|
||||
isDisabled: disabled.value,
|
||||
isInvalid: invalid.value,
|
||||
isFocusWithin: focused.value,
|
||||
isHovered: hovered.value,
|
||||
}));
|
||||
const ordinaryStyle = computed(() =>
|
||||
typeof props.style === "function" ? props.style(state.value) : props.style,
|
||||
);
|
||||
const computedStyle = computed(() => props.styleFn?.(state.value));
|
||||
function click(event: MouseEvent) {
|
||||
if (event.defaultPrevented || disabled.value) return;
|
||||
const target = event.target as HTMLElement;
|
||||
@@ -44,17 +57,23 @@ function blur(event: FocusEvent) {
|
||||
if (!root.value?.contains(event.relatedTarget as Node | null))
|
||||
focused.value = false;
|
||||
}
|
||||
defineExpose({
|
||||
element: root,
|
||||
focus: () =>
|
||||
root.value
|
||||
?.querySelector<HTMLInputElement>(
|
||||
'input[data-slot="color-input-group-input"]',
|
||||
)
|
||||
?.focus(),
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
ref="root"
|
||||
v-bind="attrs"
|
||||
class="hv-color-input-group"
|
||||
:class="[
|
||||
`hv-color-input-group--${variant}`,
|
||||
{ 'hv-color-input-group--full-width': fullWidth },
|
||||
]"
|
||||
:class="colorInputGroupVariants({ variant, fullWidth }).base()"
|
||||
:style="[ordinaryStyle, computedStyle]"
|
||||
:role="role ?? (field ? 'presentation' : 'group')"
|
||||
data-slot="color-input-group"
|
||||
:data-disabled="disabled || undefined"
|
||||
|
||||
@@ -77,10 +77,12 @@ function inputAttrs() {
|
||||
field.field.field.required.value) ||
|
||||
undefined,
|
||||
"aria-describedby": mergeIds(
|
||||
field.nativeAttrs(attrs)["aria-describedby"] as string | undefined,
|
||||
attrs["aria-describedby"] as string | undefined,
|
||||
field.field.describedBy(),
|
||||
),
|
||||
"aria-labelledby": mergeIds(
|
||||
field.nativeAttrs(attrs)["aria-labelledby"] as string | undefined,
|
||||
attrs["aria-labelledby"] as string | undefined,
|
||||
field.field.labelledBy(),
|
||||
),
|
||||
|
||||
@@ -12,6 +12,10 @@ import type { ValidateResult } from "../field/context";
|
||||
export interface ColorFieldProps
|
||||
extends ColorModelProps, ColorTextOptions, ChoiceFieldProps {
|
||||
as?: string;
|
||||
style?:
|
||||
| import("vue").StyleValue
|
||||
| ((state: ColorFieldRenderState) => import("vue").StyleValue);
|
||||
styleFn?: (state: ColorFieldRenderState) => import("vue").StyleValue;
|
||||
fullWidth?: boolean;
|
||||
autoFocus?: boolean;
|
||||
autoComplete?: string;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { StyleValue, VNode } from "vue";
|
||||
import type ColorField from "./ColorField.vue";
|
||||
import type ColorInputGroup from "./ColorInputGroup.vue";
|
||||
import type ColorInputGroupInput from "./ColorInputGroupInput.vue";
|
||||
import type ColorInputGroupPrefix from "./ColorInputGroupPrefix.vue";
|
||||
import type ColorInputGroupSuffix from "./ColorInputGroupSuffix.vue";
|
||||
export type {
|
||||
ColorFieldProps,
|
||||
ColorFieldProps as ColorFieldRootProps,
|
||||
ColorFieldRenderState,
|
||||
ColorFieldRenderState as ColorFieldRenderProps,
|
||||
} from "./context";
|
||||
export interface ColorInputGroupRenderProps {
|
||||
isDisabled: boolean;
|
||||
isInvalid: boolean;
|
||||
isFocusWithin: boolean;
|
||||
isHovered: boolean;
|
||||
}
|
||||
export interface ColorInputGroupBaseProps {
|
||||
variant?: "primary" | "secondary";
|
||||
fullWidth?: boolean;
|
||||
as?: string;
|
||||
role?: string;
|
||||
style?: StyleValue | ((state: ColorInputGroupRenderProps) => StyleValue);
|
||||
styleFn?: (state: ColorInputGroupRenderProps) => StyleValue;
|
||||
}
|
||||
export type ColorInputGroupProps = InstanceType<
|
||||
typeof ColorInputGroup
|
||||
>["$props"];
|
||||
export type ColorInputGroupRootProps = ColorInputGroupProps;
|
||||
export type ColorFieldGroupProps = ColorInputGroupProps;
|
||||
export type ColorInputGroupInputProps = InstanceType<
|
||||
typeof ColorInputGroupInput
|
||||
>["$props"];
|
||||
export type ColorFieldInputProps = ColorInputGroupInputProps;
|
||||
export type ColorInputGroupPrefixProps = InstanceType<
|
||||
typeof ColorInputGroupPrefix
|
||||
>["$props"];
|
||||
export type ColorFieldPrefixProps = ColorInputGroupPrefixProps;
|
||||
export type ColorInputGroupSuffixProps = InstanceType<
|
||||
typeof ColorInputGroupSuffix
|
||||
>["$props"];
|
||||
export type ColorFieldSuffixProps = ColorInputGroupSuffixProps;
|
||||
export type ColorFieldExpose = Pick<
|
||||
InstanceType<typeof ColorField>,
|
||||
"focus" | "element" | "color"
|
||||
>;
|
||||
export type ColorFieldSlots = {
|
||||
default?: (state: import("./context").ColorFieldRenderState) => VNode[];
|
||||
};
|
||||
@@ -1290,3 +1290,35 @@ export type {
|
||||
RangeCalendarCellProps,
|
||||
RangeCalendarCellIndicatorProps,
|
||||
} from "./types";
|
||||
|
||||
// ColorField and its shared ColorInputGroup parts (HeroUI ce90ea3).
|
||||
export {
|
||||
default as ColorField,
|
||||
default as ColorFieldRoot,
|
||||
} from "./components/color-field/ColorField.vue";
|
||||
export {
|
||||
default as ColorInputGroup,
|
||||
default as ColorInputGroupRoot,
|
||||
default as ColorFieldGroup,
|
||||
} from "./components/color-field/ColorInputGroup.vue";
|
||||
export {
|
||||
default as ColorInputGroupInput,
|
||||
default as ColorFieldInput,
|
||||
} from "./components/color-field/ColorInputGroupInput.vue";
|
||||
export {
|
||||
default as ColorInputGroupPrefix,
|
||||
default as ColorFieldPrefix,
|
||||
} from "./components/color-field/ColorInputGroupPrefix.vue";
|
||||
export {
|
||||
default as ColorInputGroupSuffix,
|
||||
default as ColorFieldSuffix,
|
||||
} from "./components/color-field/ColorInputGroupSuffix.vue";
|
||||
export type * from "./components/color-field/types";
|
||||
export {
|
||||
colorFieldVariants,
|
||||
colorInputGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ColorFieldVariants,
|
||||
ColorInputGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef, useTemplateRef } from "vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorFieldSuffix,
|
||||
Label,
|
||||
parseColor,
|
||||
type Color,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#123456"));
|
||||
const field = useTemplateRef<InstanceType<typeof ColorField>>("field");
|
||||
const input = useTemplateRef<InstanceType<typeof ColorFieldInput>>("input");
|
||||
function focus() {
|
||||
field.value?.focus();
|
||||
field.value?.color?.toString("hex");
|
||||
field.value?.element?.select();
|
||||
input.value?.select();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<button @click="focus">聚焦</button>
|
||||
<ColorField
|
||||
ref="field"
|
||||
v-model="color"
|
||||
channel="hue"
|
||||
color-space="hsl"
|
||||
v-slot="state"
|
||||
:style-fn="(s) => ({ opacity: s.isFocused ? 1 : 0.8 })"
|
||||
>
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup variant="secondary" v-slot="group">
|
||||
<ColorFieldPrefix>{{ state.value?.toString("hex") }}</ColorFieldPrefix>
|
||||
<ColorFieldInput ref="input" />
|
||||
<ColorFieldSuffix>{{ group.isHovered }}</ColorFieldSuffix>
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<!-- @vue-expect-error invalid public model -->
|
||||
<ColorField :model-value="123" />
|
||||
<!-- @vue-expect-error invalid public color channel -->
|
||||
<ColorField channel="cyan" />
|
||||
<!-- @vue-expect-error invalid public color space -->
|
||||
<ColorField color-space="lab" />
|
||||
<!-- @vue-expect-error unsupported group variant -->
|
||||
<ColorFieldGroup variant="tertiary" />
|
||||
</template>
|
||||
@@ -0,0 +1,154 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { ColorField } from "../packages/vue/src";
|
||||
import Basic from "../apps/docs/demos/color-field-basic.vue";
|
||||
import Variants from "../apps/docs/demos/color-field-variants.vue";
|
||||
import OnSurface from "../apps/docs/demos/color-field-on-surface.vue";
|
||||
import WithDescription from "../apps/docs/demos/color-field-with-description.vue";
|
||||
import Required from "../apps/docs/demos/color-field-required.vue";
|
||||
import Disabled from "../apps/docs/demos/color-field-disabled.vue";
|
||||
import FullWidth from "../apps/docs/demos/color-field-full-width.vue";
|
||||
import Invalid from "../apps/docs/demos/color-field-invalid.vue";
|
||||
import ChannelEditing from "../apps/docs/demos/color-field-channel-editing.vue";
|
||||
import Controlled from "../apps/docs/demos/color-field-controlled.vue";
|
||||
import FormExample from "../apps/docs/demos/color-field-form-example.vue";
|
||||
import RenderFunction from "../apps/docs/demos/color-field-render-function.vue";
|
||||
import CustomStyles from "../apps/docs/demos/color-field-custom-styles.vue";
|
||||
const demos = {
|
||||
basic: Basic,
|
||||
variants: Variants,
|
||||
"on-surface": OnSurface,
|
||||
"with-description": WithDescription,
|
||||
required: Required,
|
||||
disabled: Disabled,
|
||||
"full-width": FullWidth,
|
||||
invalid: Invalid,
|
||||
"channel-editing": ChannelEditing,
|
||||
controlled: Controlled,
|
||||
"form-example": FormExample,
|
||||
"render-function": RenderFunction,
|
||||
"custom-styles": CustomStyles,
|
||||
};
|
||||
const mounted: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
mounted.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
function render(component: Parameters<typeof mount>[0]) {
|
||||
const w = mount(component, { attachTo: document.body });
|
||||
mounted.push(w);
|
||||
return w;
|
||||
}
|
||||
const inputs = (w: ReturnType<typeof mount>) =>
|
||||
w.findAll<HTMLInputElement>("input[type=text]");
|
||||
describe("ColorField documentation", () => {
|
||||
it("keeps all thirteen fixed-source previews in page order", () => {
|
||||
const doc = readFileSync("apps/docs/components/color-field.md", "utf8");
|
||||
expect(
|
||||
[...doc.matchAll(/<ComponentPreview name="color-field-([^"]+)"/g)].map(
|
||||
(m) => m[1],
|
||||
),
|
||||
).toEqual(Object.keys(demos));
|
||||
});
|
||||
for (const [name, demo] of Object.entries(demos))
|
||||
it(`renders ${name} through public parts with a label for every input`, () => {
|
||||
const w = render(demo);
|
||||
expect(inputs(w).length).toBeGreaterThan(0);
|
||||
for (const input of inputs(w))
|
||||
expect(w.find(`label[for="${input.attributes("id")}"]`).exists()).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
readFileSync(`apps/docs/demos/color-field-${name}.vue`, "utf8"),
|
||||
).not.toContain("packages/vue");
|
||||
});
|
||||
it("synchronizes basic hex editing and preview on blur", async () => {
|
||||
const w = render(Basic);
|
||||
expect(inputs(w)[0]!.element.value).toBe("#0485F7");
|
||||
await inputs(w)[0]!.setValue("22c55e");
|
||||
await inputs(w)[0]!.trigger("blur");
|
||||
expect(inputs(w)[0]!.element.value).toBe("#22C55E");
|
||||
expect(
|
||||
w.get<HTMLElement>("[data-slot=color-swatch]").element.style
|
||||
.backgroundColor,
|
||||
).toBe("rgb(34, 197, 94)");
|
||||
});
|
||||
it("renders actual secondary, full width, disabled and invalid states", () => {
|
||||
expect(
|
||||
render(Variants)
|
||||
.find("[data-slot=color-input-group].hv-color-input-group--secondary")
|
||||
.exists(),
|
||||
).toBe(true);
|
||||
expect(
|
||||
render(OnSurface)
|
||||
.find(".hv-surface .hv-color-input-group--secondary")
|
||||
.exists(),
|
||||
).toBe(true);
|
||||
expect(
|
||||
render(FullWidth).findAll(".hv-color-field--full-width"),
|
||||
).toHaveLength(2);
|
||||
expect(inputs(render(Disabled)).every((i) => i.element.disabled)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
inputs(render(Invalid)).every(
|
||||
(i) => i.attributes("aria-invalid") === "true",
|
||||
),
|
||||
).toBe(true);
|
||||
expect(inputs(render(Required)).every((i) => i.element.required)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
it("updates all three HSL fields from one accepted color", async () => {
|
||||
const w = render(ChannelEditing);
|
||||
await inputs(w)[0]!.setValue("90");
|
||||
await inputs(w)[0]!.trigger("blur");
|
||||
expect(inputs(w)[0]!.element.value).toBe("90°");
|
||||
expect(inputs(w)[1]!.element.value).toBe("100%");
|
||||
expect(w.text()).toContain("当前:#407F00");
|
||||
});
|
||||
it("controlled buttons replace and clear both input and preview", async () => {
|
||||
const w = render(Controlled);
|
||||
await w.findAll("button")[0]!.trigger("click");
|
||||
expect(inputs(w)[0]!.element.value).toBe("#EF4444");
|
||||
await w.findAll("button")[1]!.trigger("click");
|
||||
expect(inputs(w)[0]!.element.value).toBe("#10B981");
|
||||
await w.findAll("button")[2]!.trigger("click");
|
||||
expect(inputs(w)[0]!.element.value).toBe("");
|
||||
expect(w.text()).toContain("(空)");
|
||||
});
|
||||
it("uses a live scoped slot in the custom root example", async () => {
|
||||
const w = render(RenderFunction);
|
||||
// Let mounted field metadata and child refs settle before exercising native focus.
|
||||
await flushPromises();
|
||||
inputs(w)[0]!.element.focus();
|
||||
await flushPromises();
|
||||
expect(w.get("[data-slot=color-field]").attributes("data-focused")).toBe(
|
||||
"true",
|
||||
);
|
||||
expect(
|
||||
w.get("[data-slot=color-input-group]").attributes("data-field-focused"),
|
||||
).toBe("true");
|
||||
});
|
||||
it("submits the accepted form color and restores empty state after saving", async () => {
|
||||
vi.useFakeTimers();
|
||||
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const w = render(FormExample);
|
||||
expect(w.get<HTMLButtonElement>("button").element.disabled).toBe(true);
|
||||
await inputs(w)[0]!.setValue("abc");
|
||||
await inputs(w)[0]!.trigger("blur");
|
||||
expect(w.get<HTMLButtonElement>("button").element.disabled).toBe(false);
|
||||
expect(new FormData(w.get("form").element).get("brand-color")).toBe(
|
||||
"#AABBCC",
|
||||
);
|
||||
await w.get("form").trigger("submit");
|
||||
expect(w.text()).toContain("保存中…");
|
||||
await vi.advanceTimersByTimeAsync(1500);
|
||||
expect(log).toHaveBeenCalledWith("已提交颜色:", { color: "#AABBCC" });
|
||||
expect(inputs(w)[0]!.element.value).toBe("");
|
||||
expect(w.getComponent(ColorField).emitted("change")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,13 @@
|
||||
import { afterEach, describe, it, expect, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef } from "vue";
|
||||
import ColorField from "../packages/vue/src/components/color-field/ColorField.vue";
|
||||
import ColorInputGroup from "../packages/vue/src/components/color-field/ColorInputGroup.vue";
|
||||
import ColorInputGroupInput from "../packages/vue/src/components/color-field/ColorInputGroupInput.vue";
|
||||
import Prefix from "../packages/vue/src/components/color-field/ColorInputGroupPrefix.vue";
|
||||
import Suffix from "../packages/vue/src/components/color-field/ColorInputGroupSuffix.vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorInputGroup,
|
||||
ColorInputGroupInput,
|
||||
ColorInputGroupPrefix as Prefix,
|
||||
ColorInputGroupSuffix as Suffix,
|
||||
} from "../packages/vue/src/index";
|
||||
import {
|
||||
Label,
|
||||
Description,
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef, h } from "vue";
|
||||
import * as api from "../packages/vue/src";
|
||||
const mounted: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
mounted.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
function view(template: string, setup = () => ({})) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
ColorField: api.ColorField,
|
||||
ColorFieldGroup: api.ColorFieldGroup,
|
||||
ColorFieldInput: api.ColorFieldInput,
|
||||
ColorFieldPrefix: api.ColorFieldPrefix,
|
||||
ColorFieldSuffix: api.ColorFieldSuffix,
|
||||
ColorInputGroup: api.ColorInputGroup,
|
||||
ColorInputGroupInput: api.ColorInputGroupInput,
|
||||
Label: api.Label,
|
||||
Description: api.Description,
|
||||
FieldError: api.FieldError,
|
||||
},
|
||||
setup,
|
||||
template,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
mounted.push(w);
|
||||
return w;
|
||||
}
|
||||
const control = (w: ReturnType<typeof mount>) =>
|
||||
w.get<HTMLInputElement>("[data-slot=color-input-group-input]");
|
||||
const body =
|
||||
"<Label>颜色</Label><ColorFieldGroup><ColorFieldPrefix>#</ColorFieldPrefix><ColorFieldInput/><ColorFieldSuffix>色</ColorFieldSuffix></ColorFieldGroup><Description>帮助</Description><FieldError/>";
|
||||
describe("public ColorField", () => {
|
||||
it("exports aliases without creating separate implementations", () => {
|
||||
expect(api.ColorFieldRoot).toBe(api.ColorField);
|
||||
expect(api.ColorInputGroupRoot).toBe(api.ColorFieldGroup);
|
||||
expect(api.ColorInputGroupInput).toBe(api.ColorFieldInput);
|
||||
expect(api.ColorInputGroupPrefix).toBe(api.ColorFieldPrefix);
|
||||
expect(api.ColorInputGroupSuffix).toBe(api.ColorFieldSuffix);
|
||||
expect(api.colorFieldVariants({ fullWidth: true })).toContain(
|
||||
"hv-color-field--full-width",
|
||||
);
|
||||
expect(
|
||||
api.colorInputGroupVariants({ variant: "secondary" }).base(),
|
||||
).toContain("hv-color-input-group--secondary");
|
||||
});
|
||||
it("routes every ARIA attribute to the input and updates root attrs reactively", async () => {
|
||||
const details = shallowRef("details-a");
|
||||
const w = view(
|
||||
`<ColorField aria-label="颜色" aria-labelledby="external-label" aria-describedby="external-description" :aria-details="details">${body}</ColorField>`,
|
||||
() => ({ details }),
|
||||
);
|
||||
expect(control(w).attributes("aria-details")).toBe("details-a");
|
||||
expect(control(w).attributes("aria-labelledby")).toContain(
|
||||
"external-label",
|
||||
);
|
||||
expect(control(w).attributes("aria-describedby")).toContain(
|
||||
"external-description",
|
||||
);
|
||||
expect(
|
||||
w.get("[data-slot=color-field]").attributes("aria-details"),
|
||||
).toBeUndefined();
|
||||
details.value = "details-b";
|
||||
await flushPromises();
|
||||
expect(control(w).attributes("aria-details")).toBe("details-b");
|
||||
});
|
||||
it("updates scoped slots, styles and focus states from the real input", async () => {
|
||||
const w = view(
|
||||
`<ColorField as="section" default-value="#123456" :style-fn="s => ({ opacity: s.isFocused ? '.5' : '1' })" v-slot="s"><ColorFieldGroup :style-fn="g => ({ marginTop: g.isFocusWithin ? '2px' : '0px' })"><ColorFieldInput /></ColorFieldGroup><output>{{s.isFocused}}/{{s.isFocusWithin}}</output></ColorField>`,
|
||||
);
|
||||
control(w).element.focus();
|
||||
await flushPromises();
|
||||
const root = w.get<HTMLElement>("section");
|
||||
expect(root.attributes("data-focused")).toBe("true");
|
||||
expect(root.attributes("data-focus-within")).toBe("true");
|
||||
expect(root.element.style.opacity).toBe("0.5");
|
||||
expect(
|
||||
w.get<HTMLElement>("[data-slot=color-input-group]").element.style
|
||||
.marginTop,
|
||||
).toBe("2px");
|
||||
expect(w.get("output").text()).toBe("true/true");
|
||||
control(w).element.blur();
|
||||
await flushPromises();
|
||||
expect(w.get("output").text()).toBe("false/false");
|
||||
expect(root.attributes("data-focus-within")).toBeUndefined();
|
||||
});
|
||||
it("exposes the actual input and color, with usable focus()", async () => {
|
||||
const w = view(`<ColorField default-value="#123456">${body}</ColorField>`);
|
||||
const field = w.getComponent(api.ColorField);
|
||||
field.vm.focus();
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(control(w).element);
|
||||
expect(field.vm.element).toBe(control(w).element);
|
||||
expect(field.vm.color?.toString("hex")).toBe("#123456");
|
||||
});
|
||||
it("retries a rejected hex, preserves the native draft until commit and resets accepted DOM", async () => {
|
||||
const w = view(
|
||||
`<form><ColorField name="color" model-value="#123456">${body}</ColorField></form>`,
|
||||
);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await control(w).setValue("abc");
|
||||
expect(new FormData(w.get("form").element).get("color")).toBe("abc");
|
||||
await control(w).trigger("keydown", { key: "Enter" });
|
||||
expect(control(w).element.value).toBe("#123456");
|
||||
}
|
||||
expect(w.getComponent(api.ColorField).emitted("change")).toHaveLength(2);
|
||||
await control(w).setValue("#12");
|
||||
w.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(control(w).element.value).toBe("#123456");
|
||||
});
|
||||
it("modelValue including null takes precedence over value/defaultValue", async () => {
|
||||
const w = view(
|
||||
`<ColorField :model-value="null" value="#abcdef" default-value="#123456">${body}</ColorField>`,
|
||||
);
|
||||
expect(control(w).element.value).toBe("");
|
||||
await control(w).setValue("abc");
|
||||
await control(w).trigger("blur");
|
||||
expect(control(w).element.value).toBe("");
|
||||
});
|
||||
it("switches between standalone and inherited color values without leaking drafts", async () => {
|
||||
const owns = shallowRef(false);
|
||||
const w = view(
|
||||
`<ColorField default-value="hsl(200,50%,50%)"><ColorFieldGroup><ColorFieldInput /></ColorFieldGroup><ColorField v-bind="owns ? { modelValue: '#abcdef' } : {}"><ColorFieldGroup><ColorFieldInput /></ColorFieldGroup></ColorField></ColorField>`,
|
||||
() => ({ owns }),
|
||||
);
|
||||
const inputs = w.findAll<HTMLInputElement>("input[type=text]");
|
||||
expect(inputs[1]!.element.value).toBe(inputs[0]!.element.value);
|
||||
await inputs[1]!.setValue("#12");
|
||||
owns.value = true;
|
||||
await flushPromises();
|
||||
expect(inputs[1]!.element.value).toBe("#ABCDEF");
|
||||
owns.value = false;
|
||||
await flushPromises();
|
||||
expect(inputs[1]!.element.value).toBe(inputs[0]!.element.value);
|
||||
});
|
||||
it("commits composition only after candidate completion and preserves alpha when text is untouched", async () => {
|
||||
const w = view(
|
||||
`<ColorField default-value="hsba(270,0%,50%,.123456789)">${body}</ColorField>`,
|
||||
);
|
||||
await control(w).trigger("compositionstart");
|
||||
await control(w).setValue("abc");
|
||||
await control(w).trigger("keydown", { key: "Enter" });
|
||||
expect(w.getComponent(api.ColorField).emitted("change")).toBeUndefined();
|
||||
await control(w).trigger("compositionend");
|
||||
await flushPromises();
|
||||
await control(w).trigger("keydown", { key: "Escape" });
|
||||
await control(w).trigger("blur");
|
||||
expect(
|
||||
w.getComponent(api.ColorField).vm.color?.getChannelValue("alpha"),
|
||||
).toBe(0.123456789);
|
||||
});
|
||||
it("does not run unknown wrappers to discover an input", () => {
|
||||
const setup = vi.fn(() => () => h(api.ColorFieldInput));
|
||||
const Unknown = defineComponent({ setup });
|
||||
const w = mount(api.ColorField, { slots: { default: () => h(Unknown) } });
|
||||
mounted.push(w);
|
||||
expect(setup).toHaveBeenCalledOnce();
|
||||
expect(control(w).element.tagName).toBe("INPUT");
|
||||
});
|
||||
it("supports an independent group as a plain v-model text field", async () => {
|
||||
const value = shallowRef("free text");
|
||||
const w = view(
|
||||
'<ColorInputGroup variant="secondary"><ColorInputGroupInput v-model="value" name="plain" /></ColorInputGroup>',
|
||||
() => ({ value }),
|
||||
);
|
||||
await control(w).setValue("anything");
|
||||
expect(value.value).toBe("anything");
|
||||
expect(w.get("[data-slot=color-input-group]").attributes("role")).toBe(
|
||||
"group",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -44,6 +44,26 @@ for (const id of process.argv.slice(2)) {
|
||||
assert(lib.RangeCalendar === lib.RangeCalendarRoot);
|
||||
assert(lib.rangeCalendarVariants().cell() === "hv-range-calendar__cell");
|
||||
}
|
||||
if (id === "color-field") {
|
||||
assert(lib.ColorField === lib.ColorFieldRoot);
|
||||
assert(lib.ColorFieldGroup === lib.ColorInputGroup);
|
||||
assert(lib.ColorFieldGroup === lib.ColorInputGroupRoot);
|
||||
assert(lib.ColorFieldInput === lib.ColorInputGroupInput);
|
||||
assert(lib.ColorFieldPrefix === lib.ColorInputGroupPrefix);
|
||||
assert(lib.ColorFieldSuffix === lib.ColorInputGroupSuffix);
|
||||
assert(
|
||||
lib
|
||||
.colorFieldVariants({ fullWidth: true })
|
||||
.includes("hv-color-field--full-width"),
|
||||
);
|
||||
const slots = lib.colorInputGroupVariants({
|
||||
variant: "secondary",
|
||||
fullWidth: true,
|
||||
});
|
||||
assert(slots.base().includes("hv-color-input-group--secondary"));
|
||||
assert(slots.base().includes("hv-color-input-group--full-width"));
|
||||
assert(slots.input() === "hv-color-input-group__input");
|
||||
}
|
||||
if (id === "time-field") {
|
||||
assert(lib.TimeField === lib.TimeFieldRoot);
|
||||
assert(lib.TimeFieldGroup === lib.DateInputGroup);
|
||||
|
||||
@@ -137,12 +137,12 @@
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-foundation": {
|
||||
"exports": [],
|
||||
"css": [".hv-color-area", ".hv-color-area__thumb"],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-picker-protocol": {
|
||||
"exports": [],
|
||||
@@ -151,7 +151,7 @@
|
||||
".hv-color-picker__trigger",
|
||||
".hv-color-picker__popover"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-slider-foundation": {
|
||||
"exports": [],
|
||||
@@ -165,7 +165,7 @@
|
||||
"max-height:inherit",
|
||||
"overscroll-behavior:contain"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"date-field": {
|
||||
"exports": [
|
||||
@@ -462,5 +462,32 @@
|
||||
"--track-start-color",
|
||||
"--track-end-color"
|
||||
]
|
||||
},
|
||||
"color-field": {
|
||||
"exports": [
|
||||
"ColorField",
|
||||
"ColorFieldRoot",
|
||||
"ColorFieldGroup",
|
||||
"ColorFieldInput",
|
||||
"ColorFieldPrefix",
|
||||
"ColorFieldSuffix",
|
||||
"ColorInputGroup",
|
||||
"ColorInputGroupRoot",
|
||||
"ColorInputGroupInput",
|
||||
"ColorInputGroupPrefix",
|
||||
"ColorInputGroupSuffix",
|
||||
"colorFieldVariants",
|
||||
"colorInputGroupVariants"
|
||||
],
|
||||
"css": [
|
||||
".hv-color-field",
|
||||
".hv-color-field--full-width",
|
||||
".hv-color-input-group",
|
||||
".hv-color-input-group--secondary",
|
||||
".hv-color-input-group__input",
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorPicker", "ColorSwatchPicker"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldRoot,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorFieldSuffix,
|
||||
ColorInputGroup,
|
||||
ColorInputGroupRoot,
|
||||
ColorInputGroupInput,
|
||||
ColorInputGroupPrefix,
|
||||
ColorInputGroupSuffix,
|
||||
colorFieldVariants,
|
||||
colorInputGroupVariants,
|
||||
parseColor,
|
||||
type ColorFieldProps,
|
||||
type ColorFieldRootProps,
|
||||
type ColorFieldGroupProps,
|
||||
type ColorFieldInputProps,
|
||||
type ColorFieldPrefixProps,
|
||||
type ColorFieldSuffixProps,
|
||||
type ColorFieldRenderProps,
|
||||
type ColorFieldRenderState,
|
||||
type ColorFieldSlots,
|
||||
type ColorFieldExpose,
|
||||
type ColorFieldVariants,
|
||||
type ColorInputGroupVariants,
|
||||
type ColorInputGroupProps,
|
||||
type ColorInputGroupInputProps,
|
||||
type ColorInputGroupRootProps,
|
||||
type ColorInputGroupPrefixProps,
|
||||
type ColorInputGroupSuffixProps,
|
||||
type ColorInputGroupRenderProps,
|
||||
} from "@heroui-vue/components";
|
||||
const props: ColorFieldProps = {
|
||||
modelValue: parseColor("#123456"),
|
||||
value: null,
|
||||
defaultValue: "#abcdef",
|
||||
channel: "hue",
|
||||
colorSpace: "hsb",
|
||||
name: "hue",
|
||||
form: "external",
|
||||
isRequired: true,
|
||||
isReadOnly: false,
|
||||
isWheelDisabled: true,
|
||||
locale: "de-DE",
|
||||
validate: (color) => (color ? true : "必填"),
|
||||
styleFn: (s) => ({ opacity: s.isFocused ? 0.5 : 1 }),
|
||||
};
|
||||
const root: ColorFieldRootProps = props;
|
||||
const group: ColorFieldGroupProps = {
|
||||
variant: "secondary",
|
||||
styleFn: (s) => ({ opacity: s.isFocusWithin ? 1 : 0.5 }),
|
||||
};
|
||||
const ig: ColorInputGroupProps = group;
|
||||
const igr: ColorInputGroupRootProps = ig;
|
||||
const input: ColorFieldInputProps = { defaultValue: "abc" };
|
||||
const ii: ColorInputGroupInputProps = input;
|
||||
const prefix: ColorFieldPrefixProps = { as: "span" };
|
||||
const ip: ColorInputGroupPrefixProps = prefix;
|
||||
const suffix: ColorFieldSuffixProps = { as: "span" };
|
||||
const is: ColorInputGroupSuffixProps = suffix;
|
||||
const slots: ColorFieldSlots = {
|
||||
default: (s) => [h("span", s.value?.toString("hex"))],
|
||||
};
|
||||
const state: ColorFieldRenderProps = {
|
||||
value: null,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isRequired: false,
|
||||
isInvalid: false,
|
||||
isFocused: false,
|
||||
isFocusWithin: false,
|
||||
isFocusVisible: false,
|
||||
validationErrors: [],
|
||||
};
|
||||
const renderState: ColorFieldRenderState = state;
|
||||
const gs: ColorInputGroupRenderProps = {
|
||||
isDisabled: false,
|
||||
isInvalid: false,
|
||||
isFocusWithin: false,
|
||||
isHovered: false,
|
||||
};
|
||||
const variant: ColorFieldVariants = { fullWidth: true };
|
||||
const iv: ColorInputGroupVariants = { variant: "secondary" };
|
||||
colorFieldVariants(variant);
|
||||
colorInputGroupVariants(iv).input();
|
||||
h(ColorField, {
|
||||
...props,
|
||||
"onUpdate:modelValue": (value) => value?.toString("hex"),
|
||||
});
|
||||
h(ColorFieldRoot, root);
|
||||
h(ColorFieldGroup, group);
|
||||
h(ColorFieldInput, input);
|
||||
h(ColorFieldPrefix, prefix);
|
||||
h(ColorFieldSuffix, suffix);
|
||||
h(ColorInputGroup, ig);
|
||||
h(ColorInputGroupRoot, igr);
|
||||
h(ColorInputGroupInput, ii);
|
||||
h(ColorInputGroupPrefix, ip);
|
||||
h(ColorInputGroupSuffix, is);
|
||||
declare const field: InstanceType<typeof ColorField>;
|
||||
field.focus();
|
||||
field.element?.select();
|
||||
field.color?.toString("hex");
|
||||
const exposed: ColorFieldExpose = field;
|
||||
declare const control: InstanceType<typeof ColorFieldInput>;
|
||||
control.focus();
|
||||
control.select();
|
||||
control.element?.select();
|
||||
// @ts-expect-error invalid model
|
||||
const bad: ColorFieldProps = { modelValue: 123 };
|
||||
// @ts-expect-error invalid channel
|
||||
const badChannel: ColorFieldProps = { channel: "cyan" };
|
||||
// @ts-expect-error invalid color space
|
||||
h(ColorField, { colorSpace: "oklch" });
|
||||
// @ts-expect-error actual public component rejects invalid model
|
||||
h(ColorField, { modelValue: 123 });
|
||||
// @ts-expect-error variant is primary or secondary
|
||||
const badGroup: ColorFieldGroupProps = { variant: "tertiary" };
|
||||
// @ts-expect-error validators receive Color/null
|
||||
const badValidator: ColorFieldProps = { validate: (v: string) => true };
|
||||
// @ts-expect-error no public transaction state
|
||||
field.state.begin();
|
||||
void [slots, renderState, gs, exposed, bad, badChannel, badGroup, badValidator];
|
||||
Reference in New Issue
Block a user