| 1 | import * as React from "react"; |
| 2 | import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; |
| 3 | import { Check, ChevronRight, Circle } from "lucide-react"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | |
| 7 | const DropdownMenu = DropdownMenuPrimitive.Root; |
| 8 | const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger; |
| 9 | const DropdownMenuGroup = DropdownMenuPrimitive.Group; |
| 10 | const DropdownMenuPortal = DropdownMenuPrimitive.Portal; |
| 11 | const DropdownMenuSub = DropdownMenuPrimitive.Sub; |
| 12 | const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup; |
| 13 | |
| 14 | const DropdownMenuSubTrigger = React.forwardRef< |
| 15 | React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>, |
| 16 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & { |
| 17 | inset?: boolean; |
| 18 | } |
| 19 | >(({ className, inset, children, ...props }, ref) => ( |
| 20 | <DropdownMenuPrimitive.SubTrigger |
| 21 | ref={ref} |
| 22 | className={cn( |
| 23 | "flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent", |
| 24 | inset && "pl-8", |
| 25 | className, |
| 26 | )} |
| 27 | {...props} |
| 28 | > |
| 29 | {children} |
| 30 | <ChevronRight className="ml-auto" /> |
| 31 | </DropdownMenuPrimitive.SubTrigger> |
| 32 | )); |
| 33 | DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName; |
| 34 | |
| 35 | const DropdownMenuSubContent = React.forwardRef< |
| 36 | React.ElementRef<typeof DropdownMenuPrimitive.SubContent>, |
| 37 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent> |
| 38 | >(({ className, ...props }, ref) => ( |
| 39 | <DropdownMenuPrimitive.SubContent |
| 40 | ref={ref} |
| 41 | className={cn( |
| 42 | "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg", |
| 43 | className, |
| 44 | )} |
| 45 | {...props} |
| 46 | /> |
| 47 | )); |
| 48 | DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName; |
| 49 | |
| 50 | const DropdownMenuContent = React.forwardRef< |
| 51 | React.ElementRef<typeof DropdownMenuPrimitive.Content>, |
| 52 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> |
| 53 | >(({ className, sideOffset = 4, ...props }, ref) => ( |
| 54 | <DropdownMenuPrimitive.Portal> |
| 55 | <DropdownMenuPrimitive.Content |
| 56 | ref={ref} |
| 57 | sideOffset={sideOffset} |
| 58 | className={cn( |
| 59 | "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", |
| 60 | className, |
| 61 | )} |
| 62 | {...props} |
| 63 | /> |
| 64 | </DropdownMenuPrimitive.Portal> |
| 65 | )); |
| 66 | DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName; |
| 67 | |
| 68 | const DropdownMenuItem = React.forwardRef< |
| 69 | React.ElementRef<typeof DropdownMenuPrimitive.Item>, |
| 70 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & { |
| 71 | inset?: boolean; |
| 72 | } |
| 73 | >(({ className, inset, ...props }, ref) => ( |
| 74 | <DropdownMenuPrimitive.Item |
| 75 | ref={ref} |
| 76 | className={cn( |
| 77 | "relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", |
| 78 | inset && "pl-8", |
| 79 | className, |
| 80 | )} |
| 81 | {...props} |
| 82 | /> |
| 83 | )); |
| 84 | DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName; |
| 85 | |
| 86 | const DropdownMenuCheckboxItem = React.forwardRef< |
| 87 | React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>, |
| 88 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem> |
| 89 | >(({ className, children, checked, ...props }, ref) => ( |
| 90 | <DropdownMenuPrimitive.CheckboxItem |
| 91 | ref={ref} |
| 92 | className={cn( |
| 93 | "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground", |
| 94 | className, |
| 95 | )} |
| 96 | checked={checked} |
| 97 | {...props} |
| 98 | > |
| 99 | <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 100 | <DropdownMenuPrimitive.ItemIndicator> |
| 101 | <Check className="h-4 w-4" /> |
| 102 | </DropdownMenuPrimitive.ItemIndicator> |
| 103 | </span> |
| 104 | {children} |
| 105 | </DropdownMenuPrimitive.CheckboxItem> |
| 106 | )); |
| 107 | DropdownMenuCheckboxItem.displayName = |
| 108 | DropdownMenuPrimitive.CheckboxItem.displayName; |
| 109 | |
| 110 | const DropdownMenuRadioItem = React.forwardRef< |
| 111 | React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>, |
| 112 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem> |
| 113 | >(({ className, children, ...props }, ref) => ( |
| 114 | <DropdownMenuPrimitive.RadioItem |
| 115 | ref={ref} |
| 116 | className={cn( |
| 117 | "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground", |
| 118 | className, |
| 119 | )} |
| 120 | {...props} |
| 121 | > |
| 122 | <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 123 | <DropdownMenuPrimitive.ItemIndicator> |
| 124 | <Circle className="h-2 w-2 fill-current" /> |
| 125 | </DropdownMenuPrimitive.ItemIndicator> |
| 126 | </span> |
| 127 | {children} |
| 128 | </DropdownMenuPrimitive.RadioItem> |
| 129 | )); |
| 130 | DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName; |
| 131 | |
| 132 | const DropdownMenuLabel = React.forwardRef< |
| 133 | React.ElementRef<typeof DropdownMenuPrimitive.Label>, |
| 134 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & { |
| 135 | inset?: boolean; |
| 136 | } |
| 137 | >(({ className, inset, ...props }, ref) => ( |
| 138 | <DropdownMenuPrimitive.Label |
| 139 | ref={ref} |
| 140 | className={cn( |
| 141 | "px-2 py-1.5 text-sm font-semibold", |
| 142 | inset && "pl-8", |
| 143 | className, |
| 144 | )} |
| 145 | {...props} |
| 146 | /> |
| 147 | )); |
| 148 | DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName; |
| 149 | |
| 150 | const DropdownMenuSeparator = React.forwardRef< |
| 151 | React.ElementRef<typeof DropdownMenuPrimitive.Separator>, |
| 152 | React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator> |
| 153 | >(({ className, ...props }, ref) => ( |
| 154 | <DropdownMenuPrimitive.Separator |
| 155 | ref={ref} |
| 156 | className={cn("-mx-1 my-1 h-px bg-muted", className)} |
| 157 | {...props} |
| 158 | /> |
| 159 | )); |
| 160 | DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName; |
| 161 | |
| 162 | export { |
| 163 | DropdownMenu, |
| 164 | DropdownMenuCheckboxItem, |
| 165 | DropdownMenuContent, |
| 166 | DropdownMenuGroup, |
| 167 | DropdownMenuItem, |
| 168 | DropdownMenuLabel, |
| 169 | DropdownMenuPortal, |
| 170 | DropdownMenuRadioGroup, |
| 171 | DropdownMenuRadioItem, |
| 172 | DropdownMenuSeparator, |
| 173 | DropdownMenuSub, |
| 174 | DropdownMenuSubContent, |
| 175 | DropdownMenuSubTrigger, |
| 176 | DropdownMenuTrigger, |
| 177 | }; |
| 178 |