@recursica/mantine-adapter 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +6 -28
- package/dist/mantine-adapter.cjs +1 -1
- package/dist/mantine-adapter.cjs.map +1 -1
- package/dist/mantine-adapter.css +1 -1
- package/dist/mantine-adapter.js +1031 -891
- package/dist/mantine-adapter.js.map +1 -1
- package/dist/src/components/Menu/Menu.d.ts +85 -3
- package/package.json +1 -1
- package/src/components/Menu/MENU_IMPLEMENTATION_NOTES.md +78 -0
- package/src/components/Menu/Menu.module.css +244 -0
- package/src/components/Menu/Menu.stories.tsx +309 -5
- package/src/components/Menu/Menu.tsx +317 -4
|
@@ -1,17 +1,321 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { Menu } from "./Menu";
|
|
3
|
-
import {
|
|
3
|
+
import { Button } from "../Button";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Menu story axes:
|
|
7
|
+
* - trigger: click (default) vs hover behavior
|
|
8
|
+
* - position: dropdown alignment relative to target
|
|
9
|
+
* - withArrow: arrow indicator on the dropdown
|
|
10
|
+
* - content variations: icons, dividers, labels, disabled items, submenus
|
|
11
|
+
* - layer: tested via the global Layer decorator (withLayer/layer args)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const SettingsIcon = () => (
|
|
15
|
+
<svg
|
|
16
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
+
width="14"
|
|
18
|
+
height="14"
|
|
19
|
+
viewBox="0 0 24 24"
|
|
20
|
+
fill="none"
|
|
21
|
+
stroke="currentColor"
|
|
22
|
+
strokeWidth="2"
|
|
23
|
+
strokeLinecap="round"
|
|
24
|
+
strokeLinejoin="round"
|
|
25
|
+
>
|
|
26
|
+
<circle cx="12" cy="12" r="3" />
|
|
27
|
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
|
28
|
+
</svg>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const SearchIcon = () => (
|
|
32
|
+
<svg
|
|
33
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
34
|
+
width="14"
|
|
35
|
+
height="14"
|
|
36
|
+
viewBox="0 0 24 24"
|
|
37
|
+
fill="none"
|
|
38
|
+
stroke="currentColor"
|
|
39
|
+
strokeWidth="2"
|
|
40
|
+
strokeLinecap="round"
|
|
41
|
+
strokeLinejoin="round"
|
|
42
|
+
>
|
|
43
|
+
<circle cx="11" cy="11" r="8" />
|
|
44
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const MessageIcon = () => (
|
|
49
|
+
<svg
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
width="14"
|
|
52
|
+
height="14"
|
|
53
|
+
viewBox="0 0 24 24"
|
|
54
|
+
fill="none"
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
strokeWidth="2"
|
|
57
|
+
strokeLinecap="round"
|
|
58
|
+
strokeLinejoin="round"
|
|
59
|
+
>
|
|
60
|
+
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
61
|
+
</svg>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const ImageIcon = () => (
|
|
65
|
+
<svg
|
|
66
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
67
|
+
width="14"
|
|
68
|
+
height="14"
|
|
69
|
+
viewBox="0 0 24 24"
|
|
70
|
+
fill="none"
|
|
71
|
+
stroke="currentColor"
|
|
72
|
+
strokeWidth="2"
|
|
73
|
+
strokeLinecap="round"
|
|
74
|
+
strokeLinejoin="round"
|
|
75
|
+
>
|
|
76
|
+
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
|
|
77
|
+
<circle cx="8.5" cy="8.5" r="1.5" />
|
|
78
|
+
<polyline points="21 15 16 10 5 21" />
|
|
79
|
+
</svg>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const TrashIcon = () => (
|
|
83
|
+
<svg
|
|
84
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
85
|
+
width="14"
|
|
86
|
+
height="14"
|
|
87
|
+
viewBox="0 0 24 24"
|
|
88
|
+
fill="none"
|
|
89
|
+
stroke="currentColor"
|
|
90
|
+
strokeWidth="2"
|
|
91
|
+
strokeLinecap="round"
|
|
92
|
+
strokeLinejoin="round"
|
|
93
|
+
>
|
|
94
|
+
<polyline points="3 6 5 6 21 6" />
|
|
95
|
+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
|
96
|
+
</svg>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const ArrowsIcon = () => (
|
|
100
|
+
<svg
|
|
101
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
102
|
+
width="14"
|
|
103
|
+
height="14"
|
|
104
|
+
viewBox="0 0 24 24"
|
|
105
|
+
fill="none"
|
|
106
|
+
stroke="currentColor"
|
|
107
|
+
strokeWidth="2"
|
|
108
|
+
strokeLinecap="round"
|
|
109
|
+
strokeLinejoin="round"
|
|
110
|
+
>
|
|
111
|
+
<polyline points="17 1 21 5 17 9" />
|
|
112
|
+
<path d="M3 11V9a4 4 0 0 1 4-4h14" />
|
|
113
|
+
<polyline points="7 23 3 19 7 15" />
|
|
114
|
+
<path d="M21 13v2a4 4 0 0 1-4 4H3" />
|
|
115
|
+
</svg>
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
+
type MenuStoryArgs = Record<string, any>;
|
|
120
|
+
|
|
121
|
+
const meta: Meta = {
|
|
122
|
+
title: "UI-Kit/Menu",
|
|
7
123
|
component: Menu,
|
|
8
124
|
tags: ["autodocs"],
|
|
125
|
+
argTypes: {
|
|
126
|
+
trigger: {
|
|
127
|
+
control: "select",
|
|
128
|
+
options: ["click", "hover", "click-hover"],
|
|
129
|
+
description:
|
|
130
|
+
"Determines how the menu is triggered: click (default), hover, or both.",
|
|
131
|
+
},
|
|
132
|
+
position: {
|
|
133
|
+
control: "select",
|
|
134
|
+
options: [
|
|
135
|
+
"bottom",
|
|
136
|
+
"bottom-start",
|
|
137
|
+
"bottom-end",
|
|
138
|
+
"top",
|
|
139
|
+
"top-start",
|
|
140
|
+
"top-end",
|
|
141
|
+
"left",
|
|
142
|
+
"left-start",
|
|
143
|
+
"left-end",
|
|
144
|
+
"right",
|
|
145
|
+
"right-start",
|
|
146
|
+
"right-end",
|
|
147
|
+
],
|
|
148
|
+
description: "The position of the dropdown relative to the target.",
|
|
149
|
+
},
|
|
150
|
+
withArrow: {
|
|
151
|
+
control: "boolean",
|
|
152
|
+
description: "Whether to display an arrow pointing to the target.",
|
|
153
|
+
},
|
|
154
|
+
offset: {
|
|
155
|
+
control: "number",
|
|
156
|
+
description:
|
|
157
|
+
"Distance in px between the dropdown and the target element.",
|
|
158
|
+
},
|
|
159
|
+
opened: {
|
|
160
|
+
control: "boolean",
|
|
161
|
+
description:
|
|
162
|
+
"Controlled open state. Leave undefined for uncontrolled behavior.",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
parameters: {
|
|
166
|
+
docs: {
|
|
167
|
+
description: {
|
|
168
|
+
component: `
|
|
169
|
+
The \`Menu\` component combines a list of secondary actions into a single interactive overlay area, wrapping Mantine's composable \`Menu\` while enforcing strict Recursica design token styling.
|
|
170
|
+
|
|
171
|
+
### Composable API
|
|
172
|
+
|
|
173
|
+
Menu uses a dot-notation composition pattern:
|
|
174
|
+
- \`<Menu>\` — Root container managing open/close state
|
|
175
|
+
- \`<Menu.Target>\` — Wrapper for the trigger element (must be a single element supporting ref)
|
|
176
|
+
- \`<Menu.Dropdown>\` — The popup panel
|
|
177
|
+
- \`<Menu.Item>\` — An actionable item with optional \`leftSection\` / \`rightSection\`
|
|
178
|
+
- \`<Menu.Divider>\` — A visual separator
|
|
179
|
+
- \`<Menu.Label>\` — A non-interactive section header
|
|
180
|
+
|
|
181
|
+
### Sub-menus
|
|
182
|
+
Nested menus are supported via \`<Menu.Sub>\`, \`<Menu.Sub.Target>\`, \`<Menu.Sub.Item>\`, and \`<Menu.Sub.Dropdown>\`.
|
|
183
|
+
|
|
184
|
+
### Design Token Limitations
|
|
185
|
+
Mantine's \`color\` prop on \`Menu.Item\` is stripped in strict mode to enforce design token adherence. Use \`overStyled={true}\` to bypass this restriction.
|
|
186
|
+
`,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
9
190
|
};
|
|
10
191
|
|
|
11
192
|
export default meta;
|
|
12
193
|
|
|
13
|
-
type Story = StoryObj<
|
|
194
|
+
type Story = StoryObj<MenuStoryArgs>;
|
|
14
195
|
|
|
15
196
|
export const Default: Story = {
|
|
16
|
-
|
|
197
|
+
args: {
|
|
198
|
+
trigger: "click",
|
|
199
|
+
position: "bottom-start",
|
|
200
|
+
withArrow: false,
|
|
201
|
+
offset: 5,
|
|
202
|
+
opened: undefined,
|
|
203
|
+
},
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
205
|
+
render: ({ withLayer, layer, ...args }: MenuStoryArgs) => {
|
|
206
|
+
return (
|
|
207
|
+
<Menu {...args}>
|
|
208
|
+
<Menu.Target>
|
|
209
|
+
<Button variant="solid">Toggle Menu</Button>
|
|
210
|
+
</Menu.Target>
|
|
211
|
+
|
|
212
|
+
<Menu.Dropdown>
|
|
213
|
+
<Menu.Label>Application</Menu.Label>
|
|
214
|
+
<Menu.Item leftSection={<SettingsIcon />}>Settings</Menu.Item>
|
|
215
|
+
<Menu.Item leftSection={<MessageIcon />}>Messages</Menu.Item>
|
|
216
|
+
<Menu.Item leftSection={<ImageIcon />}>Gallery</Menu.Item>
|
|
217
|
+
<Menu.Item leftSection={<SearchIcon />}>Search</Menu.Item>
|
|
218
|
+
|
|
219
|
+
<Menu.Divider />
|
|
220
|
+
|
|
221
|
+
<Menu.Label>Danger zone</Menu.Label>
|
|
222
|
+
<Menu.Item leftSection={<ArrowsIcon />}>Transfer my data</Menu.Item>
|
|
223
|
+
<Menu.Item leftSection={<TrashIcon />}>Delete my account</Menu.Item>
|
|
224
|
+
</Menu.Dropdown>
|
|
225
|
+
</Menu>
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const WithDisabledItems: Story = {
|
|
231
|
+
args: {
|
|
232
|
+
position: "bottom-start",
|
|
233
|
+
},
|
|
234
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
235
|
+
render: ({ withLayer, layer, ...args }: MenuStoryArgs) => {
|
|
236
|
+
return (
|
|
237
|
+
<Menu {...args}>
|
|
238
|
+
<Menu.Target>
|
|
239
|
+
<Button variant="solid">Menu with Disabled</Button>
|
|
240
|
+
</Menu.Target>
|
|
241
|
+
|
|
242
|
+
<Menu.Dropdown>
|
|
243
|
+
<Menu.Item leftSection={<SettingsIcon />}>Settings</Menu.Item>
|
|
244
|
+
<Menu.Item leftSection={<SearchIcon />} disabled>
|
|
245
|
+
Search (disabled)
|
|
246
|
+
</Menu.Item>
|
|
247
|
+
<Menu.Item leftSection={<MessageIcon />}>Messages</Menu.Item>
|
|
248
|
+
<Menu.Item leftSection={<TrashIcon />} disabled>
|
|
249
|
+
Delete (disabled)
|
|
250
|
+
</Menu.Item>
|
|
251
|
+
</Menu.Dropdown>
|
|
252
|
+
</Menu>
|
|
253
|
+
);
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const WithSubmenus: Story = {
|
|
258
|
+
args: {
|
|
259
|
+
position: "bottom-start",
|
|
260
|
+
width: 200,
|
|
261
|
+
},
|
|
262
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
263
|
+
render: ({ withLayer, layer, ...args }: MenuStoryArgs) => {
|
|
264
|
+
return (
|
|
265
|
+
<Menu {...args}>
|
|
266
|
+
<Menu.Target>
|
|
267
|
+
<Button variant="solid">Menu with Submenus</Button>
|
|
268
|
+
</Menu.Target>
|
|
269
|
+
|
|
270
|
+
<Menu.Dropdown>
|
|
271
|
+
<Menu.Item>Dashboard</Menu.Item>
|
|
272
|
+
<Menu.Sub>
|
|
273
|
+
<Menu.Sub.Target>
|
|
274
|
+
<Menu.Sub.Item>Products</Menu.Sub.Item>
|
|
275
|
+
</Menu.Sub.Target>
|
|
276
|
+
<Menu.Sub.Dropdown>
|
|
277
|
+
<Menu.Item>All products</Menu.Item>
|
|
278
|
+
<Menu.Item>Categories</Menu.Item>
|
|
279
|
+
<Menu.Item>Tags</Menu.Item>
|
|
280
|
+
</Menu.Sub.Dropdown>
|
|
281
|
+
</Menu.Sub>
|
|
282
|
+
<Menu.Sub>
|
|
283
|
+
<Menu.Sub.Target>
|
|
284
|
+
<Menu.Sub.Item>Orders</Menu.Sub.Item>
|
|
285
|
+
</Menu.Sub.Target>
|
|
286
|
+
<Menu.Sub.Dropdown>
|
|
287
|
+
<Menu.Item>Open</Menu.Item>
|
|
288
|
+
<Menu.Item>Completed</Menu.Item>
|
|
289
|
+
<Menu.Item>Cancelled</Menu.Item>
|
|
290
|
+
</Menu.Sub.Dropdown>
|
|
291
|
+
</Menu.Sub>
|
|
292
|
+
</Menu.Dropdown>
|
|
293
|
+
</Menu>
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export const HoverTrigger: Story = {
|
|
299
|
+
args: {
|
|
300
|
+
trigger: "click-hover",
|
|
301
|
+
position: "bottom-start",
|
|
302
|
+
openDelay: 100,
|
|
303
|
+
closeDelay: 400,
|
|
304
|
+
},
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
306
|
+
render: ({ withLayer, layer, ...args }: MenuStoryArgs) => {
|
|
307
|
+
return (
|
|
308
|
+
<Menu {...args}>
|
|
309
|
+
<Menu.Target>
|
|
310
|
+
<Button variant="solid">Hover or Click</Button>
|
|
311
|
+
</Menu.Target>
|
|
312
|
+
|
|
313
|
+
<Menu.Dropdown>
|
|
314
|
+
<Menu.Item leftSection={<SettingsIcon />}>Settings</Menu.Item>
|
|
315
|
+
<Menu.Item leftSection={<MessageIcon />}>Messages</Menu.Item>
|
|
316
|
+
<Menu.Item leftSection={<ImageIcon />}>Gallery</Menu.Item>
|
|
317
|
+
</Menu.Dropdown>
|
|
318
|
+
</Menu>
|
|
319
|
+
);
|
|
320
|
+
},
|
|
17
321
|
};
|
|
@@ -1,7 +1,320 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Menu as MantineMenu,
|
|
4
|
+
type MenuProps as MantineMenuProps,
|
|
5
|
+
type MenuTargetProps as MantineMenuTargetProps,
|
|
6
|
+
type MenuDropdownProps as MantineMenuDropdownProps,
|
|
7
|
+
type MenuItemProps as MantineMenuItemProps,
|
|
8
|
+
type MenuDividerProps as MantineMenuDividerProps,
|
|
9
|
+
type MenuLabelProps as MantineMenuLabelProps,
|
|
10
|
+
type MenuSubProps as MantineMenuSubProps,
|
|
11
|
+
type MenuSubTargetProps as MantineMenuSubTargetProps,
|
|
12
|
+
type MenuSubDropdownProps as MantineMenuSubDropdownProps,
|
|
13
|
+
} from "@mantine/core";
|
|
14
|
+
import {
|
|
15
|
+
filterStylingProps,
|
|
16
|
+
type RecursicaOverStyled,
|
|
17
|
+
} from "../../utils/filterStylingProps";
|
|
18
|
+
import styles from "./Menu.module.css";
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// ============================================================
|
|
21
|
+
// MENU ROOT
|
|
22
|
+
// ============================================================
|
|
4
23
|
|
|
5
|
-
|
|
6
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Recursica Menu component wrapping Mantine's composable Menu.
|
|
26
|
+
*
|
|
27
|
+
* Usage follows the composable dot-notation pattern:
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <Menu>
|
|
30
|
+
* <Menu.Target><Button>Open</Button></Menu.Target>
|
|
31
|
+
* <Menu.Dropdown>
|
|
32
|
+
* <Menu.Label>Section</Menu.Label>
|
|
33
|
+
* <Menu.Item>Action</Menu.Item>
|
|
34
|
+
* <Menu.Divider />
|
|
35
|
+
* <Menu.Item>Another action</Menu.Item>
|
|
36
|
+
* </Menu.Dropdown>
|
|
37
|
+
* </Menu>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type MenuProps = RecursicaOverStyled<MantineMenuProps>;
|
|
41
|
+
|
|
42
|
+
const MenuBase = function Menu({ overStyled = false, ...rest }: MenuProps) {
|
|
43
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
44
|
+
|
|
45
|
+
// Bind CSS module classes to Mantine's internal classNames API
|
|
46
|
+
const mergedClassNames: Partial<Record<string, string>> = {
|
|
47
|
+
dropdown: styles.dropdown,
|
|
48
|
+
item: styles.item,
|
|
49
|
+
itemLabel: styles.itemLabel,
|
|
50
|
+
itemSection: styles.itemSection,
|
|
51
|
+
divider: styles.divider,
|
|
52
|
+
label: styles.label,
|
|
53
|
+
chevron: styles.chevron,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const classNamesProp = (sanitizedProps as Record<string, unknown>).classNames;
|
|
57
|
+
if (
|
|
58
|
+
classNamesProp &&
|
|
59
|
+
typeof classNamesProp === "object" &&
|
|
60
|
+
!Array.isArray(classNamesProp)
|
|
61
|
+
) {
|
|
62
|
+
const o = classNamesProp as Record<string, string>;
|
|
63
|
+
Object.keys(o).forEach((key) => {
|
|
64
|
+
if (mergedClassNames[key]) {
|
|
65
|
+
mergedClassNames[key] = `${mergedClassNames[key]} ${o[key]}`;
|
|
66
|
+
} else {
|
|
67
|
+
mergedClassNames[key] = o[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<MantineMenu
|
|
74
|
+
classNames={mergedClassNames}
|
|
75
|
+
{...(sanitizedProps as unknown as MantineMenuProps)}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
7
78
|
};
|
|
79
|
+
MenuBase.displayName = "Menu";
|
|
80
|
+
|
|
81
|
+
// ============================================================
|
|
82
|
+
// MENU TARGET
|
|
83
|
+
// ============================================================
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Wrapper for the element that triggers the menu.
|
|
87
|
+
* Requires a single child element that supports ref forwarding.
|
|
88
|
+
*/
|
|
89
|
+
export type MenuTargetProps = MantineMenuTargetProps;
|
|
90
|
+
|
|
91
|
+
const MenuTarget = function MenuTarget(props: MenuTargetProps) {
|
|
92
|
+
return <MantineMenu.Target {...props} />;
|
|
93
|
+
};
|
|
94
|
+
MenuTarget.displayName = "MenuTarget";
|
|
95
|
+
|
|
96
|
+
// ============================================================
|
|
97
|
+
// MENU DROPDOWN
|
|
98
|
+
// ============================================================
|
|
99
|
+
|
|
100
|
+
/** The dropdown panel containing menu items, dividers, and labels. */
|
|
101
|
+
export type MenuDropdownProps = RecursicaOverStyled<MantineMenuDropdownProps>;
|
|
102
|
+
|
|
103
|
+
const MenuDropdown = forwardRef<HTMLDivElement, MenuDropdownProps>(
|
|
104
|
+
function MenuDropdown({ overStyled = false, ...rest }, ref) {
|
|
105
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
106
|
+
const classNameProp = (sanitizedProps as Record<string, unknown>)
|
|
107
|
+
.className as string | undefined;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<MantineMenu.Dropdown
|
|
111
|
+
ref={ref}
|
|
112
|
+
className={classNameProp}
|
|
113
|
+
{...(sanitizedProps as unknown as MantineMenuDropdownProps)}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
MenuDropdown.displayName = "MenuDropdown";
|
|
119
|
+
|
|
120
|
+
// ============================================================
|
|
121
|
+
// MENU ITEM
|
|
122
|
+
// ============================================================
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An individual actionable item within the menu dropdown.
|
|
126
|
+
*
|
|
127
|
+
* **Note:** Mantine's `color` prop is stripped in strict mode to enforce
|
|
128
|
+
* design token adherence. Use `overStyled={true}` if you need to bypass.
|
|
129
|
+
*/
|
|
130
|
+
export type MenuItemProps = RecursicaOverStyled<
|
|
131
|
+
Omit<MantineMenuItemProps, "color">
|
|
132
|
+
>;
|
|
133
|
+
|
|
134
|
+
const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(function MenuItem(
|
|
135
|
+
{ overStyled = false, ...rest },
|
|
136
|
+
ref,
|
|
137
|
+
) {
|
|
138
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
139
|
+
const restRecord = sanitizedProps as Record<string, unknown>;
|
|
140
|
+
|
|
141
|
+
// Strip Mantine's `color` prop to enforce token-driven styling
|
|
142
|
+
if (!overStyled) {
|
|
143
|
+
delete restRecord["color"];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const classNameProp = restRecord.className as string | undefined;
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<MantineMenu.Item
|
|
150
|
+
ref={ref}
|
|
151
|
+
className={classNameProp}
|
|
152
|
+
{...(sanitizedProps as unknown as MantineMenuItemProps)}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
MenuItem.displayName = "MenuItem";
|
|
157
|
+
|
|
158
|
+
// ============================================================
|
|
159
|
+
// MENU DIVIDER
|
|
160
|
+
// ============================================================
|
|
161
|
+
|
|
162
|
+
/** A visual separator between groups of menu items. */
|
|
163
|
+
export type MenuDividerProps = RecursicaOverStyled<MantineMenuDividerProps>;
|
|
164
|
+
|
|
165
|
+
const MenuDivider = forwardRef<HTMLHRElement, MenuDividerProps>(
|
|
166
|
+
function MenuDivider({ overStyled = false, ...rest }, ref) {
|
|
167
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
168
|
+
const classNameProp = (sanitizedProps as Record<string, unknown>)
|
|
169
|
+
.className as string | undefined;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<MantineMenu.Divider
|
|
173
|
+
ref={ref}
|
|
174
|
+
className={classNameProp}
|
|
175
|
+
{...(sanitizedProps as unknown as MantineMenuDividerProps)}
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
MenuDivider.displayName = "MenuDivider";
|
|
181
|
+
|
|
182
|
+
// ============================================================
|
|
183
|
+
// MENU LABEL
|
|
184
|
+
// ============================================================
|
|
185
|
+
|
|
186
|
+
/** A non-interactive section label used to categorize groups of menu items. */
|
|
187
|
+
export type MenuLabelProps = RecursicaOverStyled<MantineMenuLabelProps>;
|
|
188
|
+
|
|
189
|
+
const MenuLabel = forwardRef<HTMLDivElement, MenuLabelProps>(function MenuLabel(
|
|
190
|
+
{ overStyled = false, ...rest },
|
|
191
|
+
ref,
|
|
192
|
+
) {
|
|
193
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
194
|
+
const classNameProp = (sanitizedProps as Record<string, unknown>)
|
|
195
|
+
.className as string | undefined;
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<MantineMenu.Label
|
|
199
|
+
ref={ref}
|
|
200
|
+
className={classNameProp}
|
|
201
|
+
{...(sanitizedProps as unknown as MantineMenuLabelProps)}
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
MenuLabel.displayName = "MenuLabel";
|
|
206
|
+
|
|
207
|
+
// ============================================================
|
|
208
|
+
// MENU SUB (SUBMENU CONTAINER)
|
|
209
|
+
// ============================================================
|
|
210
|
+
|
|
211
|
+
/** Container for a submenu, wrapping Menu.Sub.Target and Menu.Sub.Dropdown. */
|
|
212
|
+
export type MenuSubProps = MantineMenuSubProps;
|
|
213
|
+
|
|
214
|
+
const MenuSubBase = function MenuSub(props: MenuSubProps) {
|
|
215
|
+
return <MantineMenu.Sub {...props} />;
|
|
216
|
+
};
|
|
217
|
+
MenuSubBase.displayName = "MenuSub";
|
|
218
|
+
|
|
219
|
+
// ============================================================
|
|
220
|
+
// MENU SUB TARGET
|
|
221
|
+
// ============================================================
|
|
222
|
+
|
|
223
|
+
/** Wrapper for the element that triggers the submenu. */
|
|
224
|
+
export type MenuSubTargetProps = MantineMenuSubTargetProps;
|
|
225
|
+
|
|
226
|
+
const MenuSubTarget = function MenuSubTarget(props: MenuSubTargetProps) {
|
|
227
|
+
return <MantineMenu.Sub.Target {...props} />;
|
|
228
|
+
};
|
|
229
|
+
MenuSubTarget.displayName = "MenuSubTarget";
|
|
230
|
+
|
|
231
|
+
// ============================================================
|
|
232
|
+
// MENU SUB ITEM (triggers submenu)
|
|
233
|
+
// ============================================================
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* A menu item that acts as a submenu trigger.
|
|
237
|
+
* Renders within Menu.Sub.Target and displays a chevron indicator.
|
|
238
|
+
*/
|
|
239
|
+
export type MenuSubItemProps = RecursicaOverStyled<
|
|
240
|
+
Omit<MantineMenuItemProps, "color">
|
|
241
|
+
>;
|
|
242
|
+
|
|
243
|
+
const MenuSubItem = forwardRef<HTMLButtonElement, MenuSubItemProps>(
|
|
244
|
+
function MenuSubItem({ overStyled = false, ...rest }, ref) {
|
|
245
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
246
|
+
const restRecord = sanitizedProps as Record<string, unknown>;
|
|
247
|
+
|
|
248
|
+
if (!overStyled) {
|
|
249
|
+
delete restRecord["color"];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const classNameProp = restRecord.className as string | undefined;
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<MantineMenu.Sub.Item
|
|
256
|
+
ref={ref}
|
|
257
|
+
className={classNameProp}
|
|
258
|
+
{...(sanitizedProps as unknown as MantineMenuItemProps)}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
MenuSubItem.displayName = "MenuSubItem";
|
|
264
|
+
|
|
265
|
+
// ============================================================
|
|
266
|
+
// MENU SUB DROPDOWN
|
|
267
|
+
// ============================================================
|
|
268
|
+
|
|
269
|
+
/** The dropdown panel for a submenu. */
|
|
270
|
+
export type MenuSubDropdownProps =
|
|
271
|
+
RecursicaOverStyled<MantineMenuSubDropdownProps>;
|
|
272
|
+
|
|
273
|
+
const MenuSubDropdown = forwardRef<HTMLDivElement, MenuSubDropdownProps>(
|
|
274
|
+
function MenuSubDropdown({ overStyled = false, ...rest }, ref) {
|
|
275
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
276
|
+
const classNameProp = (sanitizedProps as Record<string, unknown>)
|
|
277
|
+
.className as string | undefined;
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<MantineMenu.Sub.Dropdown
|
|
281
|
+
ref={ref}
|
|
282
|
+
className={classNameProp}
|
|
283
|
+
{...(sanitizedProps as unknown as MantineMenuSubDropdownProps)}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
},
|
|
287
|
+
);
|
|
288
|
+
MenuSubDropdown.displayName = "MenuSubDropdown";
|
|
289
|
+
|
|
290
|
+
// ============================================================
|
|
291
|
+
// DOT NOTATION EXPORT
|
|
292
|
+
// ============================================================
|
|
293
|
+
|
|
294
|
+
type MenuSubComponent = typeof MenuSubBase & {
|
|
295
|
+
Target: typeof MenuSubTarget;
|
|
296
|
+
Item: typeof MenuSubItem;
|
|
297
|
+
Dropdown: typeof MenuSubDropdown;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const MenuSub = MenuSubBase as MenuSubComponent;
|
|
301
|
+
MenuSub.Target = MenuSubTarget;
|
|
302
|
+
MenuSub.Item = MenuSubItem;
|
|
303
|
+
MenuSub.Dropdown = MenuSubDropdown;
|
|
304
|
+
|
|
305
|
+
type MenuComponent = typeof MenuBase & {
|
|
306
|
+
Target: typeof MenuTarget;
|
|
307
|
+
Dropdown: typeof MenuDropdown;
|
|
308
|
+
Item: typeof MenuItem;
|
|
309
|
+
Divider: typeof MenuDivider;
|
|
310
|
+
Label: typeof MenuLabel;
|
|
311
|
+
Sub: MenuSubComponent;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export const Menu = MenuBase as MenuComponent;
|
|
315
|
+
Menu.Target = MenuTarget;
|
|
316
|
+
Menu.Dropdown = MenuDropdown;
|
|
317
|
+
Menu.Item = MenuItem;
|
|
318
|
+
Menu.Divider = MenuDivider;
|
|
319
|
+
Menu.Label = MenuLabel;
|
|
320
|
+
Menu.Sub = MenuSub;
|