Files

78 lines
2.3 KiB
TypeScript

import {
Select,
SelectRoot,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectClearButton,
SelectPopover,
selectVariants,
type SelectProps,
type SelectValueProps,
type SelectPopoverProps,
type SelectModelValue,
} from "@heroui-vue/components";
const value: SelectModelValue = [0, "0", ""];
const props: SelectProps = {
modelValue: value,
selectionMode: "multiple",
variant: "secondary",
autoComplete: "country",
items: [{ id: 0, textValue: "Zero" }],
onChange: (next) => {
if (Array.isArray(next)) next.forEach((key) => String(key));
},
validate: (next) => (next === null ? "Required" : undefined),
onOpenChange: (open) => Boolean(open),
};
const part: SelectValueProps = { as: "span" };
const popup: SelectPopoverProps = { placement: "bottom start", offset: 8 };
// @ts-expect-error Keys are strings or numbers, never objects
const badValue: SelectProps = { modelValue: { id: 0 } };
// @ts-expect-error Selection mode is constrained
const badMode: SelectProps = { selectionMode: "checkbox" };
// @ts-expect-error Variants are constrained
const badVariant: SelectProps = { variant: "solid" };
// @ts-expect-error Metadata text is required
const badItems: SelectProps = { items: [{ id: 0 }] };
// @ts-expect-error Model listener receives SelectModelValue, not boolean
const badEvent: SelectProps = { onChange: (value: boolean) => value };
// @ts-expect-error Popover placement is constrained
const badPlacement: SelectPopoverProps = { placement: "diagonal" };
const badComponent: InstanceType<typeof Select>["$props"] = {
// @ts-expect-error Generated component props are also constrained
modelValue: [false],
};
void [
Select,
SelectRoot,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectClearButton,
SelectPopover,
selectVariants,
props,
part,
popup,
badValue,
badMode,
badVariant,
badItems,
badEvent,
badPlacement,
badComponent,
];
type RootSlot = Parameters<
NonNullable<InstanceType<typeof Select>["$slots"]["default"]>
>[0];
const slotState: RootSlot = {
value: 0,
isOpen: false,
selectedItems: [{ key: 0, textValue: "Zero" }],
};
const selectedKey: string | number = slotState.selectedItems[0].key;
// @ts-expect-error Root scoped slot keys must retain their actual type
const booleanKey: boolean = slotState.selectedItems[0].key;
void [selectedKey, booleanKey];