feat: establish composed color picker protocol
This commit is contained in:
@@ -522,3 +522,7 @@ Area 覆盖所有有序轴和 RTL;稳定 Root 捕获指针,内容区/边框/
|
||||
Root/Group/Input 复用 choice/Form;Group 独立时是普通文本,不能污染外层 TextField。元数据预读不能冻结 Group 实际作用域插槽状态,也不执行未知组件 setup/render;未知包装的关键属性放 Root。输入事件在真实节点合并一次、先尊重可取消事件。内部组合与样式已有验证,尚未公开;Area/Swatch 后按 [COLOR-07](docs/migrations/COLOR-07-field-group-prompt.md) 交接13例和公共收尾,Picker 正式接口仍由集成人维护。
|
||||
|
||||
字段 Root 的 useAttrs 不当作可 watch 的响应式状态;仅 ARIA 或事件回调变化也要让真实 Input 更新。元数据预读与实际 Group scoped slot 渲染分开验证,不能因 SSR 标签规划而冻结 hover/focus 插槽。
|
||||
|
||||
## COLOR-08 Picker 正式组合协议
|
||||
|
||||
先读 [COLOR-08](docs/migrations/COLOR-08-picker-protocol.md)。Picker 默认黑色、拒绝 null 子提案;allowEmpty 只在该 owner 关闭,独立字段仍可清空。Root/Trigger/Popover 已替换临时组合,仍未公开。关闭只观察接受 open、默认 bottom left 为物理左对齐、面板直接滚动并保留自身间距/zoom95。name/form/changeEnd/open 为明确 Vue 扩展,不冒充 RAC 原生 API;完整颜色提交与字段显示协议分开。不得使用 v-bind 全部已声明 props 给下级 Root:省略的 modelValue/value 也会变为 vnode 显式属性,改变受控/继承语义。公开前按 [COLOR-09](docs/migrations/COLOR-09-picker-prompt.md) 补全 Trigger 状态、variants、六例、文档与独立产物。
|
||||
|
||||
@@ -234,3 +234,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
|
||||
## COLOR-06 颜色字段组合协议
|
||||
|
||||
ColorField/ColorInputGroup 内部 Root/Input/前后缀、校验/关联、独立文本组及正式字段显示/提交协议已验证;未公开包根、variants 或正式13例。通道字段以自然步长提交归一化数字,Hex 使用命名可见输入,完整接受颜色独立保留精度。原始底座修正和实际差异见 [COLOR-06](migrations/COLOR-06-field-protocol.md)。
|
||||
|
||||
## COLOR-08 Picker 内部三部件
|
||||
|
||||
ColorPicker/Trigger/Popover 正式组合内部已接入,共享非空 owner、现有 Popover 和单一原生提交/reset。尚无包根导出、公共 variants/六例完成声明;默认值、明确 Vue 扩展和公开待办见 [COLOR-08](migrations/COLOR-08-picker-protocol.md)。
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# COLOR-08:ColorPicker 组合部件与非空 owner
|
||||
|
||||
2026-10-25,从同步后的 main `92c7682` 新建 `feat/color-picker-protocol`。已实现内部 ColorPicker、ColorPickerTrigger、ColorPickerPopover 三部件,并替换旧组合夹具中的临时 owner/Popover/Boundary。没有提前添加包根导出或正式组件页;Area/Swatch、Slider、Field/Group 的公开批次仍未合入,不能将本记录当作六个正式示例已完成。
|
||||
|
||||
## 固定源码与约定
|
||||
|
||||
核对 HeroUI ce90ea3 的 ColorPicker TSX、CSS、中文文档与六例;直接审计官方 npm RAC1.21.1 ColorPicker 与 Stately3.50.0 useColorPickerState 的发布源码及声明,未安装或运行 React。
|
||||
|
||||
- [RAC ColorPicker](https://unpkg.com/react-aria-components@1.21.1/dist/private/ColorPicker.mjs) 为颜色子组件提供共享值;HeroUI 自己加 DialogTrigger 和容器,Vue 使用同一个颜色 owner 与现有 Popover,不增加第二套 open 状态或定位/焦点栈。
|
||||
- [Stately 状态](https://unpkg.com/react-stately@3.50.0/dist/private/color/useColorPickerState.mjs) 默认 `#000000`,忽略 null 提案。共享模型新增可选 `allowEmpty:false`:Picker 拒绝子字段清空,不发 change/changeEnd;独立字段仍可为空。Picker 的类型不接受 null。运行时越过类型传入 null 时以黑色兜底,子部件和 Root 从同一状态取值。
|
||||
- 默认非继承 owner;嵌套 Picker 独立,普通字段/轨道省略自身值时才继承最近 owner。Root slot 暴露接受的 color、isOpen、close、isDisabled、isReadOnly;`value` 别名与 `v-model` 保持既有优先级。
|
||||
- `open` / `isOpen` 默认明确保留 undefined。只在现有 Popover **接受关闭**后取消事务;受控拒绝关闭不能取消当前手势。关闭、焦点恢复、外部点击与 Teleport 全部复用已有实现。
|
||||
|
||||
## Vue 扩展与提交边界
|
||||
|
||||
固定 RAC Picker 本身没有 name/form、changeEnd 或受控 open。本库内部组合明确增加这几项能力,公开时必须记录为 Vue 扩展,不写成照搬上游:
|
||||
|
||||
- `name` 可选,省略时没有成功提交值。Root 的唯一 hidden input 同时复用既有原生 reset 关联,支持外部 form;禁用不成功提交。
|
||||
- opt-in 完整颜色值使用 `serializeColorValue`,保留当前 RGB/HSL/HSB 空间及完整数字精度,不借由 Hex 或通道显示往返;它与 ColorField 通道的归一化数字、命名可见 Hex 输入不同。字段子部件默认不另命名;用户显式命名子字段即是另一项提交。
|
||||
- changeEnd 表示本次事务的最后提案,不能当作受控父层已接受。改变颜色和改变打开状态分别发事件。
|
||||
|
||||
## 样式与实际节点
|
||||
|
||||
ColorPicker CSS 原数值移植并加 hv- 前缀、Apache 声明。默认 placement 为物理 `bottom left`,并非 RTL 下的 start;映射至现有定位器。面板本身 flex/gap3、px2/pt2/pb3、min-w62、圆角 `min(32px, radius*2.5)`、enter150ms/zoom95、exit100ms/zoom95;使用 Reka origin/side/available-height。Popup 直接滚动,不强加通用 PopoverDialog 的16px内边距。减少动画加显式适配,Presence 仍拥有卸载生命周期。
|
||||
|
||||
PopoverTrigger 原先固定 data-slot 会吞掉组合组件的 slot。现在允许显式 data-slot,普通 Popover 的默认标记不变;新 Picker Trigger 默认是原生 button/type=button,无 Button 的默认胶囊/内边距。class/style/ARIA/可取消事件均由真实触发器、真实面板接收。
|
||||
|
||||
## 验证与剩余工作
|
||||
|
||||
新增8项组合协议与2项真正 Node SSR,原有10项组合/实际水合继续覆盖正式部件;全库、构建和重点浏览器结论见 verification.md。真实浏览器检查正式面板、Hex/alpha同步、清空拒绝、Escape恢复焦点及唯一提交。仅重点验收,未做六例全主题逐像素、完整读屏、物理触屏或 Nuxt。
|
||||
|
||||
公开收尾见 [COLOR-09](COLOR-09-picker-prompt.md)。仍需 variants、包根各部件/Props、Trigger 的完整 button scoped states/公开类型、六例和正式 API/差异文档,以及独立最终 tarball 的公共类型正反例。不得把内部接口直接导出后跳过这些检查。
|
||||
@@ -0,0 +1,17 @@
|
||||
# COLOR-09:ColorPicker 公开收尾交接
|
||||
|
||||
先同步最新远程 main,再新开 feat/color-picker-public 分支。只操作自己的独立 checkout,不修改集成人 heroui-vue-core 工作区。先读 AGENTS.md、COLOR-01/03/04/06/08、兼容矩阵及固定上游来源。
|
||||
|
||||
本任务以 COLOR-02 Area/Swatch、COLOR-05 Slider、COLOR-07 Field/Group 已经合入 main 为前提;未合入先完成它们,不复制私有测试夹具或用临时 div/native 输入充当正式示例。
|
||||
|
||||
完成内部 `color-picker/` 三部件的公开收尾:ColorPicker/ColorPickerRoot、ColorPickerTrigger、ColorPickerPopover、全部 Props 与 variants。默认样式/子部件/六例按 HeroUI ce90ea3,不另设计外观。Picker 已有颜色/关闭/原生提交协议,消费该实现,不另建颜色 ref、Popover 或 Form 队列。
|
||||
|
||||
1. 审计原版 Trigger 所继承的 button Props/作用域状态;补齐需要的 hover/pressed/focused/focusVisible 状态与正确原生交互。不要把普通 Button 的默认视觉套给无样式 Trigger。原生取消先于激活,处理器只执行一次,disabled/asChild/ref/键盘均检查。
|
||||
2. 六例按顺序迁移 basic、controlled、with-swatches、with-fields、with-sliders、custom-styles,预览/复制/高亮同一 SFC,图标用 Tabler Vue。示例使用公开包根,不能引用私有 fixture、源码相对路径或未导出类型。
|
||||
3. 默认黑色、非空 Picker、子字段清空不清 Picker;控件共享接受值并保留灰色 hue/alpha/完整精度。保持受控拒绝重试、关闭拒绝、dirty Escape/clean Escape、单一 owner、独立子值与嵌套 owner 语义。
|
||||
4. name/form、changeEnd、v-model:open/isOpen、disabled/readOnly 是有意提供的 Vue 扩展,文档明确;可选唯一提交格式为完整原生空间函数,不抄 Hex/通道字段格式。Root 不命名时不成功提交,禁用排除、reset/外部form/取消reset必须保留。
|
||||
5. 默认 bottom left 为物理对齐,Source Picker 本身是滚动面板,不额外套 PopoverDialog 的内边距。检查 data-slot、可用高度、origin、placement/data-side、150/100ms zoom95 与 reduced-motion,不能退回通用 zoom90。
|
||||
6. 满宽换行 API 表、中文标题/介绍/示例顺序、导航/前后页同步。同步 compatibility/upstream/verification,明确真实验收与待办。
|
||||
7. 单元、真实 Node SSR/水合、类型/构建/格式检查。最终两包 tarball 安装到独立应用,ESM/SSR/CSS 与 strict NodeNext/bundler 公共组件/Props/事件/slot 正反例有效。重点浏览器检查一个完整 Picker 的共享值、文本、关闭焦点、长面板定位与动画;不用每页逐个点击。
|
||||
|
||||
遇到共享 owner/字段/轨道/弹层的真实缺口,提交最小失败用例和原因交集成人,不重写内核或安装第二套整库。没有完成功能/公开类型/完整文档时不要只用绿色测试数量宣称迁移完成。完成后报告分支、变更范围、实际验证和明确差异,等待集成人复核合入。
|
||||
@@ -222,3 +222,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
## COLOR-06 字段组合(2026-10-25)
|
||||
|
||||
固定 ce90ea3 ColorField/ColorInputGroup、对应 CSS/tv、中文文档与13例;CSS 加 hv- 前缀并保留 Apache 声明。直接审计 npm 官方 RAC1.21.1、Stately3.50.0、Aria3.52.1 tarball 中 ColorField、ColorChannelFieldState、ColorField/NumberField 原生协议,未安装/执行 React、未移植其 hook。发布文件链接、通道尺度与禁用/validate 修正见 [COLOR-06](migrations/COLOR-06-field-protocol.md)。
|
||||
|
||||
## COLOR-08 Picker(2026-10-25)
|
||||
|
||||
固定 ce90ea3 ColorPicker TSX/CSS/中文六例;CSS 加 hv- 前缀与 Apache 声明,placement/origin 映射到 Reka,并适配 reduced-motion。直接审计官方 npm RAC1.21.1 ColorPicker 与 Stately3.50.0 useColorPickerState 的发布源码/声明,没有安装或执行 React;默认黑色与拒绝 null 依据、Vue 扩展见 [COLOR-08](migrations/COLOR-08-picker-protocol.md)。
|
||||
|
||||
@@ -946,3 +946,11 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
- 最终 tarball 在 `/private/tmp/heroui-color-field-consumer` 独立安装,无源码 alias:新增字段/输入组 CSS 和没有提前公开占位的检查;Calendar/DateField/Select 的 ESM/SSR/CSS 与 strict NodeNext/bundler 类型正反例保留。这不证明私有字段的公共类型/产物已经验收,公开批次仍需单独的完整契约。
|
||||
- 真浏览器 5176 `?color-field-protocol` 验证受控 Hex 原生 Enter 提交 `#DDEEFF`、德语 `33,25%` 提交0.33、聚焦纵向滚轮50%→51%、必填错误聚焦/描述切换,以及 Picker 文本25%同步 Slider/完整颜色且只有一个 name=color。验收截图 `/private/tmp/heroui-color-field-protocol-review.png` 不参与构建。
|
||||
- 固定 RAC1.21.1/Stately3.50.0/Aria3.52.1 发布源码仅审计,未安装/执行 React;通道步长/百分数/Hex 原生草稿语义已与旧单输入夹具分开。Group 实际作用域插槽状态、Root attrs-only 更新、独立文本组和字段 owner 隔离均有回归。完整读屏、物理触屏、逐像素/全主题和 Nuxt 未验收。
|
||||
|
||||
## COLOR-08 Picker 正式组合协议(2026-10-25)
|
||||
|
||||
- 从同步 main `92c7682` 新建 feat/color-picker-protocol;内部 Root/Trigger/Popover 替换旧 owner/Boundary 夹具。新增8项协议、2项真正 Node SSR,保留10项原组合/实际水合;最终全库 **88 文件 / 1061 项通过**。类型检查包含 null/数字 Picker 模型反例,未提前公开颜色组件。
|
||||
- 固定版本发布源码审计默认黑色与拒绝 null;非空 owner、清空不发事件、父拒绝/重试、独立嵌套、readOnly/程序更新、外部 form/reset、一次原生取消与 open 拒绝均有回归。完整精度 opt-in 提交及 changeEnd/open 是明确 Vue 扩展,见 [COLOR-08](migrations/COLOR-08-picker-protocol.md)。
|
||||
- 库/样式/文档 SSR、playground 构建、vue-tsc、全仓格式与 diff 检查通过;原有 docs 大 chunk 提示保留。最终两份 tarball 独立安装 `/private/tmp/heroui-color-picker-consumer`,Picker暂存CSS/没有提前公开占位、旧Calendar/DateField/Select ESM/SSR/CSS 与 strict NodeNext/bundler正反类型均通过。这不是尚未公开 Picker 的公共产物类型验收。
|
||||
- 真浏览器 5176 `?color-field-protocol` 验证清空 Hex 回到 #808080、alpha25%同步Slider、clean Escape关闭恢复正式Trigger、仅一份name=color。面板实际248px宽、12px gap、8px 8px 12px padding、20px圆角,约束来自固定源CSS并映射Reka可用高度;截图 `/private/tmp/heroui-color-picker-protocol-review.png`。没有逐帧计时、六例全主题像素比较、全AT、物理触屏或Nuxt验收。
|
||||
- 公开API/Trigger完整button状态、variants、六例与独立公共产物收尾按 [COLOR-09](migrations/COLOR-09-picker-prompt.md);必须等待其他公开颜色批次集成,不能引用私有fixture冒充正式文档。
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts tests/range-calendar-foundation.test.ts tests/color-foundation.test.ts tests/color-foundation-probes.test.ts tests/color-input-foundation.test.ts tests/color-input-probes.test.ts tests/color-slider-foundation.test.ts tests/color-picker-composition.test.ts tests/color-field-protocol.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts tests/range-calendar-foundation-ssr.test.ts tests/color-foundation-ssr.test.ts tests/color-input-foundation-ssr.test.ts tests/color-slider-foundation-ssr.test.ts tests/color-field-protocol-ssr.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts tests/range-calendar-foundation.test.ts tests/color-foundation.test.ts tests/color-foundation-probes.test.ts tests/color-input-foundation.test.ts tests/color-input-probes.test.ts tests/color-slider-foundation.test.ts tests/color-picker-composition.test.ts tests/color-field-protocol.test.ts tests/color-picker-protocol.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts tests/range-calendar-foundation-ssr.test.ts tests/color-foundation-ssr.test.ts tests/color-input-foundation-ssr.test.ts tests/color-slider-foundation-ssr.test.ts tests/color-field-protocol-ssr.test.ts tests/color-picker-protocol-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* ==========================================================================
|
||||
ColorPicker - Color selection component with popover
|
||||
========================================================================== */
|
||||
|
||||
/* Base color-picker styles */
|
||||
.hv-color-picker {
|
||||
@apply inline-flex;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Trigger
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-picker__trigger {
|
||||
@apply inline-flex items-center gap-3 rounded-sm text-sm no-highlight;
|
||||
|
||||
/* Cursor */
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
background-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
[data-slot="label"] {
|
||||
cursor: var(--cursor-interactive);
|
||||
}
|
||||
|
||||
/* Focus visible state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Popover
|
||||
========================================================================== */
|
||||
|
||||
.hv-color-picker__popover {
|
||||
@apply min-w-62 origin-(--reka-popper-transform-origin) scrollbar-none overflow-x-hidden overflow-y-auto overscroll-contain bg-overlay px-2 pt-2 pb-3;
|
||||
box-shadow: var(--overlay-shadow);
|
||||
border-radius: min(32px, calc(var(--radius) * 2.5));
|
||||
/* Content layout */
|
||||
@apply flex flex-col gap-3;
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
/* Entering animations */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-95;
|
||||
|
||||
/* Placement-specific translations */
|
||||
&[data-side="top"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
|
||||
&[data-side="bottom"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-side="left"] {
|
||||
@apply slide-in-from-right-1;
|
||||
}
|
||||
|
||||
&[data-side="right"] {
|
||||
@apply slide-in-from-left-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Exiting animations */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
|
||||
/* Stays non-interactive while closing, even if the exit animation is interrupted. */
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||||
}
|
||||
}
|
||||
|
||||
/* Reka supplies available height on the positioned surface. Picker scrolls its own content. */
|
||||
.hv-popover.hv-color-picker__popover {
|
||||
max-height: var(--reka-popover-content-available-height);
|
||||
&[data-entering="true"] {
|
||||
--tw-enter-scale: 0.95;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-popover.hv-color-picker__popover:is(
|
||||
[data-entering="true"],
|
||||
[data-exiting="true"]
|
||||
) {
|
||||
@apply motion-reduce:animate-none motion-reduce:transition-none;
|
||||
}
|
||||
@@ -168,3 +168,5 @@
|
||||
|
||||
@import "./components/color-field.css" layer(components);
|
||||
@import "./components/color-input-group.css" layer(components);
|
||||
|
||||
@import "./components/color-picker.css" layer(components);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, shallowRef, type VNode } from "vue";
|
||||
import { useColorState } from "../color/model";
|
||||
import { parseColor, type Color } from "../color/value";
|
||||
import { serializeColorValue } from "../color/submission";
|
||||
import { useChoiceForm } from "../choice/shared";
|
||||
import Popover from "../popover/Popover";
|
||||
import Boundary from "./ColorPickerBoundary";
|
||||
import {
|
||||
colorPickerKey,
|
||||
type ColorPickerProps,
|
||||
type ColorPickerRenderState,
|
||||
} from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
defineSlots<{ default?: (state: ColorPickerRenderState) => VNode[] }>();
|
||||
const props = withDefaults(defineProps<ColorPickerProps>(), {
|
||||
as: "div",
|
||||
open: undefined,
|
||||
isOpen: undefined,
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [Color];
|
||||
change: [Color];
|
||||
changeEnd: [Color];
|
||||
"update:open": [boolean];
|
||||
"update:isOpen": [boolean];
|
||||
openChange: [boolean];
|
||||
}>();
|
||||
const state = useColorState(props, {
|
||||
provide: true,
|
||||
allowEmpty: false,
|
||||
fallback: () => parseColor("#000000"),
|
||||
change: (value) => {
|
||||
if (value) {
|
||||
emit("update:modelValue", value);
|
||||
emit("change", value);
|
||||
}
|
||||
},
|
||||
changeEnd: (value) => {
|
||||
if (value) emit("changeEnd", value);
|
||||
},
|
||||
});
|
||||
provide(colorPickerKey, state);
|
||||
const native = shallowRef<HTMLInputElement>();
|
||||
const color = computed(() => state.value.value ?? parseColor("#000000"));
|
||||
const disabled = state.disabled,
|
||||
readOnly = state.readOnly;
|
||||
const serialized = computed(() => serializeColorValue(color.value));
|
||||
useChoiceForm(native, state.reset, () => {
|
||||
if (native.value) native.value.value = serialized.value;
|
||||
});
|
||||
function openChange(value: boolean) {
|
||||
emit("update:open", value);
|
||||
emit("update:isOpen", value);
|
||||
emit("openChange", value);
|
||||
}
|
||||
defineExpose({ state });
|
||||
</script>
|
||||
<template>
|
||||
<Popover
|
||||
:open="open ?? isOpen"
|
||||
:default-open="defaultOpen"
|
||||
@update:open="openChange"
|
||||
>
|
||||
<Boundary v-slot="overlay">
|
||||
<component
|
||||
:is="as"
|
||||
v-bind="$attrs"
|
||||
class="hv-color-picker"
|
||||
data-slot="color-picker"
|
||||
:data-disabled="disabled || undefined"
|
||||
:data-readonly="readOnly || undefined"
|
||||
>
|
||||
<slot
|
||||
:color="color"
|
||||
:is-open="overlay.isOpen"
|
||||
:close="overlay.close"
|
||||
:is-disabled="disabled"
|
||||
:is-read-only="readOnly"
|
||||
/>
|
||||
<input
|
||||
ref="native"
|
||||
type="hidden"
|
||||
:name="name"
|
||||
:form="form"
|
||||
:disabled="disabled"
|
||||
:value="serialized"
|
||||
/>
|
||||
</component>
|
||||
</Boundary>
|
||||
</Popover>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { defineComponent, watch } from "vue";
|
||||
import { usePopover } from "../popover/context";
|
||||
import { useColorPicker } from "./context";
|
||||
/** Only an accepted close cancels the active color transaction. */
|
||||
export default defineComponent({
|
||||
name: "ColorPickerBoundary",
|
||||
setup(_, { slots }) {
|
||||
const overlay = usePopover(),
|
||||
color = useColorPicker();
|
||||
watch(
|
||||
overlay.state.isOpen,
|
||||
(open) => {
|
||||
if (!open) color.cancel();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
return () =>
|
||||
slots.default?.({
|
||||
isOpen: overlay.state.isOpen.value,
|
||||
close: overlay.state.close,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { useForwardExpose } from "reka-ui";
|
||||
import PopoverContent from "../popover/PopoverContent.vue";
|
||||
import type { OverlayPlacement } from "../overlay/placement";
|
||||
import { useColorPicker } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
as?: string;
|
||||
id?: string;
|
||||
placement?: OverlayPlacement;
|
||||
offset?: number;
|
||||
crossOffset?: number;
|
||||
shouldFlip?: boolean;
|
||||
containerPadding?: number;
|
||||
to?: string | HTMLElement;
|
||||
isNonModal?: boolean;
|
||||
isDismissable?: boolean;
|
||||
isKeyboardDismissDisabled?: boolean;
|
||||
}>(),
|
||||
{
|
||||
as: "div",
|
||||
placement: "bottom left",
|
||||
offset: 8,
|
||||
crossOffset: 0,
|
||||
shouldFlip: true,
|
||||
containerPadding: 12,
|
||||
isNonModal: undefined,
|
||||
isDismissable: true,
|
||||
isKeyboardDismissDisabled: false,
|
||||
},
|
||||
);
|
||||
useColorPicker();
|
||||
const { forwardRef } = useForwardExpose();
|
||||
</script>
|
||||
<template>
|
||||
<PopoverContent
|
||||
:ref="forwardRef"
|
||||
v-bind="{ ...$props, ...$attrs }"
|
||||
class="hv-color-picker__popover"
|
||||
data-slot="color-picker-popover"
|
||||
>
|
||||
<template #default="state"><slot v-bind="state" /></template>
|
||||
</PopoverContent>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { useForwardExpose } from "reka-ui";
|
||||
import PopoverTrigger from "../popover/PopoverTrigger.vue";
|
||||
import { useColorPicker } from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{ as?: string; asChild?: boolean; isDisabled?: boolean }>(),
|
||||
{ as: "button" },
|
||||
);
|
||||
const color = useColorPicker(),
|
||||
disabled = color.disabled;
|
||||
const { forwardRef } = useForwardExpose();
|
||||
</script>
|
||||
<template>
|
||||
<PopoverTrigger
|
||||
:ref="forwardRef"
|
||||
v-bind="$attrs"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:is-disabled="isDisabled || disabled"
|
||||
class="hv-color-picker__trigger"
|
||||
data-slot="color-picker-trigger"
|
||||
>
|
||||
<slot :color="color.value.value" :is-disabled="isDisabled || disabled" />
|
||||
</PopoverTrigger>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
import { inject, type InjectionKey } from "vue";
|
||||
import type { ColorState } from "../color/model";
|
||||
import type { Color, ColorValue } from "../color/value";
|
||||
export interface ColorPickerProps {
|
||||
modelValue?: ColorValue;
|
||||
value?: ColorValue;
|
||||
defaultValue?: ColorValue;
|
||||
open?: boolean;
|
||||
isOpen?: boolean;
|
||||
defaultOpen?: boolean;
|
||||
isDisabled?: boolean;
|
||||
disabled?: boolean;
|
||||
isReadOnly?: boolean;
|
||||
/** Vue extension: opt in to a single full-precision native form value. */
|
||||
name?: string;
|
||||
form?: string;
|
||||
as?: string;
|
||||
}
|
||||
export interface ColorPickerRenderState {
|
||||
color: Color;
|
||||
isOpen: boolean;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
close: () => void;
|
||||
}
|
||||
export const colorPickerKey: InjectionKey<ColorState> =
|
||||
Symbol("hv-color-picker");
|
||||
export function useColorPicker() {
|
||||
const context = inject(colorPickerKey);
|
||||
if (!context) throw new Error("ColorPicker parts require ColorPicker.");
|
||||
return context;
|
||||
}
|
||||
@@ -43,6 +43,8 @@ export function useColorState(
|
||||
options: {
|
||||
fallback: () => Color | null;
|
||||
inherit?: boolean;
|
||||
/** Composite pickers retain their accepted color when an editable child clears. */
|
||||
allowEmpty?: boolean;
|
||||
provide?: boolean;
|
||||
change: (value: Color | null) => void;
|
||||
changeEnd?: (value: Color | null) => void;
|
||||
@@ -93,8 +95,10 @@ export function useColorState(
|
||||
const inherited = computed(
|
||||
() => !!(options.inherit && parent && !ownValue.value),
|
||||
);
|
||||
const value = computed(() =>
|
||||
copyColor(inherited.value ? parent!.value.value : model.value.value),
|
||||
const value = computed(
|
||||
() =>
|
||||
copyColor(inherited.value ? parent!.value.value : model.value.value) ??
|
||||
(options.allowEmpty === false ? options.fallback() : null),
|
||||
);
|
||||
const active = computed(() =>
|
||||
inherited.value ? parent!.active.value : source.value,
|
||||
@@ -123,7 +127,12 @@ export function useColorState(
|
||||
return true;
|
||||
},
|
||||
request(next, token) {
|
||||
if (disabled.value || readOnly.value || (token && active.value !== token))
|
||||
if (
|
||||
(next === null && options.allowEmpty === false) ||
|
||||
disabled.value ||
|
||||
readOnly.value ||
|
||||
(token && active.value !== token)
|
||||
)
|
||||
return false;
|
||||
const copied = copyColor(next);
|
||||
if (inherited.value) return parent!.request(copied, token);
|
||||
|
||||
@@ -35,7 +35,7 @@ root.triggerId = ctx.triggerId;
|
||||
:is-disabled="isDisabled"
|
||||
:activate="ctx.state.toggle"
|
||||
class="hv-popover__trigger"
|
||||
data-slot="popover-trigger"
|
||||
:data-slot="$attrs['data-slot'] ?? 'popover-trigger'"
|
||||
aria-haspopup="dialog"
|
||||
:aria-expanded="ctx.state.isOpen.value"
|
||||
:aria-controls="ctx.state.isOpen.value ? ctx.contentId.value : undefined"
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { defineComponent, watch } from "vue";
|
||||
import { usePopover } from "../../src/components/popover/context";
|
||||
import { useColorStateContext } from "../../src/components/color/model";
|
||||
/** Observe accepted overlay state, never its potentially rejected close proposal. */
|
||||
export default defineComponent({
|
||||
name: "ColorPickerBoundary",
|
||||
setup(_, { slots }) {
|
||||
const overlay = usePopover(),
|
||||
color = useColorStateContext()!;
|
||||
watch(
|
||||
overlay.state.isOpen,
|
||||
(open) => {
|
||||
if (!open) color.cancel();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
return () => slots.default?.();
|
||||
},
|
||||
});
|
||||
+45
-103
@@ -1,122 +1,64 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, shallowRef } from "vue";
|
||||
import {
|
||||
useColorState,
|
||||
type ColorModelProps,
|
||||
} from "../../src/components/color/model";
|
||||
import { serializeColorValue } from "../../src/components/color/submission";
|
||||
import { useChoiceForm } from "../../src/components/choice/shared";
|
||||
import { parseColor, type Color } from "../../src/components/color/value";
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverTrigger,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
} from "../../src/index";
|
||||
import Boundary from "./ColorPickerBoundary";
|
||||
import type { Color } from "../../src/components/color/value";
|
||||
import Picker from "../../src/components/color-picker/ColorPicker.vue";
|
||||
import Trigger from "../../src/components/color-picker/ColorPickerTrigger.vue";
|
||||
import Panel from "../../src/components/color-picker/ColorPickerPopover.vue";
|
||||
import Area from "./ColorAreaFoundation.vue";
|
||||
import Slider from "./ColorSliderFoundation.vue";
|
||||
import ColorField from "../../src/components/color-field/ColorField.vue";
|
||||
import ColorInputGroup from "../../src/components/color-field/ColorInputGroup.vue";
|
||||
import ColorInputGroupInput from "../../src/components/color-field/ColorInputGroupInput.vue";
|
||||
const props = withDefaults(
|
||||
defineProps<
|
||||
ColorModelProps & {
|
||||
name?: string;
|
||||
form?: string;
|
||||
open?: boolean;
|
||||
defaultOpen?: boolean;
|
||||
}
|
||||
>(),
|
||||
{ open: undefined },
|
||||
);
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [Color | null];
|
||||
change: [Color | null];
|
||||
changeEnd: [Color | null];
|
||||
"update:modelValue": [Color];
|
||||
change: [Color];
|
||||
changeEnd: [Color];
|
||||
"update:open": [boolean];
|
||||
}>();
|
||||
const state = useColorState(props, {
|
||||
provide: true,
|
||||
fallback: () => parseColor("hsb(270,0%,50%,.123456789)"),
|
||||
change: (value) => {
|
||||
emit("update:modelValue", value);
|
||||
emit("change", value);
|
||||
},
|
||||
changeEnd: (value) => emit("changeEnd", value),
|
||||
});
|
||||
const native = shallowRef<HTMLInputElement>();
|
||||
const value = state.value,
|
||||
disabled = state.disabled;
|
||||
const serialized = computed(() => serializeColorValue(value.value));
|
||||
useChoiceForm(native, state.reset, () => {
|
||||
if (native.value) native.value.value = serialized.value;
|
||||
});
|
||||
const picker = shallowRef<InstanceType<typeof Picker>>();
|
||||
const state = computed(() => picker.value?.state);
|
||||
const accepted = computed(() =>
|
||||
serializeColorValue(picker.value?.state.value.value ?? null),
|
||||
);
|
||||
defineExpose({ state });
|
||||
</script>
|
||||
<template>
|
||||
<div data-color-picker-composition>
|
||||
<Popover
|
||||
:open="open"
|
||||
:default-open="defaultOpen"
|
||||
<Picker
|
||||
ref="picker"
|
||||
default-value="hsb(270,0%,50%,.123456789)"
|
||||
v-bind="$attrs"
|
||||
v-slot="{ color }"
|
||||
@update:model-value="emit('update:modelValue', $event)"
|
||||
@change="emit('change', $event)"
|
||||
@change-end="emit('changeEnd', $event)"
|
||||
@update:open="emit('update:open', $event)"
|
||||
>
|
||||
<Boundary>
|
||||
<PopoverTrigger as-child>
|
||||
<Button
|
||||
:is-disabled="disabled"
|
||||
variant="secondary"
|
||||
data-color-picker-trigger
|
||||
>
|
||||
<span
|
||||
:style="{
|
||||
width: '20px',
|
||||
height: '20px',
|
||||
borderRadius: '6px',
|
||||
background: value?.toString('css'),
|
||||
}"
|
||||
/>
|
||||
选择颜色
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
placement="bottom start"
|
||||
:style="{ width: '256px' }"
|
||||
data-color-picker-panel
|
||||
>
|
||||
<PopoverDialog
|
||||
aria-label="选择颜色"
|
||||
class="color-picker-composition-panel"
|
||||
>
|
||||
<Area aria-label="Color area" />
|
||||
<Slider channel="hue" aria-label="Color hue" />
|
||||
<Slider channel="alpha" aria-label="Color alpha" />
|
||||
<ColorField channel="alpha" aria-label="Color alpha text">
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
<ColorField aria-label="Color hex text">
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Boundary>
|
||||
</Popover>
|
||||
<input
|
||||
ref="native"
|
||||
type="hidden"
|
||||
:name="name"
|
||||
:form="form"
|
||||
:disabled="disabled"
|
||||
:value="serialized"
|
||||
/>
|
||||
<output data-color-picker-accepted>{{ serialized }}</output>
|
||||
<Trigger data-color-picker-trigger>
|
||||
<span
|
||||
:style="{
|
||||
width: '20px',
|
||||
height: '20px',
|
||||
borderRadius: '6px',
|
||||
background: color.toString('css'),
|
||||
}"
|
||||
/>
|
||||
选择颜色
|
||||
</Trigger>
|
||||
<Panel aria-label="选择颜色" data-color-picker-panel>
|
||||
<Area aria-label="Color area" />
|
||||
<Slider channel="hue" aria-label="Color hue" />
|
||||
<Slider channel="alpha" aria-label="Color alpha" />
|
||||
<ColorField channel="alpha" aria-label="Color alpha text">
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
<ColorField aria-label="Color hex text">
|
||||
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
|
||||
</ColorField>
|
||||
</Panel>
|
||||
</Picker>
|
||||
<output data-color-picker-accepted>{{ accepted }}</output>
|
||||
</div>
|
||||
</template>
|
||||
<style>
|
||||
.color-picker-composition-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// @vitest-environment node
|
||||
import { it, expect } from "vitest";
|
||||
import { createSSRApp, defineComponent } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import Picker from "../packages/vue/src/components/color-picker/ColorPicker.vue";
|
||||
import Trigger from "../packages/vue/src/components/color-picker/ColorPickerTrigger.vue";
|
||||
import Panel from "../packages/vue/src/components/color-picker/ColorPickerPopover.vue";
|
||||
const components = { Picker, Trigger, Panel };
|
||||
it("renders closed Picker SSR without browser globals or premature popup markup", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
components,
|
||||
template:
|
||||
'<Picker v-slot="{color}" name="color"><Trigger aria-label="Choose">{{color.toString("hex")}}</Trigger><Panel aria-label="Color">Popup</Panel></Picker>',
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(html).toContain("#000000");
|
||||
expect(html).toContain('data-slot="color-picker-trigger"');
|
||||
expect(html).toContain('aria-expanded="false"');
|
||||
expect(html).not.toContain('role="dialog"');
|
||||
expect(html.match(/name="color"/g)).toHaveLength(1);
|
||||
expect(html).toContain('value="rgba(0, 0, 0, 1)"');
|
||||
});
|
||||
it("keeps Picker state isolated across server requests and strips disabled submission", async () => {
|
||||
const render = (value: string) =>
|
||||
renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
components,
|
||||
template: `<Picker default-value="${value}" is-disabled name="color"><Trigger>Choose</Trigger></Picker>`,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const [red, blue] = await Promise.all([render("#ff0000"), render("#0000ff")]);
|
||||
expect(red).toContain('value="rgba(255, 0, 0, 1)"');
|
||||
expect(blue).toContain('value="rgba(0, 0, 255, 1)"');
|
||||
expect(red).toMatch(/<input[^>]*disabled/);
|
||||
expect(blue).toMatch(/<button[^>]*disabled/);
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef } from "vue";
|
||||
import Picker from "../packages/vue/src/components/color-picker/ColorPicker.vue";
|
||||
import Trigger from "../packages/vue/src/components/color-picker/ColorPickerTrigger.vue";
|
||||
import Panel from "../packages/vue/src/components/color-picker/ColorPickerPopover.vue";
|
||||
import Field from "../packages/vue/src/components/color-field/ColorField.vue";
|
||||
import Group from "../packages/vue/src/components/color-field/ColorInputGroup.vue";
|
||||
import Input from "../packages/vue/src/components/color-field/ColorInputGroupInput.vue";
|
||||
import { parseColor } from "../packages/vue/src/components/color/value";
|
||||
const components = { Picker, Trigger, Panel, Field, Group, Input };
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
beforeEach(() =>
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
},
|
||||
),
|
||||
);
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
await flushPromises();
|
||||
document.body.innerHTML = "";
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
function view(template: string, setup = () => ({})) {
|
||||
const w = mount(defineComponent({ components, setup, template }), {
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const content =
|
||||
'<Trigger>Choose</Trigger><Panel aria-label="Color"><Field aria-label="Hex"><Group><Input/></Group></Field></Panel>';
|
||||
async function open(w: ReturnType<typeof mount>) {
|
||||
await w.get("button").trigger("click");
|
||||
await flushPromises();
|
||||
}
|
||||
async function edit(value: string) {
|
||||
const input = document.querySelector<HTMLInputElement>('[aria-label="Hex"]')!;
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "Enter",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
return input;
|
||||
}
|
||||
describe("formal ColorPicker owner protocol", () => {
|
||||
it("uses baseline black, exposes accepted slot color and no successful control without a name", () => {
|
||||
const w = view(
|
||||
`<form><Picker v-slot="{ color, isOpen }"><Trigger>{{color.toString('hex')}}/{{isOpen}}</Trigger></Picker></form>`,
|
||||
);
|
||||
expect(w.get("button").text()).toBe("#000000/false");
|
||||
expect([...new FormData(w.get("form").element as HTMLFormElement)]).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(w.get("button").attributes("data-slot")).toBe(
|
||||
"color-picker-trigger",
|
||||
);
|
||||
expect(w.get("button").attributes("type")).toBe("button");
|
||||
});
|
||||
it("ignores a child clear, including the completion event, while standalone fields remain clearable", async () => {
|
||||
const w = view(`<Picker default-value="#123456">${content}</Picker>`);
|
||||
await open(w);
|
||||
const input = await edit("");
|
||||
expect(input.value).toBe("#123456");
|
||||
expect(w.getComponent(Picker).emitted("change")).toBeUndefined();
|
||||
expect(w.getComponent(Picker).emitted("changeEnd")).toBeUndefined();
|
||||
});
|
||||
it("retains parent refusal and retries the same child edit with non-null Color events", async () => {
|
||||
const w = view(`<Picker model-value="#123456">${content}</Picker>`);
|
||||
await open(w);
|
||||
for (let n = 0; n < 2; n++)
|
||||
expect((await edit("#abc")).value).toBe("#123456");
|
||||
expect(w.getComponent(Picker).emitted("change")).toHaveLength(2);
|
||||
expect(w.getComponent(Picker).emitted("change")![0]![0]).toEqual(
|
||||
parseColor("#abc"),
|
||||
);
|
||||
});
|
||||
it("supports explicit external form association and reset with an open Teleport", async () => {
|
||||
const w = view(
|
||||
`<main><form id="external"/><Picker name="color" form="external" default-value="hsba(270,0%,50%,.123456789)">${content}</Picker></main>`,
|
||||
);
|
||||
await open(w);
|
||||
await edit("#abc");
|
||||
const form = w.get("form").element as HTMLFormElement;
|
||||
expect(new FormData(form).getAll("color")).toEqual([
|
||||
"rgba(170, 187, 204, 1)",
|
||||
]);
|
||||
form.reset();
|
||||
await flushPromises();
|
||||
expect(new FormData(form).getAll("color")).toEqual([
|
||||
"hsba(270, 0%, 50%, 0.123456789)",
|
||||
]);
|
||||
expect(
|
||||
document.querySelector<HTMLInputElement>('[aria-label="Hex"]')!.value,
|
||||
).toBe("#808080");
|
||||
expect(document.querySelectorAll("input[name=color]")).toHaveLength(1);
|
||||
});
|
||||
it("cancels native trigger click before activation and preserves attrs on their actual nodes", async () => {
|
||||
const clicked = vi.fn();
|
||||
const w = view(
|
||||
'<Picker id="owner" class="custom-root"><Trigger id="trigger" class="custom-trigger" @click.prevent="clicked">Choose</Trigger><Panel id="panel" aria-label="Color"/></Picker>',
|
||||
() => ({ clicked }),
|
||||
);
|
||||
await open(w);
|
||||
expect(clicked).toHaveBeenCalledTimes(1);
|
||||
expect(document.querySelector("[role=dialog]")).toBeNull();
|
||||
expect(w.get("#owner").classes()).toContain("hv-color-picker");
|
||||
expect(w.get("#trigger").classes()).toContain("custom-trigger");
|
||||
});
|
||||
it("leaves nested Picker owners independent and scopes disabled to its own children", async () => {
|
||||
const w = view(
|
||||
`<form><Picker is-disabled name="outer" default-value="#123456"><Trigger>Outer</Trigger><Picker name="inner" default-value="#abcdef"><Trigger>Inner</Trigger></Picker></Picker></form>`,
|
||||
);
|
||||
const buttons = w.findAll<HTMLButtonElement>("button");
|
||||
expect(buttons[0]!.element.disabled).toBe(true);
|
||||
expect(buttons[1]!.element.disabled).toBe(false);
|
||||
expect(
|
||||
new FormData(w.get("form").element as HTMLFormElement).getAll("inner"),
|
||||
).toEqual(["rgba(171, 205, 239, 1)"]);
|
||||
});
|
||||
it("respects read-only but accepts later programmatic values through the same owner", async () => {
|
||||
const value = shallowRef(parseColor("#123456"));
|
||||
const w = view(
|
||||
`<Picker v-model="value" is-read-only>${content}</Picker>`,
|
||||
() => ({ value }),
|
||||
);
|
||||
await open(w);
|
||||
await edit("#abc");
|
||||
expect(value.value.equals(parseColor("#123456"))).toBe(true);
|
||||
value.value = parseColor("#fedcba");
|
||||
await flushPromises();
|
||||
expect(
|
||||
document.querySelector<HTMLInputElement>('[aria-label="Hex"]')!.value,
|
||||
).toBe("#FEDCBA");
|
||||
});
|
||||
it("keeps controlled open refusal independent from the accepted color", async () => {
|
||||
const w = view(`<Picker :open="false">${content}</Picker>`);
|
||||
await open(w);
|
||||
expect(document.querySelector("[role=dialog]")).toBeNull();
|
||||
expect(w.getComponent(Picker).emitted("update:open")).toEqual([[true]]);
|
||||
expect(w.getComponent(Picker).emitted("change")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -35,3 +35,5 @@ COLOR-01 增加 `consume-color-foundation.mjs`:只验证准备好的 Area CSS
|
||||
COLOR-04 增加 `consume-color-slider-foundation.mjs`,在 `/private/tmp/heroui-color-slider-consumer` 用最终两份 tarball 验证暂存 Slider CSS、端帽变量、公共 Popover 高度/滚动约束与无公共颜色占位导出,同时保留 Calendar/DateField/Select 的 ESM/SSR/CSS 和 strict NodeNext/bundler 正反类型回归。私有 Slider/Picker 的实际交互/SSR/水合在工作区验收,公开组件仍需另写完整产物契约。
|
||||
|
||||
COLOR-06 增加 `consume-color-field-protocol.mjs`,在 `/private/tmp/heroui-color-field-consumer` 验证两份最终 tarball 的字段/输入组暂存 CSS 与没有提前公开占位;同时保留 Calendar/DateField/Select 的 ESM/SSR/CSS 和 strict NodeNext/bundler 类型正反例。组合字段当前内部实现,其 Props/slots 行为与 SSR/水合在工作区测试;COLOR-07 公共批次须补完整产物契约。
|
||||
|
||||
COLOR-08 增加 `consume-color-picker-protocol.mjs`,最终 tarball 在 `/private/tmp/heroui-color-picker-consumer` 验证 Picker CSS 暂存和没有公共占位,保留旧 Calendar/DateField/Select 运行/SSR/CSS 及双解析模式类型契约。Picker 内部三部件已接入组合夹具,公开批次仍须补完整公共 Props/事件/插槽产物验收。
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import * as ui from "@heroui-vue/components";
|
||||
const css = fs.readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of [
|
||||
".hv-color-picker",
|
||||
".hv-color-picker__trigger",
|
||||
".hv-color-picker__popover",
|
||||
"--tw-enter-scale:.95",
|
||||
])
|
||||
assert.ok(css.includes(name), name);
|
||||
for (const name of ["ColorPicker", "ColorPickerTrigger", "ColorPickerPopover"])
|
||||
assert.equal(name in ui, false);
|
||||
console.log(
|
||||
"Picker protocol CSS present; unfinished public exports remain private.",
|
||||
);
|
||||
@@ -72,3 +72,21 @@ const wrongFieldModel: ColorFieldProps = { modelValue: 123 };
|
||||
void field;
|
||||
void wrongValidator;
|
||||
void wrongFieldModel;
|
||||
|
||||
import type { ColorPickerProps } from "../../packages/vue/src/components/color-picker/context";
|
||||
const picker: ColorPickerProps = {
|
||||
modelValue: color,
|
||||
open: false,
|
||||
name: "color",
|
||||
};
|
||||
const emptyPicker: ColorPickerProps = {
|
||||
// @ts-expect-error picker is non-null even when a child field is cleared
|
||||
modelValue: null,
|
||||
};
|
||||
const numericPicker: ColorPickerProps = {
|
||||
// @ts-expect-error numeric color values are not accepted
|
||||
value: 123,
|
||||
};
|
||||
void picker;
|
||||
void emptyPicker;
|
||||
void numericPicker;
|
||||
|
||||
Reference in New Issue
Block a user