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; field.focus(); field.element?.select(); field.color?.toString("hex"); const exposed: ColorFieldExpose = field; declare const control: InstanceType; 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];