feat: publish ColorField and shared color input parts
This commit is contained in:
@@ -44,6 +44,26 @@ for (const id of process.argv.slice(2)) {
|
||||
assert(lib.RangeCalendar === lib.RangeCalendarRoot);
|
||||
assert(lib.rangeCalendarVariants().cell() === "hv-range-calendar__cell");
|
||||
}
|
||||
if (id === "color-field") {
|
||||
assert(lib.ColorField === lib.ColorFieldRoot);
|
||||
assert(lib.ColorFieldGroup === lib.ColorInputGroup);
|
||||
assert(lib.ColorFieldGroup === lib.ColorInputGroupRoot);
|
||||
assert(lib.ColorFieldInput === lib.ColorInputGroupInput);
|
||||
assert(lib.ColorFieldPrefix === lib.ColorInputGroupPrefix);
|
||||
assert(lib.ColorFieldSuffix === lib.ColorInputGroupSuffix);
|
||||
assert(
|
||||
lib
|
||||
.colorFieldVariants({ fullWidth: true })
|
||||
.includes("hv-color-field--full-width"),
|
||||
);
|
||||
const slots = lib.colorInputGroupVariants({
|
||||
variant: "secondary",
|
||||
fullWidth: true,
|
||||
});
|
||||
assert(slots.base().includes("hv-color-input-group--secondary"));
|
||||
assert(slots.base().includes("hv-color-input-group--full-width"));
|
||||
assert(slots.input() === "hv-color-input-group__input");
|
||||
}
|
||||
if (id === "time-field") {
|
||||
assert(lib.TimeField === lib.TimeFieldRoot);
|
||||
assert(lib.TimeFieldGroup === lib.DateInputGroup);
|
||||
|
||||
@@ -137,12 +137,12 @@
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-foundation": {
|
||||
"exports": [],
|
||||
"css": [".hv-color-area", ".hv-color-area__thumb"],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-picker-protocol": {
|
||||
"exports": [],
|
||||
@@ -151,7 +151,7 @@
|
||||
".hv-color-picker__trigger",
|
||||
".hv-color-picker__popover"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"color-slider-foundation": {
|
||||
"exports": [],
|
||||
@@ -165,7 +165,7 @@
|
||||
"max-height:inherit",
|
||||
"overscroll-behavior:contain"
|
||||
],
|
||||
"absent": ["ColorField", "ColorInputGroup", "ColorPicker"]
|
||||
"absent": ["ColorPicker"]
|
||||
},
|
||||
"date-field": {
|
||||
"exports": [
|
||||
@@ -462,5 +462,32 @@
|
||||
"--track-start-color",
|
||||
"--track-end-color"
|
||||
]
|
||||
},
|
||||
"color-field": {
|
||||
"exports": [
|
||||
"ColorField",
|
||||
"ColorFieldRoot",
|
||||
"ColorFieldGroup",
|
||||
"ColorFieldInput",
|
||||
"ColorFieldPrefix",
|
||||
"ColorFieldSuffix",
|
||||
"ColorInputGroup",
|
||||
"ColorInputGroupRoot",
|
||||
"ColorInputGroupInput",
|
||||
"ColorInputGroupPrefix",
|
||||
"ColorInputGroupSuffix",
|
||||
"colorFieldVariants",
|
||||
"colorInputGroupVariants"
|
||||
],
|
||||
"css": [
|
||||
".hv-color-field",
|
||||
".hv-color-field--full-width",
|
||||
".hv-color-input-group",
|
||||
".hv-color-input-group--secondary",
|
||||
".hv-color-input-group__input",
|
||||
".hv-color-input-group__prefix",
|
||||
".hv-color-input-group__suffix"
|
||||
],
|
||||
"absent": ["ColorPicker", "ColorSwatchPicker"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldRoot,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorFieldSuffix,
|
||||
ColorInputGroup,
|
||||
ColorInputGroupRoot,
|
||||
ColorInputGroupInput,
|
||||
ColorInputGroupPrefix,
|
||||
ColorInputGroupSuffix,
|
||||
colorFieldVariants,
|
||||
colorInputGroupVariants,
|
||||
parseColor,
|
||||
type ColorFieldProps,
|
||||
type ColorFieldRootProps,
|
||||
type ColorFieldGroupProps,
|
||||
type ColorFieldInputProps,
|
||||
type ColorFieldPrefixProps,
|
||||
type ColorFieldSuffixProps,
|
||||
type ColorFieldRenderProps,
|
||||
type ColorFieldRenderState,
|
||||
type ColorFieldSlots,
|
||||
type ColorFieldExpose,
|
||||
type ColorFieldVariants,
|
||||
type ColorInputGroupVariants,
|
||||
type ColorInputGroupProps,
|
||||
type ColorInputGroupInputProps,
|
||||
type ColorInputGroupRootProps,
|
||||
type ColorInputGroupPrefixProps,
|
||||
type ColorInputGroupSuffixProps,
|
||||
type ColorInputGroupRenderProps,
|
||||
} from "@heroui-vue/components";
|
||||
const props: ColorFieldProps = {
|
||||
modelValue: parseColor("#123456"),
|
||||
value: null,
|
||||
defaultValue: "#abcdef",
|
||||
channel: "hue",
|
||||
colorSpace: "hsb",
|
||||
name: "hue",
|
||||
form: "external",
|
||||
isRequired: true,
|
||||
isReadOnly: false,
|
||||
isWheelDisabled: true,
|
||||
locale: "de-DE",
|
||||
validate: (color) => (color ? true : "必填"),
|
||||
styleFn: (s) => ({ opacity: s.isFocused ? 0.5 : 1 }),
|
||||
};
|
||||
const root: ColorFieldRootProps = props;
|
||||
const group: ColorFieldGroupProps = {
|
||||
variant: "secondary",
|
||||
styleFn: (s) => ({ opacity: s.isFocusWithin ? 1 : 0.5 }),
|
||||
};
|
||||
const ig: ColorInputGroupProps = group;
|
||||
const igr: ColorInputGroupRootProps = ig;
|
||||
const input: ColorFieldInputProps = { defaultValue: "abc" };
|
||||
const ii: ColorInputGroupInputProps = input;
|
||||
const prefix: ColorFieldPrefixProps = { as: "span" };
|
||||
const ip: ColorInputGroupPrefixProps = prefix;
|
||||
const suffix: ColorFieldSuffixProps = { as: "span" };
|
||||
const is: ColorInputGroupSuffixProps = suffix;
|
||||
const slots: ColorFieldSlots = {
|
||||
default: (s) => [h("span", s.value?.toString("hex"))],
|
||||
};
|
||||
const state: ColorFieldRenderProps = {
|
||||
value: null,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isRequired: false,
|
||||
isInvalid: false,
|
||||
isFocused: false,
|
||||
isFocusWithin: false,
|
||||
isFocusVisible: false,
|
||||
validationErrors: [],
|
||||
};
|
||||
const renderState: ColorFieldRenderState = state;
|
||||
const gs: ColorInputGroupRenderProps = {
|
||||
isDisabled: false,
|
||||
isInvalid: false,
|
||||
isFocusWithin: false,
|
||||
isHovered: false,
|
||||
};
|
||||
const variant: ColorFieldVariants = { fullWidth: true };
|
||||
const iv: ColorInputGroupVariants = { variant: "secondary" };
|
||||
colorFieldVariants(variant);
|
||||
colorInputGroupVariants(iv).input();
|
||||
h(ColorField, {
|
||||
...props,
|
||||
"onUpdate:modelValue": (value) => value?.toString("hex"),
|
||||
});
|
||||
h(ColorFieldRoot, root);
|
||||
h(ColorFieldGroup, group);
|
||||
h(ColorFieldInput, input);
|
||||
h(ColorFieldPrefix, prefix);
|
||||
h(ColorFieldSuffix, suffix);
|
||||
h(ColorInputGroup, ig);
|
||||
h(ColorInputGroupRoot, igr);
|
||||
h(ColorInputGroupInput, ii);
|
||||
h(ColorInputGroupPrefix, ip);
|
||||
h(ColorInputGroupSuffix, is);
|
||||
declare const field: InstanceType<typeof ColorField>;
|
||||
field.focus();
|
||||
field.element?.select();
|
||||
field.color?.toString("hex");
|
||||
const exposed: ColorFieldExpose = field;
|
||||
declare const control: InstanceType<typeof ColorFieldInput>;
|
||||
control.focus();
|
||||
control.select();
|
||||
control.element?.select();
|
||||
// @ts-expect-error invalid model
|
||||
const bad: ColorFieldProps = { modelValue: 123 };
|
||||
// @ts-expect-error invalid channel
|
||||
const badChannel: ColorFieldProps = { channel: "cyan" };
|
||||
// @ts-expect-error invalid color space
|
||||
h(ColorField, { colorSpace: "oklch" });
|
||||
// @ts-expect-error actual public component rejects invalid model
|
||||
h(ColorField, { modelValue: 123 });
|
||||
// @ts-expect-error variant is primary or secondary
|
||||
const badGroup: ColorFieldGroupProps = { variant: "tertiary" };
|
||||
// @ts-expect-error validators receive Color/null
|
||||
const badValidator: ColorFieldProps = { validate: (v: string) => true };
|
||||
// @ts-expect-error no public transaction state
|
||||
field.state.begin();
|
||||
void [slots, renderState, gs, exposed, bad, badChannel, badGroup, badValidator];
|
||||
Reference in New Issue
Block a user