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