138 lines
3.8 KiB
TypeScript
138 lines
3.8 KiB
TypeScript
import { h } from "vue";
|
|
import {
|
|
ColorSwatchPicker,
|
|
ColorSwatchPickerRoot,
|
|
ColorSwatchPickerItem,
|
|
ColorSwatchPickerSwatch,
|
|
ColorSwatchPickerIndicator,
|
|
colorSwatchPickerVariants,
|
|
parseColor,
|
|
type ColorSwatchPickerProps,
|
|
type ColorSwatchPickerRootProps,
|
|
type ColorSwatchPickerItemProps,
|
|
type ColorSwatchPickerSwatchProps,
|
|
type ColorSwatchPickerIndicatorProps,
|
|
type ColorSwatchPickerExpose,
|
|
type ColorSwatchPickerItemExpose,
|
|
type ColorSwatchPickerItemRenderProps,
|
|
type ColorSwatchPickerItemSlots,
|
|
type ColorSwatchPickerIndicatorSlots,
|
|
type ColorSwatchPickerLayout,
|
|
type ColorSwatchPickerRenderProps,
|
|
type ColorSwatchPickerShape,
|
|
type ColorSwatchPickerSize,
|
|
type ColorSwatchPickerSlots,
|
|
type ColorSwatchPickerVariants,
|
|
} from "@heroui-vue/components";
|
|
|
|
const props: ColorSwatchPickerProps = {
|
|
modelValue: parseColor("#123456"),
|
|
value: "#abcdef",
|
|
defaultValue: null,
|
|
layout: "stack",
|
|
size: "xl",
|
|
variant: "square",
|
|
isDisabled: false,
|
|
disabled: false,
|
|
isReadOnly: true,
|
|
dir: "rtl",
|
|
as: "div",
|
|
};
|
|
const root: ColorSwatchPickerRootProps = props;
|
|
const item: ColorSwatchPickerItemProps = {
|
|
color: "hsl(210, 100%, 50%)",
|
|
isDisabled: true,
|
|
as: "div",
|
|
};
|
|
const swatch: ColorSwatchPickerSwatchProps = {
|
|
color: parseColor("#f008"),
|
|
colorName: "海洋蓝",
|
|
as: "span",
|
|
};
|
|
const indicator: ColorSwatchPickerIndicatorProps = { as: "span" };
|
|
const slots: ColorSwatchPickerSlots = {
|
|
default: (s) => [h("span", {}, [s.color?.toString("hex"), String(s.layout)])],
|
|
};
|
|
const itemSlots: ColorSwatchPickerItemSlots = {
|
|
default: (s: ColorSwatchPickerItemRenderProps) => [
|
|
h("span", s.isSelected ? s.color.toString("hexa") : "none"),
|
|
],
|
|
};
|
|
const indicatorSlots: ColorSwatchPickerIndicatorSlots = itemSlots;
|
|
const state: ColorSwatchPickerRenderProps = {
|
|
color: null,
|
|
isEmpty: false,
|
|
isDisabled: false,
|
|
isReadOnly: false,
|
|
isFocused: false,
|
|
layout: "grid",
|
|
};
|
|
const itemState: ColorSwatchPickerItemRenderProps = {
|
|
color: parseColor("#8B5CF6"),
|
|
isSelected: true,
|
|
isDisabled: false,
|
|
isFocused: true,
|
|
isFocusVisible: true,
|
|
isPressed: false,
|
|
isHovered: false,
|
|
};
|
|
const variant: ColorSwatchPickerVariants = {
|
|
layout: "grid",
|
|
size: "md",
|
|
variant: "circle",
|
|
};
|
|
const layout: ColorSwatchPickerLayout = "stack";
|
|
const size: ColorSwatchPickerSize = "xs";
|
|
const shape: ColorSwatchPickerShape = "square";
|
|
colorSwatchPickerVariants(variant).swatch();
|
|
|
|
h(ColorSwatchPicker, {
|
|
...props,
|
|
"onUpdate:modelValue": (value) => value.toString("hex"),
|
|
onChange: (value) => value.toString("hexa"),
|
|
});
|
|
h(ColorSwatchPickerRoot, root);
|
|
h(ColorSwatchPickerItem, item);
|
|
h(ColorSwatchPickerSwatch, swatch);
|
|
h(ColorSwatchPickerIndicator, indicator);
|
|
declare const picker: InstanceType<typeof ColorSwatchPicker>;
|
|
picker.focus();
|
|
picker.element?.focus();
|
|
const exposed: ColorSwatchPickerExpose = picker;
|
|
declare const row: InstanceType<typeof ColorSwatchPickerItem>;
|
|
row.element?.focus();
|
|
const itemExposed: ColorSwatchPickerItemExpose = row;
|
|
|
|
// @ts-expect-error invalid model
|
|
const bad: ColorSwatchPickerProps = { modelValue: 123 };
|
|
// @ts-expect-error invalid layout
|
|
const badLayout: ColorSwatchPickerProps = { layout: "carousel" };
|
|
// @ts-expect-error invalid size
|
|
const badSize: ColorSwatchPickerProps = { size: "huge" };
|
|
// @ts-expect-error invalid variant
|
|
h(ColorSwatchPicker, { variant: "pill" });
|
|
// @ts-expect-error actual public component rejects invalid model
|
|
h(ColorSwatchPicker, { modelValue: 123 });
|
|
// @ts-expect-error item color must be a color value
|
|
const badColor: ColorSwatchPickerItemProps = { color: 123 };
|
|
// @ts-expect-error no public transaction or owner state
|
|
picker.state.begin();
|
|
// @ts-expect-error item state is exposed through slots only
|
|
row.selectedKeys;
|
|
void [
|
|
slots,
|
|
itemSlots,
|
|
indicatorSlots,
|
|
state,
|
|
itemState,
|
|
exposed,
|
|
itemExposed,
|
|
bad,
|
|
badLayout,
|
|
badSize,
|
|
badColor,
|
|
layout,
|
|
size,
|
|
shape,
|
|
];
|