feat: add public ColorArea components, docs, and package contract

This commit is contained in:
maoyingjie
2026-10-26 23:51:31 +08:00
parent 01882160e6
commit ae364578ce
33 changed files with 2201 additions and 151 deletions
+135
View File
@@ -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,
];