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