feat: migrate ColorSwatch and public color boundary

This commit is contained in:
maoyingjie
2026-10-26 13:25:21 +08:00
parent 60af6ee40b
commit 270dea5cff
29 changed files with 1427 additions and 18 deletions
+36
View File
@@ -49,6 +49,42 @@ for (const id of process.argv.slice(2)) {
.base()
.includes("hv-select--secondary"),
);
if (id === "color-swatch") {
assert(lib.ColorSwatch === lib.ColorSwatchRoot);
assert(
lib
.colorSwatchVariants({ shape: "square", size: "xl" })
.includes("hv-color-swatch--square"),
);
assert(
lib
.colorSwatchVariants({ shape: "square", size: "xl" })
.includes("hv-color-swatch--xl"),
);
assert(lib.parseColor("#f008").toString("hexa") === "#FF000088");
assert(
lib.parseColor("rgba(4, 133, 247, 0.5)").getChannelValue("alpha") === 0.5,
);
const valueDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color/value.d.ts",
import.meta.url,
),
"utf8",
);
const swatchDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-swatch/ColorSwatch.vue.d.ts",
import.meta.url,
),
"utf8",
);
assert(!valueDts.includes("reka-ui"), "Color declarations leak Reka types");
assert(
!swatchDts.includes("reka-ui"),
"ColorSwatch declarations leak Reka types",
);
}
if (id === "b03-tag-error-message") {
assert(/\.hv-tag-group\s*\[data-slot=["']?error-message/.test(css));
assert(lib.tagVariants({ size: "sm" }).base().includes("hv-tag--sm"));
+17
View File
@@ -337,5 +337,22 @@
"sliderVariants"
],
"css": [".hv-slider__track", "hv-slider__thumb"]
},
"color-swatch": {
"exports": [
"ColorSwatch",
"ColorSwatchRoot",
"colorSwatchVariants",
"Color",
"parseColor"
],
"css": [
".hv-color-swatch",
".hv-color-swatch--circle",
".hv-color-swatch--square",
".hv-color-swatch--xs",
".hv-color-swatch--xl",
"repeating-conic-gradient"
]
}
}
+87
View File
@@ -0,0 +1,87 @@
import {
Color,
ColorSwatch,
ColorSwatchRoot,
colorSwatchVariants,
parseColor,
type ColorChannel,
type ColorInput,
type ColorSpace,
type ColorSwatchProps,
type ColorSwatchRenderProps,
type ColorSwatchRootProps,
type ColorSwatchSlots,
type ColorSwatchStyle,
type ColorSwatchStyleFn,
type ColorValue,
} from "@heroui-vue/components";
const color = parseColor("#0485F7");
const value: ColorValue = color;
const format: ColorSpace = "hsl";
const channel: ColorChannel = "alpha";
const input: ColorInput = { space: "rgb", r: 4, g: 133, b: 247, alpha: 1 };
const constructed = new Color(input);
const style: ColorSwatchStyle = { outline: "1px solid black" };
const styleFn: ColorSwatchStyleFn = ({ color: current }) => ({
background: current.toString("css"),
});
const styleRender: ColorSwatchStyle = ({ color: current }) => ({
background: current.toString("css"),
});
const props: ColorSwatchProps = {
color,
colorName: "海洋蓝",
shape: "square",
size: "xl",
as: "div",
asChild: false,
style,
styleFn,
};
const rootProps: ColorSwatchRootProps = props;
const inlineStyle: ColorSwatchProps = {
color: "#0485F7",
style: ({ color: current }) => ({ background: current.toString("css") }),
};
const slots: ColorSwatchSlots = {
default: ({ color: current }: ColorSwatchRenderProps) =>
current.toString("hex"),
};
// @ts-expect-error shape is constrained to circle | square
const badShape: ColorSwatchProps = { shape: "pill" };
// @ts-expect-error size is constrained to the baseline set
const badSize: ColorSwatchProps = { size: "xxl" };
// @ts-expect-error color accepts strings, Color or null
const badColor: ColorSwatchProps = { color: 42 };
// @ts-expect-error ColorChannel is the public channel union
const badChannel: ColorChannel = "yellow";
// @ts-expect-error ColorSpace is limited to rgb | hsl | hsb
const badSpace: ColorSpace = "lab";
// @ts-expect-error ColorInput requires the space discriminator
const badInput: ColorInput = { r: 1, g: 2, b: 3, alpha: 1 };
// @ts-expect-error withAlpha accepts a number
const badAlpha = color.withAlpha("0.5");
void [
ColorSwatch,
ColorSwatchRoot,
colorSwatchVariants,
value,
format,
channel,
constructed,
props,
rootProps,
styleRender,
inlineStyle,
slots,
badShape,
badSize,
badColor,
badChannel,
badSpace,
badInput,
badAlpha,
];