import * as React from "react" import * as SelectPrimitive from "@radix-ui/react-select" import { Check, ChevronDown, ChevronUp } from "lucide-react" import { cn } from "@/lib/utils" import { CUSTOM_NODE_CLASS } from "@/lib/constants" interface SelectOverlayContextValue { open: boolean close: () => void } const SelectOverlayContext = React.createContext({ open: false, close: () => {}, }) const Select = ({ open: controlledOpen, defaultOpen = false, onOpenChange, ...props }: React.ComponentProps) => { const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen) const open = controlledOpen ?? uncontrolledOpen const handleOpenChange = React.useCallback((nextOpen: boolean) => { if (controlledOpen === undefined) setUncontrolledOpen(nextOpen) onOpenChange?.(nextOpen) }, [controlledOpen, onOpenChange]) const overlayContext = React.useMemo(() => ({ open, close: () => handleOpenChange(false), }), [handleOpenChange, open]) return ( ) } Select.displayName = SelectPrimitive.Root.displayName const SelectGroup = SelectPrimitive.Group const SelectValue = SelectPrimitive.Value const SelectTrigger = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( span]:line-clamp-1", className )} {...props} > {children} )) SelectTrigger.displayName = SelectPrimitive.Trigger.displayName const SelectScrollUpButton = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName const SelectScrollDownButton = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName const SelectContent = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, position = "popper", ...props }, ref) => { const overlayContext = React.useContext(SelectOverlayContext) return (
{overlayContext.open ? ( ) }) SelectContent.displayName = SelectPrimitive.Content.displayName const SelectLabel = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectLabel.displayName = SelectPrimitive.Label.displayName const SelectItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( {children} )) SelectItem.displayName = SelectPrimitive.Item.displayName const SelectSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectSeparator.displayName = SelectPrimitive.Separator.displayName export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, }