import { Fragment, useState } from "react"; import { Listbox, Transition } from "@headlessui/react"; import { faCheck, faChevronDown } from "@fortawesome/pro-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; export type SelectValue = string | number; export type SelectOption = { label: string; value: SelectValue }; interface ListDropdownProps { options: SelectOption[]; onChange: (val: string) => void; placeholder?: string; value: SelectValue; } export const Select = ({ onChange, options, placeholder, value, }: ListDropdownProps) => { const selectedOption = options.find( (option: SelectOption) => option.value === value, ) || { label: placeholder || "", value: "" }; return (
{selectedOption.label} {options.map((option, itemIdx) => ( `relative cursor-pointer select-none py-2 pl-10 pr-4 text-white ${ active ? "text-white" : "text-gray-400" }` } value={option.value}> {({ selected }) => ( <> {option.label} {selected ? ( ) : null} )} ))}
); };