(props: {
title?: string;
options: SelectBoxOption[];
selected: string | null;
setSelected: (selected: string) => void;
theme?: "light" | "dark";
size?: "small" | "base";
includeNull?: boolean;
})
| 11 | } |
| 12 | |
| 13 | export default function SelectBox(props: { |
| 14 | title?: string; |
| 15 | options: SelectBoxOption[]; |
| 16 | selected: string | null; |
| 17 | setSelected: (selected: string) => void; |
| 18 | theme?: "light" | "dark"; |
| 19 | size?: "small" | "base"; |
| 20 | includeNull?: boolean; |
| 21 | }) { |
| 22 | /** |
| 23 | * selected: the id of the selected option |
| 24 | * setSelected: a function that takes the id of the selected option |
| 25 | */ |
| 26 | // Defaults |
| 27 | const theme = props.theme ?? "light"; |
| 28 | const size = props.size ?? "small"; |
| 29 | |
| 30 | return ( |
| 31 | <Listbox value={props.selected} onChange={props.setSelected}> |
| 32 | {({ open }) => ( |
| 33 | <> |
| 34 | {props.title && ( |
| 35 | <Listbox.Label |
| 36 | className={classNames( |
| 37 | "block font-medium leading-6", |
| 38 | theme === "light" ? "text-gray-700" : "text-gray-200", |
| 39 | size === "small" ? "text-sm" : size === "base" && "text-base", |
| 40 | )} |
| 41 | > |
| 42 | {props.title} |
| 43 | </Listbox.Label> |
| 44 | )} |
| 45 | <div className="relative flex-1"> |
| 46 | <Listbox.Button |
| 47 | className={classNames( |
| 48 | "relative w-full cursor-default rounded-md py-1.5 pl-3 pr-10 text-left shadow-sm ring-1 ring-inset focus:outline-none focus:ring-2 focus:ring-purple-600 sm:leading-6", |
| 49 | theme === "light" |
| 50 | ? "bg-gray-50 text-gray-900 ring-purple-300" |
| 51 | : props.selected === null |
| 52 | ? "bg-gray-700 text-gray-400 ring-gray-300" |
| 53 | : "bg-gray-700 text-gray-300 ring-gray-400", |
| 54 | size === "small" |
| 55 | ? "text-sm py-1.5" |
| 56 | : size === "base" && "text-base py-[0.6875rem]", |
| 57 | )} |
| 58 | > |
| 59 | <div className="flex flex-row place-items-center gap-x-1"> |
| 60 | {props.options.find((o) => props.selected === o.id)?.icon} |
| 61 | <span className="block truncate"> |
| 62 | {props.options.find((o) => props.selected === o.id)?.name ?? |
| 63 | "Select an option"} |
| 64 | </span> |
| 65 | </div> |
| 66 | <span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"> |
| 67 | <ChevronUpDownIcon |
| 68 | className="h-5 w-5 text-gray-400" |
| 69 | aria-hidden="true" |
| 70 | /> |
nothing calls this directly
no test coverage detected