| 1 | 'use client';
|
| 2 |
|
| 3 | import * as React from 'react';
|
| 4 | import { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';
|
| 5 | import { DropdownMenu as DropdownMenuPrimitive } from 'radix-ui';
|
| 6 |
|
| 7 | import { cn } from '@/lib/utils';
|
| 8 |
|
| 9 | function DropdownMenu({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
| 10 | return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
| 11 | }
|
| 12 |
|
| 13 | function DropdownMenuPortal({
|
| 14 | ...props
|
| 15 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
| 16 | return <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
|
| 17 | }
|
| 18 |
|
| 19 | function DropdownMenuTrigger({
|
| 20 | ...props
|
| 21 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
| 22 | return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
| 23 | }
|
| 24 |
|
| 25 | function DropdownMenuContent({
|
| 26 | className,
|
| 27 | sideOffset = 4,
|
| 28 | ...props
|
| 29 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
| 30 | return (
|
| 31 | <DropdownMenuPrimitive.Portal>
|
| 32 | <DropdownMenuPrimitive.Content
|
| 33 | data-slot="dropdown-menu-content"
|
| 34 | sideOffset={sideOffset}
|
| 35 | className={cn(
|
| 36 | 'z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
| 37 | className,
|
| 38 | )}
|
| 39 | {...props}
|
| 40 | />
|
| 41 | </DropdownMenuPrimitive.Portal>
|
| 42 | );
|
| 43 | }
|
| 44 |
|
| 45 | function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
| 46 | return <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
|
| 47 | }
|
| 48 |
|
| 49 | function DropdownMenuItem({
|
| 50 | className,
|
| 51 | inset,
|
| 52 | variant = 'default',
|
| 53 | ...props
|
| 54 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
| 55 | inset?: boolean;
|
| 56 | variant?: 'default' | 'destructive';
|
| 57 | }) {
|
| 58 | return (
|
| 59 | <DropdownMenuPrimitive.Item
|
| 60 | data-slot="dropdown-menu-item"
|
| 61 | data-inset={inset}
|
| 62 | data-variant={variant}
|
| 63 | className={cn(
|
| 64 | "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
| 65 | className,
|
| 66 | )}
|
| 67 | {...props}
|
| 68 | />
|
| 69 | );
|
| 70 | }
|
| 71 |
|
| 72 | function DropdownMenuCheckboxItem({
|
| 73 | className,
|
| 74 | children,
|
| 75 | checked,
|
| 76 | ...props
|
| 77 | }: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
| 78 | return (
|
| 79 | <DropdownMenuPrimitive.CheckboxItem
|
| 80 | data-slot="dropdown-menu-checkbox-item"
|
| 81 | className={cn(
|
| 82 | "relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
| 83 | className,
|
| 84 | )}
|
| 85 | checked={checked}
|
| 86 | {...props}
|
| 87 | >
|
| 88 | <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
| 89 | <DropdownMenuPrimitive.ItemIndicator>
|
| 90 | <CheckIcon className="size-4" />
|
| 91 | </DropdownMenuPrimitive.ItemIndicator>
|
| 92 | </span>
|
| 93 | {children}
|
| 94 | </DropdownMenuPrimitive.CheckboxItem>
|
| 95 | );
|
| 96 | }
|
| 97 |
|
| 98 | function DropdownMenuRadioGroup({
|
| 99 | ...props
|
| 100 | }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
| 101 | return <DropdownMenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />;
|
| 102 | }
|
| 103 |
|
| 104 | function DropdownMenuRadioItem({
|
| 105 | className,
|
| 106 | children,
|
| 107 | ...props
|
| 108 | }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
| 109 | return (
|
| 110 | <DropdownMenuPrimitive.RadioItem
|
| 111 | data-slot="dropdown-menu-radio-item"
|
| 112 | className={cn(
|
| 113 | "relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
| 114 | className,
|
| 115 | )}
|
| 116 | {...props}
|
| 117 | >
|
| 118 | <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
| 119 | <DropdownMenuPrimitive.ItemIndicator>
|
| 120 | <CircleIcon className="size-2 fill-current" />
|
| 121 | </DropdownMenuPrimitive.ItemIndicator>
|
| 122 | </span>
|
| 123 | {children}
|
| 124 | </DropdownMenuPrimitive.RadioItem>
|
| 125 | );
|
| 126 | }
|
| 127 |
|
| 128 | function DropdownMenuLabel({
|
| 129 | className,
|
| 130 | inset,
|
| 131 | ...props
|
| 132 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
| 133 | inset?: boolean;
|
| 134 | }) {
|
| 135 | return (
|
| 136 | <DropdownMenuPrimitive.Label
|
| 137 | data-slot="dropdown-menu-label"
|
| 138 | data-inset={inset}
|
| 139 | className={cn('px-2 py-1.5 text-sm font-medium data-[inset]:pl-8', className)}
|
| 140 | {...props}
|
| 141 | />
|
| 142 | );
|
| 143 | }
|
| 144 |
|
| 145 | function DropdownMenuSeparator({
|
| 146 | className,
|
| 147 | ...props
|
| 148 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
| 149 | return (
|
| 150 | <DropdownMenuPrimitive.Separator
|
| 151 | data-slot="dropdown-menu-separator"
|
| 152 | className={cn('-mx-1 my-1 h-px bg-border', className)}
|
| 153 | {...props}
|
| 154 | />
|
| 155 | );
|
| 156 | }
|
| 157 |
|
| 158 | function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<'span'>) {
|
| 159 | return (
|
| 160 | <span
|
| 161 | data-slot="dropdown-menu-shortcut"
|
| 162 | className={cn('ml-auto text-xs tracking-widest text-muted-foreground', className)}
|
| 163 | {...props}
|
| 164 | />
|
| 165 | );
|
| 166 | }
|
| 167 |
|
| 168 | function DropdownMenuSub({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
| 169 | return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
| 170 | }
|
| 171 |
|
| 172 | function DropdownMenuSubTrigger({
|
| 173 | className,
|
| 174 | inset,
|
| 175 | children,
|
| 176 | ...props
|
| 177 | }: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
| 178 | inset?: boolean;
|
| 179 | }) {
|
| 180 | return (
|
| 181 | <DropdownMenuPrimitive.SubTrigger
|
| 182 | data-slot="dropdown-menu-sub-trigger"
|
| 183 | data-inset={inset}
|
| 184 | className={cn(
|
| 185 | "flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
| 186 | className,
|
| 187 | )}
|
| 188 | {...props}
|
| 189 | >
|
| 190 | {children}
|
| 191 | <ChevronRightIcon className="ml-auto size-4" />
|
| 192 | </DropdownMenuPrimitive.SubTrigger>
|
| 193 | );
|
| 194 | }
|
| 195 |
|
| 196 | function DropdownMenuSubContent({
|
| 197 | className,
|
| 198 | ...props
|
| 199 | }: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
| 200 | return (
|
| 201 | <DropdownMenuPrimitive.SubContent
|
| 202 | data-slot="dropdown-menu-sub-content"
|
| 203 | className={cn(
|
| 204 | 'z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
| 205 | className,
|
| 206 | )}
|
| 207 | {...props}
|
| 208 | />
|
| 209 | );
|
| 210 | }
|
| 211 |
|
| 212 | export {
|
| 213 | DropdownMenu,
|
| 214 | DropdownMenuPortal,
|
| 215 | DropdownMenuTrigger,
|
| 216 | DropdownMenuContent,
|
| 217 | DropdownMenuGroup,
|
| 218 | DropdownMenuLabel,
|
| 219 | DropdownMenuItem,
|
| 220 | DropdownMenuCheckboxItem,
|
| 221 | DropdownMenuRadioGroup,
|
| 222 | DropdownMenuRadioItem,
|
| 223 | DropdownMenuSeparator,
|
| 224 | DropdownMenuShortcut,
|
| 225 | DropdownMenuSub,
|
| 226 | DropdownMenuSubTrigger,
|
| 227 | DropdownMenuSubContent,
|
| 228 | };
|