g1t/apps/web/app/components/ui/dropdown-menu.tsx
| 1 | import { DropdownMenu as Primitive } from "radix-ui"; |
| 2 | import type { ComponentProps } from "react"; |
| 3 | |
| 4 | import { cn } from "../../lib/cn"; |
| 5 | |
| 6 | // shadcn/ui's dropdown menu, styled with g1t's tokens. |
| 7 | |
| 8 | export const DropdownMenu = Primitive.Root; |
| 9 | export const DropdownMenuTrigger = Primitive.Trigger; |
| 10 | export const DropdownMenuGroup = Primitive.Group; |
| 11 | |
| 12 | export function DropdownMenuContent({ |
| 13 | className, |
| 14 | sideOffset = 6, |
| 15 | ...props |
| 16 | }: ComponentProps<typeof Primitive.Content>) { |
| 17 | return ( |
| 18 | <Primitive.Portal> |
| 19 | <Primitive.Content |
| 20 | sideOffset={sideOffset} |
| 21 | className={cn( |
| 22 | "z-50 min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg border border-line-strong bg-raised p-1 text-sm shadow-xl shadow-black/40", |
| 23 | className, |
| 24 | )} |
| 25 | {...props} |
| 26 | /> |
| 27 | </Primitive.Portal> |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | export function DropdownMenuItem({ |
| 32 | className, |
| 33 | ...props |
| 34 | }: ComponentProps<typeof Primitive.Item>) { |
| 35 | return ( |
| 36 | <Primitive.Item |
| 37 | className={cn( |
| 38 | "flex cursor-default items-center gap-2 rounded-md px-2 py-1.5 text-fg/90 outline-none select-none", |
| 39 | "data-highlighted:bg-line data-highlighted:text-fg data-disabled:opacity-50", |
| 40 | "[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-faint", |
| 41 | className, |
| 42 | )} |
| 43 | {...props} |
| 44 | /> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | export function DropdownMenuLabel({ |
| 49 | className, |
| 50 | ...props |
| 51 | }: ComponentProps<typeof Primitive.Label>) { |
| 52 | return ( |
| 53 | <Primitive.Label |
| 54 | className={cn("px-2 py-1.5 text-xs text-faint", className)} |
| 55 | {...props} |
| 56 | /> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | export function DropdownMenuSeparator({ |
| 61 | className, |
| 62 | ...props |
| 63 | }: ComponentProps<typeof Primitive.Separator>) { |
| 64 | return ( |
| 65 | <Primitive.Separator |
| 66 | className={cn("-mx-1 my-1 h-px bg-line", className)} |
| 67 | {...props} |
| 68 | /> |
| 69 | ); |
| 70 | } |