diff --git a/src/components/dropdowns/Dropdown.tsx b/src/components/dropdowns/Dropdown.tsx index 005e010..69015e9 100644 --- a/src/components/dropdowns/Dropdown.tsx +++ b/src/components/dropdowns/Dropdown.tsx @@ -1,5 +1,4 @@ import { - Label, Listbox, ListboxButton, ListboxOption, @@ -10,35 +9,37 @@ import { CheckIcon } from "@heroicons/react/20/solid/index"; import { clsx } from "clsx"; import { Fragment } from "react"; -interface Props { - item: string; - options: readonly string[]; - onChange: (option: string) => void; - label?: string; - icon: JSX.Element; +type Item = { label: string; value: T }; + +interface Props { + item: Item; + options: Item[]; + onChange: (option: T) => void; + leftIcon?: JSX.Element; + rightIcon?: JSX.Element; } -export const Dropdown = ({ item, options, icon, onChange, label }: Props) => { +export function Dropdown({ + item, + options, + onChange, + leftIcon, + rightIcon, +}: Props) { return ( option !== item && onChange(option)} + onChange={(option) => + option.value !== item.value && onChange(option.value) + } > {({ open }) => (
- {label && ( - - )}
- - - {item} - - - {icon} - + + {leftIcon && {leftIcon}} + {item.label} + {rightIcon && {rightIcon}} { leaveTo="opacity-0" > - {options.map((option) => ( + {options.map((option, index) => ( @@ -65,14 +66,14 @@ export const Dropdown = ({ item, options, icon, onChange, label }: Props) => { "block truncate", )} > - {option} + {option.label} - {selected ? ( + {selected && ( - ) : null} + )} )} @@ -84,4 +85,4 @@ export const Dropdown = ({ item, options, icon, onChange, label }: Props) => { )} ); -}; +} diff --git a/src/components/dropdowns/LanguageDropdown.tsx b/src/components/dropdowns/LanguageDropdown.tsx index cb030df..6898b46 100644 --- a/src/components/dropdowns/LanguageDropdown.tsx +++ b/src/components/dropdowns/LanguageDropdown.tsx @@ -1,21 +1,21 @@ -import { ChevronUpDownIcon } from "@heroicons/react/20/solid"; -import type { LocalePath } from "~/i18n"; +import { LanguageIcon } from "@heroicons/react/20/solid"; +import { languages, type Language, type LocalePath } from "~/i18n"; import { Dropdown } from "./Dropdown"; interface Props { - lang: string; + lang: Language; paths: LocalePath[]; } export const LanguageDropdown = ({ lang, paths }: Props) => (