feat: migrate public ColorPicker composition
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# ColorPicker 独立产物验收
|
||||
|
||||
先运行 `node scripts/check-package.mjs color-picker color-picker-protocol color-foundation color-area color-slider color-field color-field-protocol color-slider-foundation color-swatch color-swatch-picker` 统一构建、打包、安装和类型验收;它会把本夹具放入独立消费者并打印路径和 Vite 命令。按输出显式选空闲端口启动,不另外复制安装流程;入口不会自动启动服务。main.js 只从包根/发布 CSS 导入,不用源码 alias、私有路径或 Vue 模板编译器。
|
||||
|
||||
在真实浏览器核对:
|
||||
|
||||
1. basic:点 Trigger(色块 + 选择颜色)在锚点下方打开弹层,二维取色区域与色相滑块可见可点;键盘/拖动改色后 Trigger 色块与可访问名称同步,Esc 关闭并把焦点还给 Trigger。
|
||||
2. controlled:已选输出与 Trigger 色块跟随接受颜色;弹层内色板预设改色、Hex 字段 Enter 提交改色、随机按钮换色;点弹层外的随机按钮属于外部点击,会先关闭弹层(组件既有弹层行为)。
|
||||
3. 表单:`name="color"` 存在时 FormData 是完整精度颜色(如 `hsba(210.148…, 98.38…%, 96.86…%, 1)`),`form.reset()` 后 FormData、滑块 DOM 值与 Trigger 名称恢复初值;Trigger 是 `type=button`,不会提交表单。受控拒绝/重试与弹层关闭取消事务由 `tests/color-picker-protocol.test.ts`、`tests/color-picker-composition.test.ts` 覆盖。
|
||||
|
||||
记录真实坐标、点击、焦点与截图;不能因 DOM 已挂载或 CSS 文本存在就通过。构建产物还应执行 `vite build`,类型正反例使用上级 `color-picker-contract.ts` 的两种解析模式。
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>ColorPicker 独立产物验收</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,158 @@
|
||||
import { createApp, defineComponent, h, shallowRef } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ColorArea,
|
||||
ColorAreaThumb,
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorPicker,
|
||||
ColorPickerPopover,
|
||||
ColorPickerTrigger,
|
||||
ColorSlider,
|
||||
ColorSliderOutput,
|
||||
ColorSliderThumb,
|
||||
ColorSliderTrack,
|
||||
ColorSwatch,
|
||||
ColorSwatchPicker,
|
||||
ColorSwatchPickerItem,
|
||||
ColorSwatchPickerSwatch,
|
||||
Label,
|
||||
parseColor,
|
||||
} from "@heroui-vue/components";
|
||||
import "@heroui-vue/styles/css";
|
||||
import "./style.css";
|
||||
|
||||
const area = () =>
|
||||
h(
|
||||
ColorArea,
|
||||
{
|
||||
"aria-label": "取色区域",
|
||||
class: "max-w-full",
|
||||
colorSpace: "hsb",
|
||||
xChannel: "saturation",
|
||||
yChannel: "brightness",
|
||||
},
|
||||
{ default: () => h(ColorAreaThumb) },
|
||||
);
|
||||
|
||||
const hueSlider = (label) =>
|
||||
h(
|
||||
ColorSlider,
|
||||
{ "aria-label": label || "色相滑块", channel: "hue", colorSpace: "hsb" },
|
||||
{
|
||||
default: () => [
|
||||
label ? h(Label, null, () => label) : null,
|
||||
h(ColorSliderOutput, { class: "text-muted" }),
|
||||
h(ColorSliderTrack, null, { default: () => h(ColorSliderThumb) }),
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
const trigger = (text) => (state) => [
|
||||
h(ColorSwatch, { size: "lg" }),
|
||||
h(Label, null, () => `${text} ${state.color ? state.color.toString("hex") : ""}`),
|
||||
];
|
||||
|
||||
const Basic = defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h("form", { id: "basic-form" }, [
|
||||
h(
|
||||
ColorPicker,
|
||||
{ defaultValue: "#0485F7", name: "color", style: { width: "max-content" } },
|
||||
{
|
||||
default: () => [
|
||||
h(ColorPickerTrigger, null, { default: trigger("选择颜色") }),
|
||||
h(ColorPickerPopover, { "aria-label": "选择颜色" }, {
|
||||
default: () => [area(), hueSlider("色相")],
|
||||
}),
|
||||
],
|
||||
},
|
||||
),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const presets = [
|
||||
"#ef4444",
|
||||
"#f97316",
|
||||
"#eab308",
|
||||
"#22c55e",
|
||||
"#06b6d4",
|
||||
"#3b82f6",
|
||||
"#8b5cf6",
|
||||
"#ec4899",
|
||||
"#f43f5e",
|
||||
];
|
||||
|
||||
const Controlled = defineComponent({
|
||||
setup() {
|
||||
const color = shallowRef(parseColor("#325578"));
|
||||
return () =>
|
||||
h("div", { class: "stack" }, [
|
||||
h(
|
||||
ColorPicker,
|
||||
{
|
||||
modelValue: color.value,
|
||||
"onUpdate:modelValue": (value) => (color.value = value),
|
||||
style: { width: "max-content" },
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(ColorPickerTrigger, null, { default: trigger("已选颜色") }),
|
||||
h(ColorPickerPopover, { "aria-label": "选择颜色", class: "gap-2" }, {
|
||||
default: () => [
|
||||
h(
|
||||
ColorSwatchPicker,
|
||||
{ class: "justify-center pt-2", size: "xs" },
|
||||
{
|
||||
default: () =>
|
||||
presets.map((preset) =>
|
||||
h(
|
||||
ColorSwatchPickerItem,
|
||||
{ key: preset, color: preset },
|
||||
{ default: () => h(ColorSwatchPickerSwatch) },
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
area(),
|
||||
hueSlider(""),
|
||||
h(
|
||||
ColorField,
|
||||
{ "aria-label": "颜色" },
|
||||
{
|
||||
default: () => [
|
||||
h(ColorFieldGroup, { variant: "secondary" }, {
|
||||
default: () => [
|
||||
h(ColorFieldPrefix, null, {
|
||||
default: () => h(ColorSwatch, { size: "xs" }),
|
||||
}),
|
||||
h(ColorFieldInput),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
),
|
||||
h("output", { id: "controlled-value" }, `已选:${color.value.toString("hex")}`),
|
||||
h(Button, {
|
||||
id: "shuffle",
|
||||
onClick: () => {
|
||||
const hue = Math.floor(Math.random() * 360);
|
||||
color.value = parseColor(`hsl(${hue}, 80%, 50%)`);
|
||||
},
|
||||
}, () => "随机颜色"),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
createApp({
|
||||
render: () => h("main", [h(Basic), h(Controlled)]),
|
||||
}).mount("#app");
|
||||
@@ -0,0 +1,16 @@
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
output {
|
||||
font-family: monospace;
|
||||
}
|
||||
Reference in New Issue
Block a user