feat: add public ColorArea components, docs, and package contract
This commit is contained in:
@@ -90,6 +90,42 @@ for (const id of process.argv.slice(2)) {
|
||||
.base()
|
||||
.includes("hv-select--secondary"),
|
||||
);
|
||||
if (id === "color-area") {
|
||||
assert(lib.ColorArea === lib.ColorAreaRoot);
|
||||
assert(lib.ColorAreaThumb);
|
||||
assert(
|
||||
lib
|
||||
.colorAreaVariants({ showDots: true })
|
||||
.base()
|
||||
.includes("hv-color-area--show-dots"),
|
||||
);
|
||||
assert(
|
||||
lib.colorAreaVariants().thumb() === "hv-color-area__thumb",
|
||||
"ColorArea thumb class must stay in the baseline namespace",
|
||||
);
|
||||
const areaDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-area/ColorArea.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
const thumbDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-area/ColorAreaThumb.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
assert(
|
||||
!areaDts.includes("reka-ui"),
|
||||
"ColorArea declarations leak Reka types",
|
||||
);
|
||||
assert(
|
||||
!thumbDts.includes("reka-ui"),
|
||||
"ColorAreaThumb declarations leak Reka types",
|
||||
);
|
||||
}
|
||||
if (id === "color-swatch") {
|
||||
assert(lib.ColorSwatch === lib.ColorSwatchRoot);
|
||||
assert(
|
||||
|
||||
@@ -110,6 +110,23 @@
|
||||
".hv-calendar-year-picker__year-cell"
|
||||
]
|
||||
},
|
||||
"color-area": {
|
||||
"exports": [
|
||||
"ColorArea",
|
||||
"ColorAreaRoot",
|
||||
"ColorAreaThumb",
|
||||
"colorAreaVariants",
|
||||
"Color",
|
||||
"parseColor"
|
||||
],
|
||||
"css": [
|
||||
".hv-color-area",
|
||||
".hv-color-area--show-dots",
|
||||
".hv-color-area__thumb",
|
||||
"--color-area-background",
|
||||
"--color-area-thumb-color"
|
||||
]
|
||||
},
|
||||
"color-field-protocol": {
|
||||
"exports": [],
|
||||
"css": [
|
||||
@@ -120,24 +137,12 @@
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": [
|
||||
"ColorArea",
|
||||
"ColorSlider",
|
||||
"ColorField",
|
||||
"ColorInputGroup",
|
||||
"ColorPicker"
|
||||
]
|
||||
"absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
},
|
||||
"color-foundation": {
|
||||
"exports": [],
|
||||
"css": [".hv-color-area", ".hv-color-area__thumb"],
|
||||
"absent": [
|
||||
"ColorArea",
|
||||
"ColorSlider",
|
||||
"ColorField",
|
||||
"ColorInputGroup",
|
||||
"ColorPicker"
|
||||
]
|
||||
"absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
},
|
||||
"color-picker-protocol": {
|
||||
"exports": [],
|
||||
@@ -146,13 +151,7 @@
|
||||
".hv-color-picker__trigger",
|
||||
".hv-color-picker__popover"
|
||||
],
|
||||
"absent": [
|
||||
"ColorArea",
|
||||
"ColorSlider",
|
||||
"ColorField",
|
||||
"ColorInputGroup",
|
||||
"ColorPicker"
|
||||
]
|
||||
"absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
},
|
||||
"color-slider-foundation": {
|
||||
"exports": [],
|
||||
@@ -166,13 +165,7 @@
|
||||
"max-height:inherit",
|
||||
"overscroll-behavior:contain"
|
||||
],
|
||||
"absent": [
|
||||
"ColorArea",
|
||||
"ColorSlider",
|
||||
"ColorField",
|
||||
"ColorInputGroup",
|
||||
"ColorPicker"
|
||||
]
|
||||
"absent": ["ColorSlider", "ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
},
|
||||
"date-field": {
|
||||
"exports": [
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import {
|
||||
ColorArea,
|
||||
ColorAreaRoot,
|
||||
ColorAreaThumb,
|
||||
colorAreaVariants,
|
||||
parseColor,
|
||||
type Color,
|
||||
type ColorAreaExpose,
|
||||
type ColorAreaProps,
|
||||
type ColorAreaRenderProps,
|
||||
type ColorAreaRootProps,
|
||||
type ColorAreaSlots,
|
||||
type ColorAreaStyle,
|
||||
type ColorAreaStyleFn,
|
||||
type ColorAreaThumbProps,
|
||||
type ColorAreaThumbRenderProps,
|
||||
type ColorAreaThumbStyle,
|
||||
type ColorAreaThumbStyleFn,
|
||||
type ColorAreaVariants,
|
||||
type ColorAxisChannel,
|
||||
type ColorSpace,
|
||||
type ColorValue,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const color = parseColor("#9B80FF");
|
||||
const value: ColorValue = color;
|
||||
const axis: ColorAxisChannel = "saturation";
|
||||
const space: ColorSpace = "hsb";
|
||||
const style: ColorAreaStyle = { outline: "1px solid black" };
|
||||
const styleFn: ColorAreaStyleFn = ({ color: current }) => ({
|
||||
outline: `1px solid ${current.toString("hex")}`,
|
||||
});
|
||||
const styleRender: ColorAreaStyle = ({ color: current }) => ({
|
||||
background: current.toString("css"),
|
||||
});
|
||||
const thumbStyle: ColorAreaThumbStyle = ({ percent }) => ({
|
||||
opacity: percent.x,
|
||||
});
|
||||
const thumbStyleFn: ColorAreaThumbStyleFn = ({ isDragging }) => ({
|
||||
width: isDragging ? "20px" : "16px",
|
||||
});
|
||||
const props: ColorAreaProps = {
|
||||
modelValue: color,
|
||||
value,
|
||||
defaultValue: "hsb(240, 50%, 50%)",
|
||||
colorSpace: space,
|
||||
xChannel: "hue",
|
||||
yChannel: axis,
|
||||
xName: "hue",
|
||||
yName: "saturation",
|
||||
form: "color-form",
|
||||
isDisabled: false,
|
||||
disabled: false,
|
||||
isReadOnly: false,
|
||||
showDots: true,
|
||||
locale: "zh-CN",
|
||||
dir: "rtl",
|
||||
as: "div",
|
||||
asChild: false,
|
||||
style,
|
||||
styleFn,
|
||||
};
|
||||
const rootProps: ColorAreaRootProps = props;
|
||||
const thumbProps: ColorAreaThumbProps = {
|
||||
as: "span",
|
||||
style: thumbStyle,
|
||||
styleFn: thumbStyleFn,
|
||||
};
|
||||
const slots: ColorAreaSlots = { default: () => null };
|
||||
const variants: ColorAreaVariants = { showDots: true };
|
||||
const render: ColorAreaRenderProps = {
|
||||
color,
|
||||
space: "hsb",
|
||||
x: "hue",
|
||||
y: "saturation",
|
||||
};
|
||||
const thumbRender: ColorAreaThumbRenderProps = {
|
||||
...render,
|
||||
percent: { x: 1, y: 0 },
|
||||
isDragging: false,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
};
|
||||
const exposed: ColorAreaExpose = { element: null, color: null };
|
||||
const typedColor: Color = parseColor("rgb(1, 2, 3)");
|
||||
|
||||
// @ts-expect-error alpha is not a two-dimensional axis
|
||||
const badAxis: ColorAxisChannel = "alpha";
|
||||
// @ts-expect-error the public space set is rgb | hsl | hsb
|
||||
const badSpace: ColorSpace = "lab";
|
||||
// @ts-expect-error showDots only accepts a boolean
|
||||
const badVariant: ColorAreaVariants = { showDots: "yes" };
|
||||
// @ts-expect-error xChannel is a channel name, not an index
|
||||
const badProps: ColorAreaProps = { xChannel: 1 };
|
||||
const badRender: ColorAreaRenderProps = {
|
||||
// @ts-expect-error render props require a Color instance
|
||||
color: "#fff",
|
||||
space: "rgb",
|
||||
x: "red",
|
||||
y: "green",
|
||||
};
|
||||
const badThumb: ColorAreaThumbRenderProps = {
|
||||
...render,
|
||||
// @ts-expect-error the thumb exposes percent, not raw pixel coordinates
|
||||
percent: 1,
|
||||
isDragging: false,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
};
|
||||
|
||||
void [
|
||||
ColorArea,
|
||||
ColorAreaRoot,
|
||||
ColorAreaThumb,
|
||||
colorAreaVariants,
|
||||
value,
|
||||
axis,
|
||||
space,
|
||||
styleRender,
|
||||
props,
|
||||
rootProps,
|
||||
thumbProps,
|
||||
slots,
|
||||
variants,
|
||||
render,
|
||||
thumbRender,
|
||||
exposed,
|
||||
typedColor,
|
||||
badAxis,
|
||||
badSpace,
|
||||
badVariant,
|
||||
badProps,
|
||||
badRender,
|
||||
badThumb,
|
||||
];
|
||||
Reference in New Issue
Block a user