import { For, Show, type JSX, splitProps, type ComponentProps } from "solid-js"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { IconCheck, IconChevronDown } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; export type SelectOption = { value: T; label: string; icon?: JSX.Element; }; export type DropdownSelectProps = { options: SelectOption[]; value: T; onChange: (value: T) => void; placeholder?: string; labelPrefix?: string; class?: string; triggerClass?: string; disabled?: boolean; }; export function DropdownSelect(props: DropdownSelectProps) { const selectedOption = () => props.options.find((opt) => opt.value === props.value); const displayLabel = () => selectedOption()?.label ?? props.placeholder ?? ""; return (
{props.labelPrefix}: {selectedOption()!.icon} {displayLabel()}
{(option) => { const isSelected = () => option.value === props.value; return ( props.onChange(option.value)} >
{option.icon} {option.label}
); }}
); } export type SelectProps = ComponentProps<"select"> & { wrapperClass?: string; }; export function Select(props: SelectProps) { const [local, rest] = splitProps(props, ["class", "wrapperClass"]); return (