|
| 1 | +import*asReactfrom"react" |
| 2 | +import*asDropdownMenuPrimitivefrom"@radix-ui/react-dropdown-menu" |
| 3 | +import{Check,ChevronRight,Circle}from"lucide-react" |
| 4 | + |
| 5 | +import{cn}from"@/lib/utils" |
| 6 | + |
| 7 | +constDropdownMenu=DropdownMenuPrimitive.Root |
| 8 | + |
| 9 | +constDropdownMenuTrigger=DropdownMenuPrimitive.Trigger |
| 10 | + |
| 11 | +constDropdownMenuGroup=DropdownMenuPrimitive.Group |
| 12 | + |
| 13 | +constDropdownMenuPortal=DropdownMenuPrimitive.Portal |
| 14 | + |
| 15 | +constDropdownMenuSub=DropdownMenuPrimitive.Sub |
| 16 | + |
| 17 | +constDropdownMenuRadioGroup=DropdownMenuPrimitive.RadioGroup |
| 18 | + |
| 19 | +constDropdownMenuSubTrigger=React.forwardRef< |
| 20 | +React.ElementRef<typeofDropdownMenuPrimitive.SubTrigger>, |
| 21 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.SubTrigger>&{ |
| 22 | +inset?:boolean |
| 23 | +} |
| 24 | +>(({ className, inset, children, ...props},ref)=>( |
| 25 | +<DropdownMenuPrimitive.SubTrigger |
| 26 | +ref={ref} |
| 27 | +className={cn( |
| 28 | +"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 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", |
| 29 | +inset&&"pl-8", |
| 30 | +className |
| 31 | +)} |
| 32 | +{...props} |
| 33 | +> |
| 34 | +{children} |
| 35 | +<ChevronRightclassName="ml-auto"/> |
| 36 | +</DropdownMenuPrimitive.SubTrigger> |
| 37 | +)) |
| 38 | +DropdownMenuSubTrigger.displayName= |
| 39 | +DropdownMenuPrimitive.SubTrigger.displayName |
| 40 | + |
| 41 | +constDropdownMenuSubContent=React.forwardRef< |
| 42 | +React.ElementRef<typeofDropdownMenuPrimitive.SubContent>, |
| 43 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.SubContent> |
| 44 | +>(({ className, ...props},ref)=>( |
| 45 | +<DropdownMenuPrimitive.SubContent |
| 46 | +ref={ref} |
| 47 | +className={cn( |
| 48 | +"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 origin-[--radix-dropdown-menu-content-transform-origin]", |
| 49 | +className |
| 50 | +)} |
| 51 | +{...props} |
| 52 | +/> |
| 53 | +)) |
| 54 | +DropdownMenuSubContent.displayName= |
| 55 | +DropdownMenuPrimitive.SubContent.displayName |
| 56 | + |
| 57 | +constDropdownMenuContent=React.forwardRef< |
| 58 | +React.ElementRef<typeofDropdownMenuPrimitive.Content>, |
| 59 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.Content> |
| 60 | +>(({ className, sideOffset=4, ...props},ref)=>( |
| 61 | +<DropdownMenuPrimitive.Portal> |
| 62 | +<DropdownMenuPrimitive.Content |
| 63 | +ref={ref} |
| 64 | +sideOffset={sideOffset} |
| 65 | +className={cn( |
| 66 | +"z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", |
| 67 | +"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 origin-[--radix-dropdown-menu-content-transform-origin]", |
| 68 | +className |
| 69 | +)} |
| 70 | +{...props} |
| 71 | +/> |
| 72 | +</DropdownMenuPrimitive.Portal> |
| 73 | +)) |
| 74 | +DropdownMenuContent.displayName=DropdownMenuPrimitive.Content.displayName |
| 75 | + |
| 76 | +constDropdownMenuItem=React.forwardRef< |
| 77 | +React.ElementRef<typeofDropdownMenuPrimitive.Item>, |
| 78 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.Item>&{ |
| 79 | +inset?:boolean |
| 80 | +} |
| 81 | +>(({ className, inset, ...props},ref)=>( |
| 82 | +<DropdownMenuPrimitive.Item |
| 83 | +ref={ref} |
| 84 | +className={cn( |
| 85 | +"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 [&>svg]:size-4 [&>svg]:shrink-0", |
| 86 | +inset&&"pl-8", |
| 87 | +className |
| 88 | +)} |
| 89 | +{...props} |
| 90 | +/> |
| 91 | +)) |
| 92 | +DropdownMenuItem.displayName=DropdownMenuPrimitive.Item.displayName |
| 93 | + |
| 94 | +constDropdownMenuCheckboxItem=React.forwardRef< |
| 95 | +React.ElementRef<typeofDropdownMenuPrimitive.CheckboxItem>, |
| 96 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.CheckboxItem> |
| 97 | +>(({ className, children, checked, ...props},ref)=>( |
| 98 | +<DropdownMenuPrimitive.CheckboxItem |
| 99 | +ref={ref} |
| 100 | +className={cn( |
| 101 | +"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", |
| 102 | +className |
| 103 | +)} |
| 104 | +checked={checked} |
| 105 | +{...props} |
| 106 | +> |
| 107 | +<spanclassName="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 108 | +<DropdownMenuPrimitive.ItemIndicator> |
| 109 | +<CheckclassName="h-4 w-4"/> |
| 110 | +</DropdownMenuPrimitive.ItemIndicator> |
| 111 | +</span> |
| 112 | +{children} |
| 113 | +</DropdownMenuPrimitive.CheckboxItem> |
| 114 | +)) |
| 115 | +DropdownMenuCheckboxItem.displayName= |
| 116 | +DropdownMenuPrimitive.CheckboxItem.displayName |
| 117 | + |
| 118 | +constDropdownMenuRadioItem=React.forwardRef< |
| 119 | +React.ElementRef<typeofDropdownMenuPrimitive.RadioItem>, |
| 120 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.RadioItem> |
| 121 | +>(({ className, children, ...props},ref)=>( |
| 122 | +<DropdownMenuPrimitive.RadioItem |
| 123 | +ref={ref} |
| 124 | +className={cn( |
| 125 | +"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", |
| 126 | +className |
| 127 | +)} |
| 128 | +{...props} |
| 129 | +> |
| 130 | +<spanclassName="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 131 | +<DropdownMenuPrimitive.ItemIndicator> |
| 132 | +<CircleclassName="h-2 w-2 fill-current"/> |
| 133 | +</DropdownMenuPrimitive.ItemIndicator> |
| 134 | +</span> |
| 135 | +{children} |
| 136 | +</DropdownMenuPrimitive.RadioItem> |
| 137 | +)) |
| 138 | +DropdownMenuRadioItem.displayName=DropdownMenuPrimitive.RadioItem.displayName |
| 139 | + |
| 140 | +constDropdownMenuLabel=React.forwardRef< |
| 141 | +React.ElementRef<typeofDropdownMenuPrimitive.Label>, |
| 142 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.Label>&{ |
| 143 | +inset?:boolean |
| 144 | +} |
| 145 | +>(({ className, inset, ...props},ref)=>( |
| 146 | +<DropdownMenuPrimitive.Label |
| 147 | +ref={ref} |
| 148 | +className={cn( |
| 149 | +"px-2 py-1.5 text-sm font-semibold", |
| 150 | +inset&&"pl-8", |
| 151 | +className |
| 152 | +)} |
| 153 | +{...props} |
| 154 | +/> |
| 155 | +)) |
| 156 | +DropdownMenuLabel.displayName=DropdownMenuPrimitive.Label.displayName |
| 157 | + |
| 158 | +constDropdownMenuSeparator=React.forwardRef< |
| 159 | +React.ElementRef<typeofDropdownMenuPrimitive.Separator>, |
| 160 | +React.ComponentPropsWithoutRef<typeofDropdownMenuPrimitive.Separator> |
| 161 | +>(({ className, ...props},ref)=>( |
| 162 | +<DropdownMenuPrimitive.Separator |
| 163 | +ref={ref} |
| 164 | +className={cn("-mx-1 my-1 h-px bg-muted",className)} |
| 165 | +{...props} |
| 166 | +/> |
| 167 | +)) |
| 168 | +DropdownMenuSeparator.displayName=DropdownMenuPrimitive.Separator.displayName |
| 169 | + |
| 170 | +constDropdownMenuShortcut=({ |
| 171 | + className, |
| 172 | + ...props |
| 173 | +}:React.HTMLAttributes<HTMLSpanElement>)=>{ |
| 174 | +return( |
| 175 | +<span |
| 176 | +className={cn("ml-auto text-xs tracking-widest opacity-60",className)} |
| 177 | +{...props} |
| 178 | +/> |
| 179 | +) |
| 180 | +} |
| 181 | +DropdownMenuShortcut.displayName="DropdownMenuShortcut" |
| 182 | + |
| 183 | +export{ |
| 184 | +DropdownMenu, |
| 185 | +DropdownMenuTrigger, |
| 186 | +DropdownMenuContent, |
| 187 | +DropdownMenuItem, |
| 188 | +DropdownMenuCheckboxItem, |
| 189 | +DropdownMenuRadioItem, |
| 190 | +DropdownMenuLabel, |
| 191 | +DropdownMenuSeparator, |
| 192 | +DropdownMenuShortcut, |
| 193 | +DropdownMenuGroup, |
| 194 | +DropdownMenuPortal, |
| 195 | +DropdownMenuSub, |
| 196 | +DropdownMenuSubContent, |
| 197 | +DropdownMenuSubTrigger, |
| 198 | +DropdownMenuRadioGroup, |
| 199 | +} |