import * as React from "react" import { Select as SelectPrimitive } from "@base-ui/react/select" import { Check, ChevronDown } from "lucide-react" import { cn } from "@/lib/utils" // Base UI's resolves the selected item's *label* from the // Root `items` prop only; without it the trigger shows the raw value. We // derive that map from the rendered children so consumers keep // the simple `Label` API and still get // labels (not raw values) in the trigger. function collectItems( node: React.ReactNode, out: Array<{ value: unknown; label: React.ReactNode }> ) { React.Children.forEach(node, (child) => { if (!React.isValidElement(child)) { return } if (child.type === SelectItem) { const props = child.props as SelectPrimitive.Item.Props out.push({ value: props.value, label: props.children }) return } const props = child.props as { children?: React.ReactNode } if (props.children != null) { collectItems(props.children, out) } }) } function Select({ children, ...props }: SelectPrimitive.Root.Props) { const items = React.useMemo(() => { const collected: Array<{ value: unknown; label: React.ReactNode }> = [] collectItems(children, collected) return collected }, [children]) return ( {children} ) } function SelectTrigger({ className, children, ...props }: SelectPrimitive.Trigger.Props) { return ( {children} ) } function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) { return ( ) } function SelectContent({ className, sideOffset = 6, ...props }: SelectPrimitive.Popup.Props & { sideOffset?: SelectPrimitive.Positioner.Props["sideOffset"] }) { return ( ) } function SelectItem({ className, children, ...props }: SelectPrimitive.Item.Props) { return ( {children} ) } export { Select, SelectTrigger, SelectValue, SelectContent, SelectItem }