fix: enforce ColorSlider union props and clean part refs

This commit is contained in:
maoyingjie
2026-10-27 10:23:10 +08:00
parent 92eb59e389
commit ea881cbcf8
9 changed files with 221 additions and 62 deletions
+29
View File
@@ -1,3 +1,4 @@
import { h } from "vue";
import {
ColorSlider,
ColorSliderOutput,
@@ -140,6 +141,30 @@ const exposed: ColorSliderExpose = {
focus: () => {},
};
const typedColor: Color = color;
type ColorSliderInstanceProps = InstanceType<typeof ColorSlider>["$props"];
const instanceProps: ColorSliderInstanceProps = {
channel: "hue",
colorSpace: "hsb",
};
// @ts-expect-error the component's own props reject red + hsl
const badInstanceRed: ColorSliderInstanceProps = {
channel: "red",
colorSpace: "hsl",
};
// @ts-expect-error the component's own props reject hue + rgb
const badInstanceHue: ColorSliderInstanceProps = {
channel: "hue",
colorSpace: "rgb",
};
const sliderNode = h(ColorSlider, {
channel: "hue",
colorSpace: "hsb",
defaultValue: "hsb(240, 50%, 50%)",
});
// @ts-expect-error h() rejects red + hsl on the real component
h(ColorSlider, { channel: "red", colorSpace: "hsl" });
// @ts-expect-error h() rejects hue + rgb on the real component
h(ColorSlider, { channel: "hue", colorSpace: "rgb" });
// @ts-expect-error red requires the rgb color space
const badRed: ColorSliderProps = { channel: "red", colorSpace: "hsl" };
@@ -219,6 +244,10 @@ void [
variants,
exposed,
typedColor,
instanceProps,
badInstanceRed,
badInstanceHue,
sliderNode,
badRed,
badHue,
badBrightness,