import * as React from 'react' import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu' import { Check, ChevronDown, ChevronRight, ChevronUp, Circle } from 'lucide-react' import { cn } from '@/lib/utils' const DropdownMenu = DropdownMenuPrimitive.Root const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger const DropdownMenuGroup = DropdownMenuPrimitive.Group const DropdownMenuPortal = DropdownMenuPrimitive.Portal const DropdownMenuSub = DropdownMenuPrimitive.Sub const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup const DropdownMenuSubTrigger = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { inset?: boolean } >(({ className, inset, children, ...props }, ref) => ( {children} )) DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName const DropdownMenuSubContent = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { showScrollButtons?: boolean } >(({ className, showScrollButtons = true, ...props }, ref) => { const [canScrollUp, setCanScrollUp] = React.useState(false) const [canScrollDown, setCanScrollDown] = React.useState(false) const contentRef = React.useRef(null) const scrollAreaRef = React.useRef(null) const lastScrollStateRef = React.useRef({ canScrollUp: false, canScrollDown: false }) React.useImperativeHandle(ref, () => contentRef.current!) const checkScrollability = React.useCallback(() => { const scrollArea = scrollAreaRef.current if (!scrollArea) return const newCanScrollUp = scrollArea.scrollTop > 0 const newCanScrollDown = scrollArea.scrollTop < scrollArea.scrollHeight - scrollArea.clientHeight // Only update state if values actually changed to prevent infinite loops if (newCanScrollUp !== lastScrollStateRef.current.canScrollUp) { lastScrollStateRef.current.canScrollUp = newCanScrollUp setCanScrollUp(newCanScrollUp) } if (newCanScrollDown !== lastScrollStateRef.current.canScrollDown) { lastScrollStateRef.current.canScrollDown = newCanScrollDown setCanScrollDown(newCanScrollDown) } }, []) const scrollUp = () => { scrollAreaRef.current?.scroll({ top: 0, behavior: 'smooth' }) } const scrollDown = () => { scrollAreaRef.current?.scroll({ top: scrollAreaRef.current.scrollHeight, behavior: 'smooth' }) } return ( { if (showScrollButtons) { checkScrollability() } }} collisionPadding={10} {...props} > {showScrollButtons && canScrollUp && (
)}
{props.children}
{showScrollButtons && canScrollDown && (
)}
) }) DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName const DropdownMenuContent = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { showScrollButtons?: boolean portalContainer?: HTMLElement | null } >(({ className, sideOffset = 4, showScrollButtons = false, portalContainer, ...props }, ref) => { const [canScrollUp, setCanScrollUp] = React.useState(false) const [canScrollDown, setCanScrollDown] = React.useState(false) const contentRef = React.useRef(null) const scrollAreaRef = React.useRef(null) const lastScrollStateRef = React.useRef({ canScrollUp: false, canScrollDown: false }) React.useImperativeHandle(ref, () => contentRef.current!) const checkScrollability = React.useCallback(() => { const scrollArea = scrollAreaRef.current if (!scrollArea) return const newCanScrollUp = scrollArea.scrollTop > 0 const newCanScrollDown = scrollArea.scrollTop < scrollArea.scrollHeight - scrollArea.clientHeight // Only update state if values actually changed to prevent infinite loops if (newCanScrollUp !== lastScrollStateRef.current.canScrollUp) { lastScrollStateRef.current.canScrollUp = newCanScrollUp setCanScrollUp(newCanScrollUp) } if (newCanScrollDown !== lastScrollStateRef.current.canScrollDown) { lastScrollStateRef.current.canScrollDown = newCanScrollDown setCanScrollDown(newCanScrollDown) } }, []) const scrollUp = () => { scrollAreaRef.current?.scroll({ top: 0, behavior: 'smooth' }) } const scrollDown = () => { scrollAreaRef.current?.scroll({ top: scrollAreaRef.current.scrollHeight, behavior: 'smooth' }) } return ( { if (showScrollButtons) { checkScrollability() } }} collisionPadding={10} {...props} > {showScrollButtons && canScrollUp && (
)}
{props.children}
{showScrollButtons && canScrollDown && (
)}
) }) DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName const DropdownMenuItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { inset?: boolean } >(({ className, inset, ...props }, ref) => ( )) DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName const DropdownMenuCheckboxItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, checked, ...props }, ref) => ( {children} )) DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName const DropdownMenuRadioItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( {children} )) DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName const DropdownMenuLabel = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { inset?: boolean } >(({ className, inset, ...props }, ref) => ( )) DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName const DropdownMenuSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName const DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes) => { return } DropdownMenuShortcut.displayName = 'DropdownMenuShortcut' export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuRadioGroup }