'use client'; import { Select as SelectPrimitive } from '@base-ui/react/select'; import { IconCheck, IconChevronDown, IconChevronUp, IconSelector, } from '@tabler/icons-react'; import * as React from 'react'; import { cn } from '@/lib/utils'; type SelectContentProps = Pick< React.ComponentProps, 'align' | 'side' | 'sideOffset' > & React.ComponentProps & { position?: 'item-aligned' | 'popper'; }; type SelectGroupLabelProps = React.ComponentProps< typeof SelectPrimitive.GroupLabel >; type SelectGroupProps = React.ComponentProps; type SelectItemData = { label: React.ReactNode; value: unknown; }; type SelectItemProps = React.ComponentProps; type SelectLabelProps = React.ComponentProps; type SelectProps = React.ComponentProps; type SelectSeparatorProps = React.ComponentProps< typeof SelectPrimitive.Separator >; type SelectTriggerProps = React.ComponentProps; type SelectValueProps = React.ComponentProps; // Base UI needs root item metadata to display labels before the popup mounts. function deriveSelectItems(children: React.ReactNode): SelectItemData[] { return React.Children.toArray(children).flatMap((child) => { if (!React.isValidElement<{ children?: React.ReactNode }>(child)) { return []; } if (child.type === SelectItem) { const { children: label, value } = child.props as SelectItemProps; return label == null ? [] : [{ label, value }]; } return deriveSelectItems(child.props.children); }); } function SelectContent({ align = 'center', children, className, position = 'popper', side = 'bottom', sideOffset = 4, ...props }: SelectContentProps) { return ( {children} ); } function SelectGroup({ className, ...props }: SelectGroupProps) { return ( ); } function SelectGroupLabel({ className, ...props }: SelectGroupLabelProps) { return ( ); } function SelectItem({ children, className, ...props }: SelectItemProps) { return ( {children} ); } function SelectLabel({ className, ...props }: SelectLabelProps) { return ( ); } function SelectRoot({ children, items, ...props }: SelectProps) { const derivedItems = React.useMemo( () => deriveSelectItems(children), [children], ); return ( {children} ); } function SelectScrollDownButton({ className, ...props }: React.ComponentProps) { return ( ); } function SelectScrollUpButton({ className, ...props }: React.ComponentProps) { return ( ); } function SelectSeparator({ className, ...props }: SelectSeparatorProps) { return ( ); } function SelectTrigger({ children, className, ...props }: SelectTriggerProps) { return ( {children} ); } function SelectValue({ ...props }: SelectValueProps) { return ; } const Select = Object.assign(SelectRoot, { Content: SelectContent, Group: SelectGroup, GroupLabel: SelectGroupLabel, Item: SelectItem, Label: SelectLabel, Separator: SelectSeparator, Trigger: SelectTrigger, Value: SelectValue, }); export { Select, SelectContent, SelectGroup, SelectGroupLabel, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, }; export type { SelectContentProps, SelectGroupLabelProps, SelectGroupProps, SelectItemProps, SelectLabelProps, SelectProps, SelectSeparatorProps, SelectTriggerProps, SelectValueProps, };