import { Listbox, Transition } from "@headlessui/react"; import clsx from "clsx"; import { Fragment } from "react"; import type { IconType } from "react-icons"; import { FaCheck } from "react-icons/fa"; import { HiOutlineChevronUpDown } from "react-icons/hi2"; interface Props { value?: T; onChange?: (value: T | undefined) => void | Promise; items?: T[]; valueMapper?: (item?: T) => string | undefined; icon: IconType; disabled?: boolean; defaultValue: T; } export default function Select(props: Props) { return ( {({ open }) => ( <>
{props.icon({ className: "text-white bg-black rounded-sm ring-2 ring-black", size: "1em", })} {props.valueMapper?.(props.value || props.defaultValue)} {(!props.items || props.items?.length == 0) && (
No options available
)} {props.items?.map((item, i) => ( clsx( active ? "bg-indigo-600 text-white" : "text-gray-900", "relative cursor-default select-none py-2 pl-3 pr-9" ) } value={item} > {({ selected, active }) => ( <>
{props.valueMapper?.(item)}
{selected ? ( ) : null} )}
))}
)}
); }