dropdown-menu.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import * as React from 'react'
  2. import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
  3. import { Check, ChevronRight, Circle } from 'lucide-react'
  4. import { cn } from '@/lib/utils'
  5. const DropdownMenu = DropdownMenuPrimitive.Root
  6. const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
  7. const DropdownMenuGroup = DropdownMenuPrimitive.Group
  8. const DropdownMenuPortal = DropdownMenuPrimitive.Portal
  9. const DropdownMenuSub = DropdownMenuPrimitive.Sub
  10. const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
  11. const DropdownMenuSubTrigger = React.forwardRef<
  12. React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
  13. React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
  14. inset?: boolean
  15. }
  16. >(({ className, inset, children, ...props }, ref) => (
  17. <DropdownMenuPrimitive.SubTrigger
  18. ref={ref}
  19. className={cn(
  20. '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',
  21. inset && 'pl-8',
  22. className
  23. )}
  24. {...props}
  25. >
  26. {children}
  27. <ChevronRight className="ml-auto h-4 w-4" />
  28. </DropdownMenuPrimitive.SubTrigger>
  29. ))
  30. DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName
  31. const DropdownMenuSubContent = React.forwardRef<
  32. React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
  33. React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
  34. >(({ className, ...props }, ref) => (
  35. <DropdownMenuPrimitive.SubContent
  36. ref={ref}
  37. className={cn(
  38. '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',
  39. className
  40. )}
  41. {...props}
  42. />
  43. ))
  44. DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName
  45. const DropdownMenuContent = React.forwardRef<
  46. React.ElementRef<typeof DropdownMenuPrimitive.Content>,
  47. React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
  48. >(({ className, sideOffset = 4, ...props }, ref) => (
  49. <DropdownMenuPrimitive.Portal>
  50. <DropdownMenuPrimitive.Content
  51. ref={ref}
  52. sideOffset={sideOffset}
  53. className={cn(
  54. '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',
  55. className
  56. )}
  57. {...props}
  58. />
  59. </DropdownMenuPrimitive.Portal>
  60. ))
  61. DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
  62. const DropdownMenuItem = React.forwardRef<
  63. React.ElementRef<typeof DropdownMenuPrimitive.Item>,
  64. React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
  65. inset?: boolean
  66. }
  67. >(({ className, inset, ...props }, ref) => (
  68. <DropdownMenuPrimitive.Item
  69. ref={ref}
  70. className={cn(
  71. '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-[disabled]:pointer-events-none data-[disabled]:opacity-50',
  72. inset && 'pl-8',
  73. className
  74. )}
  75. {...props}
  76. />
  77. ))
  78. DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
  79. const DropdownMenuSeparator = React.forwardRef<
  80. React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
  81. React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
  82. >(({ className, ...props }, ref) => (
  83. <DropdownMenuPrimitive.Separator
  84. ref={ref}
  85. className={cn('-mx-1 my-1 h-px bg-muted', className)}
  86. {...props}
  87. />
  88. ))
  89. DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
  90. export {
  91. DropdownMenu,
  92. DropdownMenuTrigger,
  93. DropdownMenuContent,
  94. DropdownMenuItem,
  95. DropdownMenuSeparator,
  96. DropdownMenuGroup,
  97. DropdownMenuPortal,
  98. DropdownMenuSub,
  99. DropdownMenuSubContent,
  100. DropdownMenuSubTrigger,
  101. DropdownMenuRadioGroup,
  102. }