import { CheckIcon } from 'lucide-react'; import { composeRenderProps } from 'react-aria-components/composeRenderProps'; import { ListBox as AriaListBox, ListBoxItem as AriaListBoxItem, Collection, Header, ListBoxSection as Section, type ListBoxProps as AriaListBoxProps, type ListBoxItemProps, type ListBoxSectionProps as SectionProps, } from 'react-aria-components/ListBox'; import { tv } from 'tailwind-variants'; import { composeTailwindRenderProps, focusRing } from './utils'; export function ListBox({ children, ...props }: Omit, 'layout' | 'orientation'>) { return ( {children} ); } export const itemStyles = tv({ extend: focusRing, base: 'group relative flex cursor-default items-center gap-8 rounded-md px-2.5 py-1.5 text-sm will-change-transform forced-color-adjust-none select-none', variants: { isSelected: { false: 'text-slate-700 -outline-offset-2 hover:bg-slate-200 dark:text-zinc-300 dark:hover:bg-zinc-700', true: 'bg-secondary-600 text-white -outline-offset-4 outline-white dark:outline-white forced-colors:bg-[Highlight] forced-colors:text-[HighlightText] forced-colors:outline-[HighlightText] [&+[data-selected]]:rounded-t-none [&:has(+[data-selected])]:rounded-b-none', }, isDisabled: { true: 'text-slate-300 dark:text-zinc-600 forced-colors:text-[GrayText]', }, }, }); export function ListBoxItem(props: ListBoxItemProps) { const textValue = props.textValue || (typeof props.children === 'string' ? props.children : undefined); return ( {composeRenderProps(props.children, (children) => ( <> {children}
))} ); } export const dropdownItemStyles = tv({ base: 'group flex cursor-default items-center gap-4 rounded-lg py-2 pr-1 pl-3 text-sm outline outline-0 forced-color-adjust-none select-none', variants: { isDisabled: { false: 'text-gray-900 dark:text-zinc-100', true: 'text-gray-300 dark:text-zinc-600 forced-colors:text-[GrayText]', }, isFocused: { true: 'bg-secondary-600 text-white forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]', }, }, compoundVariants: [ { isFocused: false, isOpen: true, className: 'bg-gray-100 dark:bg-zinc-700/60', }, ], }); export function DropdownItem(props: ListBoxItemProps) { const textValue = props.textValue || (typeof props.children === 'string' ? props.children : undefined); return ( {composeRenderProps(props.children, (children, { isSelected }) => ( <> {children} {isSelected && } ))} ); } export interface DropdownSectionProps extends SectionProps { title?: string; } export function DropdownSection( props: DropdownSectionProps, ) { return (
{props.title}
{props.children}
); }