1
+ /**
2
+ * Copied from shadc/ui on 12/19/2024
3
+ * @see {@link https://ui.shadcn.com/docs/components/dropdown-menu }
4
+ *
5
+ * This component was updated to match the styles from the Figma design:
6
+ * @see {@link https://www.figma.com/design/WfqIgsTFXN2BscBSSyXWF8/Coder-kit?node-id=656-2354&t=CiGt5le3yJEwMH4M-0 }
7
+ */
8
+
1
9
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu" ;
2
10
import { Check , ChevronRight , Circle } from "lucide-react" ;
3
- import * as React from "react" ;
11
+ import {
12
+ forwardRef ,
13
+ type ElementRef ,
14
+ type ComponentPropsWithoutRef ,
15
+ type HTMLAttributes ,
16
+ } from "react" ;
4
17
import { cn } from "utils/cn" ;
5
18
6
- const DropdownMenu = DropdownMenuPrimitive . Root ;
19
+ export const DropdownMenu = DropdownMenuPrimitive . Root ;
7
20
8
- const DropdownMenuTrigger = DropdownMenuPrimitive . Trigger ;
21
+ export const DropdownMenuTrigger = DropdownMenuPrimitive . Trigger ;
9
22
10
- const DropdownMenuGroup = DropdownMenuPrimitive . Group ;
23
+ export const DropdownMenuGroup = DropdownMenuPrimitive . Group ;
11
24
12
- const DropdownMenuPortal = DropdownMenuPrimitive . Portal ;
25
+ export const DropdownMenuPortal = DropdownMenuPrimitive . Portal ;
13
26
14
- const DropdownMenuSub = DropdownMenuPrimitive . Sub ;
27
+ export const DropdownMenuSub = DropdownMenuPrimitive . Sub ;
15
28
16
- const DropdownMenuRadioGroup = DropdownMenuPrimitive . RadioGroup ;
29
+ export const DropdownMenuRadioGroup = DropdownMenuPrimitive . RadioGroup ;
17
30
18
- const DropdownMenuSubTrigger = React . forwardRef <
19
- React . ElementRef < typeof DropdownMenuPrimitive . SubTrigger > ,
20
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . SubTrigger > & {
31
+ export const DropdownMenuSubTrigger = forwardRef <
32
+ ElementRef < typeof DropdownMenuPrimitive . SubTrigger > ,
33
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . SubTrigger > & {
21
34
inset ?: boolean ;
22
35
}
23
36
> ( ( { className, inset, children, ...props } , ref ) => (
24
37
< DropdownMenuPrimitive . SubTrigger
25
38
ref = { ref }
26
39
className = { cn (
27
- "flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-surface-secondary data-[state=open]:bg-surface-secondary [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0" ,
28
- inset && "pl-8" ,
40
+ [
41
+ "flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-surface-secondary" ,
42
+ "data-[state=open]:bg-surface-secondary [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0" ,
43
+ inset && "pl-8" ,
44
+ ] ,
29
45
className ,
30
46
) }
31
47
{ ...props }
@@ -37,14 +53,20 @@ const DropdownMenuSubTrigger = React.forwardRef<
37
53
DropdownMenuSubTrigger . displayName =
38
54
DropdownMenuPrimitive . SubTrigger . displayName ;
39
55
40
- const DropdownMenuSubContent = React . forwardRef <
41
- React . ElementRef < typeof DropdownMenuPrimitive . SubContent > ,
42
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . SubContent >
56
+ export const DropdownMenuSubContent = forwardRef <
57
+ ElementRef < typeof DropdownMenuPrimitive . SubContent > ,
58
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . SubContent >
43
59
> ( ( { className, ...props } , ref ) => (
44
60
< DropdownMenuPrimitive . SubContent
45
61
ref = { ref }
46
62
className = { cn (
47
- "z-50 min-w-[8rem] overflow-hidden rounded-md border border-solid bg-surface-primary p-1 text-content-secondary 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" ,
63
+ [
64
+ "z-50 min-w-[8rem] overflow-hidden rounded-md border border-solid bg-surface-primary p-1 text-content-secondary shadow-lg" ,
65
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" ,
66
+ "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95" ,
67
+ "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2" ,
68
+ "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2" ,
69
+ ] ,
48
70
className ,
49
71
) }
50
72
{ ...props }
@@ -53,17 +75,22 @@ const DropdownMenuSubContent = React.forwardRef<
53
75
DropdownMenuSubContent . displayName =
54
76
DropdownMenuPrimitive . SubContent . displayName ;
55
77
56
- const DropdownMenuContent = React . forwardRef <
57
- React . ElementRef < typeof DropdownMenuPrimitive . Content > ,
58
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Content >
78
+ export const DropdownMenuContent = forwardRef <
79
+ ElementRef < typeof DropdownMenuPrimitive . Content > ,
80
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Content >
59
81
> ( ( { className, sideOffset = 4 , ...props } , ref ) => (
60
82
< DropdownMenuPrimitive . Portal >
61
83
< DropdownMenuPrimitive . Content
62
84
ref = { ref }
63
85
sideOffset = { sideOffset }
64
86
className = { cn (
65
- "z-50 min-w-48 overflow-hidden rounded-md border border-solid bg-surface-primary p-2 text-content-secondary shadow-md" ,
66
- "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" ,
87
+ [
88
+ "z-50 min-w-48 overflow-hidden rounded-md border border-solid bg-surface-primary p-2 text-content-secondary shadow-md" ,
89
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" ,
90
+ "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95" ,
91
+ "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2" ,
92
+ "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2" ,
93
+ ] ,
67
94
className ,
68
95
) }
69
96
{ ...props }
@@ -72,32 +99,39 @@ const DropdownMenuContent = React.forwardRef<
72
99
) ) ;
73
100
DropdownMenuContent . displayName = DropdownMenuPrimitive . Content . displayName ;
74
101
75
- const DropdownMenuItem = React . forwardRef <
76
- React . ElementRef < typeof DropdownMenuPrimitive . Item > ,
77
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Item > & {
102
+ export const DropdownMenuItem = forwardRef <
103
+ ElementRef < typeof DropdownMenuPrimitive . Item > ,
104
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Item > & {
78
105
inset ?: boolean ;
79
106
}
80
107
> ( ( { className, inset, ...props } , ref ) => (
81
108
< DropdownMenuPrimitive . Item
82
109
ref = { ref }
83
110
className = { cn (
84
- "relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-2 text-sm text-content-secondary font-medium outline-none transition-colors focus:bg-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0" ,
85
- inset && "pl-8" ,
111
+ [
112
+ "relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-2 text-sm text-content-secondary font-medium outline-none transition-colors" ,
113
+ "focus:bg-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50" ,
114
+ "[&>svg]:size-4 [&>svg]:shrink-0" ,
115
+ inset && "pl-8" ,
116
+ ] ,
86
117
className ,
87
118
) }
88
119
{ ...props }
89
120
/>
90
121
) ) ;
91
122
DropdownMenuItem . displayName = DropdownMenuPrimitive . Item . displayName ;
92
123
93
- const DropdownMenuCheckboxItem = React . forwardRef <
94
- React . ElementRef < typeof DropdownMenuPrimitive . CheckboxItem > ,
95
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . CheckboxItem >
124
+ export const DropdownMenuCheckboxItem = forwardRef <
125
+ ElementRef < typeof DropdownMenuPrimitive . CheckboxItem > ,
126
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . CheckboxItem >
96
127
> ( ( { className, children, checked, ...props } , ref ) => (
97
128
< DropdownMenuPrimitive . CheckboxItem
98
129
ref = { ref }
99
130
className = { cn (
100
- "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-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50" ,
131
+ [
132
+ "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors" ,
133
+ "focus:bg-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50" ,
134
+ ] ,
101
135
className ,
102
136
) }
103
137
checked = { checked }
@@ -114,14 +148,17 @@ const DropdownMenuCheckboxItem = React.forwardRef<
114
148
DropdownMenuCheckboxItem . displayName =
115
149
DropdownMenuPrimitive . CheckboxItem . displayName ;
116
150
117
- const DropdownMenuRadioItem = React . forwardRef <
118
- React . ElementRef < typeof DropdownMenuPrimitive . RadioItem > ,
119
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . RadioItem >
151
+ export const DropdownMenuRadioItem = forwardRef <
152
+ ElementRef < typeof DropdownMenuPrimitive . RadioItem > ,
153
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . RadioItem >
120
154
> ( ( { className, children, ...props } , ref ) => (
121
155
< DropdownMenuPrimitive . RadioItem
122
156
ref = { ref }
123
157
className = { cn (
124
- "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-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50" ,
158
+ [
159
+ "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors" ,
160
+ "focus:bg-surface-secondary focus:text-content-primary data-[disabled]:pointer-events-none data-[disabled]:opacity-50" ,
161
+ ] ,
125
162
className ,
126
163
) }
127
164
{ ...props }
@@ -136,40 +173,39 @@ const DropdownMenuRadioItem = React.forwardRef<
136
173
) ) ;
137
174
DropdownMenuRadioItem . displayName = DropdownMenuPrimitive . RadioItem . displayName ;
138
175
139
- const DropdownMenuLabel = React . forwardRef <
140
- React . ElementRef < typeof DropdownMenuPrimitive . Label > ,
141
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Label > & {
176
+ export const DropdownMenuLabel = forwardRef <
177
+ ElementRef < typeof DropdownMenuPrimitive . Label > ,
178
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Label > & {
142
179
inset ?: boolean ;
143
180
}
144
181
> ( ( { className, inset, ...props } , ref ) => (
145
182
< DropdownMenuPrimitive . Label
146
183
ref = { ref }
147
184
className = { cn (
148
- "px-2 py-1.5 text-sm font-semibold" ,
149
- inset && "pl-8" ,
185
+ [ "px-2 py-1.5 text-sm font-semibold" , inset && "pl-8" ] ,
150
186
className ,
151
187
) }
152
188
{ ...props }
153
189
/>
154
190
) ) ;
155
191
DropdownMenuLabel . displayName = DropdownMenuPrimitive . Label . displayName ;
156
192
157
- const DropdownMenuSeparator = React . forwardRef <
158
- React . ElementRef < typeof DropdownMenuPrimitive . Separator > ,
159
- React . ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Separator >
193
+ export const DropdownMenuSeparator = forwardRef <
194
+ ElementRef < typeof DropdownMenuPrimitive . Separator > ,
195
+ ComponentPropsWithoutRef < typeof DropdownMenuPrimitive . Separator >
160
196
> ( ( { className, ...props } , ref ) => (
161
197
< DropdownMenuPrimitive . Separator
162
198
ref = { ref }
163
- className = { cn ( "-mx-1 my-1 h-px bg-border" , className ) }
199
+ className = { cn ( [ "-mx-1 my-1 h-px bg-border" ] , className ) }
164
200
{ ...props }
165
201
/>
166
202
) ) ;
167
203
DropdownMenuSeparator . displayName = DropdownMenuPrimitive . Separator . displayName ;
168
204
169
- const DropdownMenuShortcut = ( {
205
+ export const DropdownMenuShortcut = ( {
170
206
className,
171
207
...props
172
- } : React . HTMLAttributes < HTMLSpanElement > ) => {
208
+ } : HTMLAttributes < HTMLSpanElement > ) => {
173
209
return (
174
210
< span
175
211
className = { cn ( "ml-auto text-xs tracking-widest opacity-60" , className ) }
@@ -178,21 +214,3 @@ const DropdownMenuShortcut = ({
178
214
) ;
179
215
} ;
180
216
DropdownMenuShortcut . displayName = "DropdownMenuShortcut" ;
181
-
182
- export {
183
- DropdownMenu ,
184
- DropdownMenuTrigger ,
185
- DropdownMenuContent ,
186
- DropdownMenuItem ,
187
- DropdownMenuCheckboxItem ,
188
- DropdownMenuRadioItem ,
189
- DropdownMenuLabel ,
190
- DropdownMenuSeparator ,
191
- DropdownMenuShortcut ,
192
- DropdownMenuGroup ,
193
- DropdownMenuPortal ,
194
- DropdownMenuSub ,
195
- DropdownMenuSubContent ,
196
- DropdownMenuSubTrigger ,
197
- DropdownMenuRadioGroup ,
198
- } ;
0 commit comments