feat: publish ColorSwatchPicker and shared swatch picker parts
This commit is contained in:
@@ -182,6 +182,61 @@ for (const id of process.argv.slice(2)) {
|
||||
"ColorSwatch declarations leak Reka types",
|
||||
);
|
||||
}
|
||||
if (id === "color-swatch-picker") {
|
||||
assert(lib.ColorSwatchPicker === lib.ColorSwatchPickerRoot);
|
||||
assert(lib.ColorSwatchPickerItem);
|
||||
assert(lib.ColorSwatchPickerSwatch);
|
||||
assert(lib.ColorSwatchPickerIndicator);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.base()
|
||||
.includes("hv-color-swatch-picker"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants({ layout: "stack", variant: "square" })
|
||||
.base()
|
||||
.includes("hv-color-swatch-picker--stack"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants({ size: "xs" })
|
||||
.item() === "hv-color-swatch-picker__item",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.swatch() === "hv-color-swatch-picker__swatch",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.indicator() === "hv-color-swatch-picker__indicator",
|
||||
);
|
||||
const pickerDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-swatch-picker/ColorSwatchPicker.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
const itemDts = readFileSync(
|
||||
new URL(
|
||||
"./node_modules/@heroui-vue/components/dist/components/color-swatch-picker/ColorSwatchPickerItem.vue.d.ts",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
assert(
|
||||
!pickerDts.includes("reka-ui"),
|
||||
"ColorSwatchPicker declarations leak Reka types",
|
||||
);
|
||||
assert(
|
||||
!itemDts.includes("reka-ui"),
|
||||
"ColorSwatchPickerItem declarations leak Reka types",
|
||||
);
|
||||
}
|
||||
if (id === "color-slider") {
|
||||
assert(lib.ColorSlider === lib.ColorSliderRoot);
|
||||
assert(lib.ColorSliderOutput);
|
||||
|
||||
@@ -372,6 +372,27 @@
|
||||
"repeating-conic-gradient"
|
||||
]
|
||||
},
|
||||
"color-swatch-picker": {
|
||||
"exports": [
|
||||
"ColorSwatchPicker",
|
||||
"ColorSwatchPickerRoot",
|
||||
"ColorSwatchPickerItem",
|
||||
"ColorSwatchPickerSwatch",
|
||||
"ColorSwatchPickerIndicator",
|
||||
"colorSwatchPickerVariants"
|
||||
],
|
||||
"css": [
|
||||
".hv-color-swatch-picker",
|
||||
".hv-color-swatch-picker--stack",
|
||||
".hv-color-swatch-picker--square",
|
||||
".hv-color-swatch-picker--xl",
|
||||
".hv-color-swatch-picker__item",
|
||||
".hv-color-swatch-picker__swatch",
|
||||
".hv-color-swatch-picker__indicator",
|
||||
"data-light-color",
|
||||
"repeating-conic-gradient"
|
||||
]
|
||||
},
|
||||
"time-field": {
|
||||
"exports": [
|
||||
"TimeField",
|
||||
@@ -488,6 +509,6 @@
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorPicker", "ColorSwatchPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
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,
|
||||
];
|
||||
Reference in New Issue
Block a user