import { Listbox } from "@headlessui/react"; import React, { Fragment } from "react"; import { Icon, Icons } from "@/components/Icon"; import { Transition } from "@/components/utils/Transition"; export interface OptionItem { id: string; name: string; leftIcon?: React.ReactNode; } interface DropdownProps { selectedItem: OptionItem; setSelectedItem: (value: OptionItem) => void; options: Array; direction?: "up" | "down"; side?: "left" | "right"; customButton?: React.ReactNode; customMenu?: React.ReactNode; className?: string; preventWrap?: boolean; } export function Dropdown(props: DropdownProps) { const { direction = "down", customButton, customMenu } = props; return (
{({ open }) => ( <> {customButton ? ( {customButton} ) : ( {props.selectedItem.leftIcon ? props.selectedItem.leftIcon : null} {props.selectedItem.name} )} {customMenu ? ( {customMenu} ) : ( {props.options.map((opt) => ( `cursor-pointer flex gap-4 items-center relative select-none py-2 px-4 mx-1 rounded-lg ${ active ? "bg-background-secondaryHover text-type-link" : "text-type-secondary" } ${props.preventWrap ? "whitespace-nowrap" : ""}` } key={opt.id} value={opt} > {opt.leftIcon ? opt.leftIcon : null} {opt.name} ))} )} )}
); }