|
1
|
"use client" |
|
2
|
|
|
3
|
import { CheckMini, ChevronRightMini, EllipseMiniSolid } from "@medusajs/icons" |
|
4
|
import { DropdownMenu as RadixDropdownMenu } from "radix-ui" |
|
5
|
import * as React from "react" |
|
6
|
|
|
7
|
import { clx } from "@/utils/clx" |
|
8
|
|
|
9
|
/** |
|
10
|
* This component is based on the [Radix UI Dropdown Menu](https://www.radix-ui.com/primitives/docs/components/dropdown-menu) primitive. |
|
11
|
*/ |
|
12
|
const Root = RadixDropdownMenu.Root |
|
13
|
Root.displayName = "DropdownMenu" |
|
14
|
|
|
15
|
/** |
|
16
|
* This component is based on the [Radix UI Dropdown Menu Trigger](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#trigger) primitive. |
|
17
|
*/ |
|
18
|
const Trigger = RadixDropdownMenu.Trigger |
|
19
|
Trigger.displayName = "DropdownMenu.Trigger" |
|
20
|
|
|
21
|
/** |
|
22
|
* This component is based on the [Radix UI Dropdown Menu Group](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#group) primitive. |
|
23
|
*/ |
|
24
|
const Group = RadixDropdownMenu.Group |
|
25
|
Group.displayName = "DropdownMenu.Group" |
|
26
|
|
|
27
|
/** |
|
28
|
* This component is based on the [Radix UI Dropdown Menu Sub](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#sub) primitive. |
|
29
|
*/ |
|
30
|
const SubMenu = RadixDropdownMenu.Sub |
|
31
|
SubMenu.displayName = "DropdownMenu.SubMenu" |
|
32
|
|
|
33
|
/** |
|
34
|
* This component is based on the [Radix UI Dropdown Menu RadioGroup](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#radiogroup) primitive. |
|
35
|
*/ |
|
36
|
const RadioGroup = RadixDropdownMenu.RadioGroup |
|
37
|
RadioGroup.displayName = "DropdownMenu.RadioGroup" |
|
38
|
|
|
39
|
/** |
|
40
|
* This component is based on the [Radix UI Dropdown Menu SubTrigger](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#subtrigger) primitive. |
|
41
|
*/ |
|
42
|
const SubMenuTrigger = React.forwardRef< |
|
43
|
React.ElementRef<typeof RadixDropdownMenu.SubTrigger>, |
|
44
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.SubTrigger> |
|
45
|
>(({ className, children, ...props }, ref) => ( |
|
46
|
<RadixDropdownMenu.SubTrigger |
|
47
|
ref={ref} |
|
48
|
className={clx( |
|
49
|
"bg-ui-bg-component text-ui-fg-base txt-compact-small relative flex cursor-pointer select-none items-center rounded-md px-2 py-1.5 outline-none transition-colors", |
|
50
|
"focus-visible:bg-ui-bg-component-hover focus:bg-ui-bg-component-hover", |
|
51
|
"active:bg-ui-bg-component-hover", |
|
52
|
"data-[disabled]:text-ui-fg-disabled data-[disabled]:pointer-events-none", |
|
53
|
"data-[state=open]:!bg-ui-bg-component-hover", |
|
54
|
className |
|
55
|
)} |
|
56
|
{...props} |
|
57
|
> |
|
58
|
{children} |
|
59
|
<ChevronRightMini className="text-ui-fg-muted ml-auto" /> |
|
60
|
</RadixDropdownMenu.SubTrigger> |
|
61
|
)) |
|
62
|
SubMenuTrigger.displayName = "DropdownMenu.SubMenuTrigger" |
|
63
|
|
|
64
|
/** |
|
65
|
* This component is based on the [Radix UI Dropdown Menu SubContent](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#subcontent) primitive. |
|
66
|
*/ |
|
67
|
const SubMenuContent = React.forwardRef< |
|
68
|
React.ElementRef<typeof RadixDropdownMenu.SubContent>, |
|
69
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.SubContent> |
|
70
|
>(({ className, collisionPadding = 8, ...props }, ref) => ( |
|
71
|
<RadixDropdownMenu.Portal> |
|
72
|
<RadixDropdownMenu.SubContent |
|
73
|
ref={ref} |
|
74
|
collisionPadding={collisionPadding} |
|
75
|
className={clx( |
|
76
|
"bg-ui-bg-component text-ui-fg-base shadow-elevation-flyout max-h-[var(--radix-popper-available-height)] min-w-[220px] overflow-hidden rounded-lg p-1", |
|
77
|
"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", |
|
78
|
className |
|
79
|
)} |
|
80
|
{...props} |
|
81
|
/> |
|
82
|
</RadixDropdownMenu.Portal> |
|
83
|
)) |
|
84
|
SubMenuContent.displayName = "DropdownMenu.SubMenuContent" |
|
85
|
|
|
86
|
/** |
|
87
|
* This component is based on the [Radix UI Dropdown Menu Content](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#content) primitive. |
|
88
|
*/ |
|
89
|
const Content = React.forwardRef< |
|
90
|
React.ElementRef<typeof RadixDropdownMenu.Content>, |
|
91
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.Content> |
|
92
|
>( |
|
93
|
( |
|
94
|
{ |
|
95
|
className, |
|
96
|
/** |
|
97
|
* The space in pixels between the dropdown menu and its trigger element. |
|
98
|
*/ |
|
99
|
sideOffset = 8, |
|
100
|
/** |
|
101
|
* The distance in pixels from the boundary edges where collision detection should occur. |
|
102
|
*/ |
|
103
|
collisionPadding = 8, |
|
104
|
/** |
|
105
|
* The alignment of the dropdown menu relative to its trigger element. |
|
106
|
* |
|
107
|
* @defaultValue center |
|
108
|
*/ |
|
109
|
align = "center", |
|
110
|
...props |
|
111
|
}, |
|
112
|
ref |
|
113
|
) => ( |
|
114
|
<RadixDropdownMenu.Portal> |
|
115
|
<RadixDropdownMenu.Content |
|
116
|
ref={ref} |
|
117
|
sideOffset={sideOffset} |
|
118
|
align={align} |
|
119
|
collisionPadding={collisionPadding} |
|
120
|
className={clx( |
|
121
|
"bg-ui-bg-component text-ui-fg-base shadow-elevation-flyout max-h-[var(--radix-popper-available-height)] min-w-[220px] overflow-hidden rounded-lg p-1", |
|
122
|
"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", |
|
123
|
className |
|
124
|
)} |
|
125
|
{...props} |
|
126
|
/> |
|
127
|
</RadixDropdownMenu.Portal> |
|
128
|
) |
|
129
|
) |
|
130
|
Content.displayName = "DropdownMenu.Content" |
|
131
|
|
|
132
|
/** |
|
133
|
* This component is based on the [Radix UI Dropdown Menu Item](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#item) primitive. |
|
134
|
*/ |
|
135
|
const Item = React.forwardRef< |
|
136
|
React.ElementRef<typeof RadixDropdownMenu.Item>, |
|
137
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.Item> |
|
138
|
>(({ className, ...props }, ref) => ( |
|
139
|
<RadixDropdownMenu.Item |
|
140
|
ref={ref} |
|
141
|
className={clx( |
|
142
|
"bg-ui-bg-component text-ui-fg-base txt-compact-small relative flex cursor-pointer select-none items-center rounded-md px-2 py-1.5 outline-none transition-colors", |
|
143
|
"focus-visible:bg-ui-bg-component-hover focus:bg-ui-bg-component-hover", |
|
144
|
"active:bg-ui-bg-component-hover", |
|
145
|
"data-[disabled]:text-ui-fg-disabled data-[disabled]:pointer-events-none", |
|
146
|
className |
|
147
|
)} |
|
148
|
{...props} |
|
149
|
/> |
|
150
|
)) |
|
151
|
Item.displayName = "DropdownMenu.Item" |
|
152
|
|
|
153
|
/** |
|
154
|
* This component is based on the [Radix UI Dropdown Menu CheckboxItem](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#checkboxitem) primitive. |
|
155
|
*/ |
|
156
|
const CheckboxItem = React.forwardRef< |
|
157
|
React.ElementRef<typeof RadixDropdownMenu.CheckboxItem>, |
|
158
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.CheckboxItem> |
|
159
|
>(({ className, children, checked, ...props }, ref) => ( |
|
160
|
<RadixDropdownMenu.CheckboxItem |
|
161
|
ref={ref} |
|
162
|
className={clx( |
|
163
|
"bg-ui-bg-component text-ui-fg-base txt-compact-small relative flex cursor-pointer select-none items-center rounded-md py-1.5 pl-[31px] pr-2 outline-none transition-colors", |
|
164
|
"focus-visible:bg-ui-bg-component-hover focus:bg-ui-bg-component-hover", |
|
165
|
"active:bg-ui-bg-component-hover", |
|
166
|
"data-[disabled]:text-ui-fg-disabled data-[disabled]:pointer-events-none", |
|
167
|
"data-[state=checked]:txt-compact-small-plus", |
|
168
|
className |
|
169
|
)} |
|
170
|
checked={checked} |
|
171
|
{...props} |
|
172
|
> |
|
173
|
<span className="absolute left-2 flex size-[15px] items-center justify-center"> |
|
174
|
<RadixDropdownMenu.ItemIndicator> |
|
175
|
<CheckMini /> |
|
176
|
</RadixDropdownMenu.ItemIndicator> |
|
177
|
</span> |
|
178
|
{children} |
|
179
|
</RadixDropdownMenu.CheckboxItem> |
|
180
|
)) |
|
181
|
CheckboxItem.displayName = "DropdownMenu.CheckboxItem" |
|
182
|
|
|
183
|
/** |
|
184
|
* This component is based on the [Radix UI Dropdown Menu RadioItem](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#radioitem) primitive. |
|
185
|
*/ |
|
186
|
const RadioItem = React.forwardRef< |
|
187
|
React.ElementRef<typeof RadixDropdownMenu.RadioItem>, |
|
188
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.RadioItem> |
|
189
|
>(({ className, children, ...props }, ref) => ( |
|
190
|
<RadixDropdownMenu.RadioItem |
|
191
|
ref={ref} |
|
192
|
className={clx( |
|
193
|
"bg-ui-bg-component txt-compact-small relative flex cursor-pointer select-none items-center rounded-md py-1.5 pl-[31px] pr-2 outline-none transition-colors", |
|
194
|
"focus-visible:bg-ui-bg-component-hover focus:bg-ui-bg-component-hover", |
|
195
|
"active:bg-ui-bg-component-hover", |
|
196
|
"data-[disabled]:text-ui-fg-disabled data-[disabled]:pointer-events-none", |
|
197
|
"data-[state=checked]:txt-compact-small-plus", |
|
198
|
className |
|
199
|
)} |
|
200
|
{...props} |
|
201
|
> |
|
202
|
<span className="absolute left-2 flex size-[15px] items-center justify-center"> |
|
203
|
<RadixDropdownMenu.ItemIndicator> |
|
204
|
<EllipseMiniSolid className="text-ui-fg-base" /> |
|
205
|
</RadixDropdownMenu.ItemIndicator> |
|
206
|
</span> |
|
207
|
{children} |
|
208
|
</RadixDropdownMenu.RadioItem> |
|
209
|
)) |
|
210
|
RadioItem.displayName = "DropdownMenu.RadioItem" |
|
211
|
|
|
212
|
/** |
|
213
|
* This component is based on the [Radix UI Dropdown Menu Label](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#label) primitive. |
|
214
|
*/ |
|
215
|
const Label = React.forwardRef< |
|
216
|
React.ElementRef<typeof RadixDropdownMenu.Label>, |
|
217
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.Label> |
|
218
|
>(({ className, ...props }, ref) => ( |
|
219
|
<RadixDropdownMenu.Label |
|
220
|
ref={ref} |
|
221
|
className={clx("text-ui-fg-subtle txt-compact-xsmall-plus", className)} |
|
222
|
{...props} |
|
223
|
/> |
|
224
|
)) |
|
225
|
Label.displayName = "DropdownMenu.Label" |
|
226
|
|
|
227
|
/** |
|
228
|
* This component is based on the [Radix UI Dropdown Menu Separator](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#separator) primitive. |
|
229
|
*/ |
|
230
|
const Separator = React.forwardRef< |
|
231
|
React.ElementRef<typeof RadixDropdownMenu.Separator>, |
|
232
|
React.ComponentPropsWithoutRef<typeof RadixDropdownMenu.Separator> |
|
233
|
>(({ className, ...props }, ref) => ( |
|
234
|
<RadixDropdownMenu.Separator |
|
235
|
ref={ref} |
|
236
|
className={clx( |
|
237
|
"bg-ui-border-component border-t-ui-border-menu-top border-b-ui-border-menu-bot -mx-1 my-1 h-0.5 border-b border-t", |
|
238
|
className |
|
239
|
)} |
|
240
|
{...props} |
|
241
|
/> |
|
242
|
)) |
|
243
|
Separator.displayName = "DropdownMenu.Separator" |
|
244
|
|
|
245
|
/** |
|
246
|
* This component is based on the `span` element and supports all of its props |
|
247
|
*/ |
|
248
|
const Shortcut = ({ |
|
249
|
className, |
|
250
|
...props |
|
251
|
}: React.HTMLAttributes<HTMLSpanElement>) => { |
|
252
|
return ( |
|
253
|
<span |
|
254
|
className={clx( |
|
255
|
"text-ui-fg-subtle txt-compact-small ml-auto tracking-widest", |
|
256
|
className |
|
257
|
)} |
|
258
|
{...props} |
|
259
|
/> |
|
260
|
) |
|
261
|
} |
|
262
|
Shortcut.displayName = "DropdownMenu.Shortcut" |
|
263
|
|
|
264
|
/** |
|
265
|
* This component is based on the `span` element and supports all of its props |
|
266
|
*/ |
|
267
|
const Hint = ({ |
|
268
|
className, |
|
269
|
...props |
|
270
|
}: React.HTMLAttributes<HTMLSpanElement>) => { |
|
271
|
return ( |
|
272
|
<span |
|
273
|
className={clx( |
|
274
|
"text-ui-fg-subtle txt-compact-small ml-auto tracking-widest", |
|
275
|
className |
|
276
|
)} |
|
277
|
{...props} |
|
278
|
/> |
|
279
|
) |
|
280
|
} |
|
281
|
Hint.displayName = "DropdownMenu.Hint" |
|
282
|
|
|
283
|
const DropdownMenu = Object.assign(Root, { |
|
284
|
Trigger, |
|
285
|
Group, |
|
286
|
SubMenu, |
|
287
|
SubMenuContent, |
|
288
|
SubMenuTrigger, |
|
289
|
Content, |
|
290
|
Item, |
|
291
|
CheckboxItem, |
|
292
|
RadioGroup, |
|
293
|
RadioItem, |
|
294
|
Label, |
|
295
|
Separator, |
|
296
|
Shortcut, |
|
297
|
Hint, |
|
298
|
}) |
|
299
|
|
|
300
|
export { DropdownMenu } |