@salt-ds/lab 1.0.0-alpha.97 → 1.0.0-alpha.98
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 +11 -0
- package/css/salt-lab.css +1 -143
- package/dist-cjs/index.js +0 -22
- package/dist-cjs/index.js.map +1 -1
- package/dist-es/index.js +0 -11
- package/dist-es/index.js.map +1 -1
- package/dist-types/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist-cjs/mega-menu/MegaMenu.js +0 -76
- package/dist-cjs/mega-menu/MegaMenu.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuActions.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuActions.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuActions.js +0 -33
- package/dist-cjs/mega-menu/MegaMenuActions.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuAside.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuAside.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuAside.js +0 -33
- package/dist-cjs/mega-menu/MegaMenuAside.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuContent.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuContent.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuContent.js +0 -25
- package/dist-cjs/mega-menu/MegaMenuContent.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuContext.js +0 -11
- package/dist-cjs/mega-menu/MegaMenuContext.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroup.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuGroup.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroup.js +0 -40
- package/dist-cjs/mega-menu/MegaMenuGroup.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroupContext.js +0 -17
- package/dist-cjs/mega-menu/MegaMenuGroupContext.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroupHeading.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuGroupHeading.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroupHeading.js +0 -39
- package/dist-cjs/mega-menu/MegaMenuGroupHeading.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroups.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuGroups.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuGroups.js +0 -25
- package/dist-cjs/mega-menu/MegaMenuGroups.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuList.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuList.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuList.js +0 -43
- package/dist-cjs/mega-menu/MegaMenuList.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuListItem.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuListItem.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuListItem.js +0 -45
- package/dist-cjs/mega-menu/MegaMenuListItem.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuPanel.css.js +0 -6
- package/dist-cjs/mega-menu/MegaMenuPanel.css.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuPanel.js +0 -88
- package/dist-cjs/mega-menu/MegaMenuPanel.js.map +0 -1
- package/dist-cjs/mega-menu/MegaMenuTrigger.js +0 -90
- package/dist-cjs/mega-menu/MegaMenuTrigger.js.map +0 -1
- package/dist-cjs/mega-menu/useMegaMenu.js +0 -15
- package/dist-cjs/mega-menu/useMegaMenu.js.map +0 -1
- package/dist-cjs/mega-menu/useMegaMenuNavigation.js +0 -282
- package/dist-cjs/mega-menu/useMegaMenuNavigation.js.map +0 -1
- package/dist-cjs/mega-menu/usePageMargin.js +0 -22
- package/dist-cjs/mega-menu/usePageMargin.js.map +0 -1
- package/dist-es/mega-menu/MegaMenu.js +0 -74
- package/dist-es/mega-menu/MegaMenu.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuActions.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuActions.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuActions.js +0 -31
- package/dist-es/mega-menu/MegaMenuActions.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuAside.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuAside.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuAside.js +0 -31
- package/dist-es/mega-menu/MegaMenuAside.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuContent.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuContent.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuContent.js +0 -23
- package/dist-es/mega-menu/MegaMenuContent.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuContext.js +0 -9
- package/dist-es/mega-menu/MegaMenuContext.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroup.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuGroup.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroup.js +0 -38
- package/dist-es/mega-menu/MegaMenuGroup.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroupContext.js +0 -14
- package/dist-es/mega-menu/MegaMenuGroupContext.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroupHeading.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuGroupHeading.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroupHeading.js +0 -37
- package/dist-es/mega-menu/MegaMenuGroupHeading.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroups.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuGroups.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuGroups.js +0 -23
- package/dist-es/mega-menu/MegaMenuGroups.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuList.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuList.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuList.js +0 -41
- package/dist-es/mega-menu/MegaMenuList.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuListItem.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuListItem.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuListItem.js +0 -43
- package/dist-es/mega-menu/MegaMenuListItem.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuPanel.css.js +0 -4
- package/dist-es/mega-menu/MegaMenuPanel.css.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuPanel.js +0 -86
- package/dist-es/mega-menu/MegaMenuPanel.js.map +0 -1
- package/dist-es/mega-menu/MegaMenuTrigger.js +0 -88
- package/dist-es/mega-menu/MegaMenuTrigger.js.map +0 -1
- package/dist-es/mega-menu/useMegaMenu.js +0 -13
- package/dist-es/mega-menu/useMegaMenu.js.map +0 -1
- package/dist-es/mega-menu/useMegaMenuNavigation.js +0 -278
- package/dist-es/mega-menu/useMegaMenuNavigation.js.map +0 -1
- package/dist-es/mega-menu/usePageMargin.js +0 -20
- package/dist-es/mega-menu/usePageMargin.js.map +0 -1
- package/dist-types/mega-menu/MegaMenu.d.ts +0 -36
- package/dist-types/mega-menu/MegaMenuActions.d.ts +0 -10
- package/dist-types/mega-menu/MegaMenuAside.d.ts +0 -9
- package/dist-types/mega-menu/MegaMenuContent.d.ts +0 -9
- package/dist-types/mega-menu/MegaMenuContext.d.ts +0 -28
- package/dist-types/mega-menu/MegaMenuGroup.d.ts +0 -9
- package/dist-types/mega-menu/MegaMenuGroupContext.d.ts +0 -12
- package/dist-types/mega-menu/MegaMenuGroupHeading.d.ts +0 -13
- package/dist-types/mega-menu/MegaMenuGroups.d.ts +0 -8
- package/dist-types/mega-menu/MegaMenuList.d.ts +0 -16
- package/dist-types/mega-menu/MegaMenuListItem.d.ts +0 -25
- package/dist-types/mega-menu/MegaMenuPanel.d.ts +0 -8
- package/dist-types/mega-menu/MegaMenuTrigger.d.ts +0 -9
- package/dist-types/mega-menu/index.d.ts +0 -11
- package/dist-types/mega-menu/useMegaMenu.d.ts +0 -6
- package/dist-types/mega-menu/useMegaMenuNavigation.d.ts +0 -16
- package/dist-types/mega-menu/usePageMargin.d.ts +0 -6
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
const COLUMN_SELECTOR = "[data-mega-menu-column]";
|
|
6
|
-
const ACTIONS_SELECTOR = "[data-mega-menu-actions]";
|
|
7
|
-
const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
8
|
-
const SELF_CONSUMING_SELECTOR = 'input, textarea, select, [contenteditable], [role="combobox"], [role="listbox"], [role="slider"], [role="spinbutton"], [role="textbox"]';
|
|
9
|
-
const HIDDEN_ANCESTOR_SELECTOR = '[aria-hidden="true"], [inert]';
|
|
10
|
-
function queryFocusables(root) {
|
|
11
|
-
return Array.from(
|
|
12
|
-
root.querySelectorAll(FOCUSABLE_SELECTOR)
|
|
13
|
-
).filter((el) => !el.closest(HIDDEN_ANCESTOR_SELECTOR));
|
|
14
|
-
}
|
|
15
|
-
function firstFocusable(root) {
|
|
16
|
-
return root ? queryFocusables(root)[0] ?? null : null;
|
|
17
|
-
}
|
|
18
|
-
function buildModel(panel) {
|
|
19
|
-
const columns = Array.from(
|
|
20
|
-
panel.querySelectorAll(COLUMN_SELECTOR)
|
|
21
|
-
).filter((el) => queryFocusables(el).length > 0);
|
|
22
|
-
const actions = Array.from(
|
|
23
|
-
panel.querySelectorAll(ACTIONS_SELECTOR)
|
|
24
|
-
).filter((el) => queryFocusables(el).length > 0);
|
|
25
|
-
return { columns, actions };
|
|
26
|
-
}
|
|
27
|
-
function focusTrigger(context) {
|
|
28
|
-
var _a;
|
|
29
|
-
const reference = context.elements.reference;
|
|
30
|
-
(_a = firstFocusable(reference) ?? reference) == null ? void 0 : _a.focus();
|
|
31
|
-
}
|
|
32
|
-
function focusNextTriggerAndClose(context) {
|
|
33
|
-
const reference = context.elements.reference;
|
|
34
|
-
const trigger = firstFocusable(reference) ?? reference;
|
|
35
|
-
const li = trigger == null ? void 0 : trigger.closest("li");
|
|
36
|
-
const next = (li == null ? void 0 : li.nextElementSibling) instanceof HTMLElement ? firstFocusable(li.nextElementSibling) : null;
|
|
37
|
-
if (next) {
|
|
38
|
-
context.onOpenChange(false);
|
|
39
|
-
next.focus();
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
function columnsStacked(columns) {
|
|
45
|
-
if (columns.length < 2) return false;
|
|
46
|
-
const first = columns[0].getBoundingClientRect();
|
|
47
|
-
const second = columns[1].getBoundingClientRect();
|
|
48
|
-
return second.top >= first.bottom - 1;
|
|
49
|
-
}
|
|
50
|
-
function handleLinear(key, cell, panel, context) {
|
|
51
|
-
var _a, _b;
|
|
52
|
-
const cells = queryFocusables(panel);
|
|
53
|
-
const index = cells.indexOf(cell);
|
|
54
|
-
if (index === -1) return false;
|
|
55
|
-
switch (key) {
|
|
56
|
-
case "ArrowDown":
|
|
57
|
-
case "ArrowRight": {
|
|
58
|
-
if (index < cells.length - 1) {
|
|
59
|
-
cells[index + 1].focus();
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
case "ArrowUp":
|
|
64
|
-
case "ArrowLeft": {
|
|
65
|
-
if (index > 0) {
|
|
66
|
-
cells[index - 1].focus();
|
|
67
|
-
} else {
|
|
68
|
-
focusTrigger(context);
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
case "Home": {
|
|
73
|
-
(_a = cells[0]) == null ? void 0 : _a.focus();
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
case "End": {
|
|
77
|
-
(_b = cells[cells.length - 1]) == null ? void 0 : _b.focus();
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
default:
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function handleArrow(key, cell, panel, context) {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
86
|
-
const { columns, actions } = buildModel(panel);
|
|
87
|
-
if (columnsStacked(columns)) {
|
|
88
|
-
return handleLinear(key, cell, panel, context);
|
|
89
|
-
}
|
|
90
|
-
const column = cell.closest(COLUMN_SELECTOR);
|
|
91
|
-
const actionsEl = cell.closest(ACTIONS_SELECTOR);
|
|
92
|
-
if (column) {
|
|
93
|
-
const colIndex = columns.indexOf(column);
|
|
94
|
-
const cells = queryFocusables(column);
|
|
95
|
-
const rowIndex = cells.indexOf(cell);
|
|
96
|
-
switch (key) {
|
|
97
|
-
case "ArrowDown": {
|
|
98
|
-
if (rowIndex < cells.length - 1) {
|
|
99
|
-
cells[rowIndex + 1].focus();
|
|
100
|
-
} else if (colIndex < columns.length - 1) {
|
|
101
|
-
(_a = firstFocusable(columns[colIndex + 1])) == null ? void 0 : _a.focus();
|
|
102
|
-
} else if (actions.length > 0) {
|
|
103
|
-
(_b = firstFocusable(actions[0])) == null ? void 0 : _b.focus();
|
|
104
|
-
} else {
|
|
105
|
-
focusNextTriggerAndClose(context);
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
case "ArrowUp": {
|
|
110
|
-
if (rowIndex > 0) {
|
|
111
|
-
cells[rowIndex - 1].focus();
|
|
112
|
-
} else {
|
|
113
|
-
focusTrigger(context);
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
case "ArrowRight": {
|
|
118
|
-
if (colIndex < columns.length - 1) {
|
|
119
|
-
(_c = firstFocusable(columns[colIndex + 1])) == null ? void 0 : _c.focus();
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
if (rowIndex === cells.length - 1 && focusNextTriggerAndClose(context)) {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
focusTrigger(context);
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
case "ArrowLeft": {
|
|
129
|
-
if (colIndex > 0) {
|
|
130
|
-
(_d = firstFocusable(columns[colIndex - 1])) == null ? void 0 : _d.focus();
|
|
131
|
-
} else {
|
|
132
|
-
focusTrigger(context);
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
case "Home": {
|
|
137
|
-
(_e = cells[0]) == null ? void 0 : _e.focus();
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
case "End": {
|
|
141
|
-
(_f = cells[cells.length - 1]) == null ? void 0 : _f.focus();
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
default:
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (actionsEl) {
|
|
149
|
-
const cells = queryFocusables(actionsEl);
|
|
150
|
-
const index = cells.indexOf(cell);
|
|
151
|
-
switch (key) {
|
|
152
|
-
case "ArrowRight": {
|
|
153
|
-
if (index < cells.length - 1) {
|
|
154
|
-
cells[index + 1].focus();
|
|
155
|
-
} else if (!focusNextTriggerAndClose(context)) {
|
|
156
|
-
focusTrigger(context);
|
|
157
|
-
}
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
case "ArrowLeft": {
|
|
161
|
-
if (index > 0) {
|
|
162
|
-
cells[index - 1].focus();
|
|
163
|
-
} else if (cell === firstFocusable(panel)) {
|
|
164
|
-
focusTrigger(context);
|
|
165
|
-
}
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
case "ArrowUp": {
|
|
169
|
-
if (columns.length > 0) {
|
|
170
|
-
const lastColumnCells = queryFocusables(columns[columns.length - 1]);
|
|
171
|
-
(_g = lastColumnCells[lastColumnCells.length - 1]) == null ? void 0 : _g.focus();
|
|
172
|
-
} else {
|
|
173
|
-
focusTrigger(context);
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
case "ArrowDown": {
|
|
178
|
-
if (index === cells.length - 1) {
|
|
179
|
-
focusNextTriggerAndClose(context);
|
|
180
|
-
}
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
case "Home": {
|
|
184
|
-
(_h = cells[0]) == null ? void 0 : _h.focus();
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
case "End": {
|
|
188
|
-
(_i = cells[cells.length - 1]) == null ? void 0 : _i.focus();
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
default:
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
function focusNextAfterPanel(context, panel) {
|
|
198
|
-
var _a;
|
|
199
|
-
const reference = context.elements.reference;
|
|
200
|
-
const refFocusable = firstFocusable(reference) ?? reference;
|
|
201
|
-
const nextLi = (_a = refFocusable == null ? void 0 : refFocusable.closest("li")) == null ? void 0 : _a.nextElementSibling;
|
|
202
|
-
const nextSibling = nextLi instanceof HTMLElement ? firstFocusable(nextLi) : null;
|
|
203
|
-
const nextOutside = nextSibling || (() => {
|
|
204
|
-
const allFocusable = queryFocusables(
|
|
205
|
-
panel.ownerDocument.documentElement
|
|
206
|
-
).filter((el) => !panel.contains(el));
|
|
207
|
-
const idx = refFocusable ? allFocusable.indexOf(refFocusable) : -1;
|
|
208
|
-
return idx >= 0 ? allFocusable[idx + 1] : void 0;
|
|
209
|
-
})();
|
|
210
|
-
if (nextOutside) {
|
|
211
|
-
const view = panel.ownerDocument.defaultView;
|
|
212
|
-
view == null ? void 0 : view.requestAnimationFrame(() => {
|
|
213
|
-
view == null ? void 0 : view.requestAnimationFrame(() => {
|
|
214
|
-
nextOutside.focus();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
function useMegaMenuNavigation(context, props = {}) {
|
|
220
|
-
const { enabled = true } = props;
|
|
221
|
-
const { open, onOpenChange } = context;
|
|
222
|
-
return react.useMemo(() => {
|
|
223
|
-
if (!enabled) {
|
|
224
|
-
return {};
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
floating: {
|
|
228
|
-
onKeyDown(event) {
|
|
229
|
-
var _a, _b;
|
|
230
|
-
if (!open) return;
|
|
231
|
-
const panel = event.currentTarget;
|
|
232
|
-
const target = event.target;
|
|
233
|
-
const { key } = event;
|
|
234
|
-
const isArrowOrEdge = key === "ArrowUp" || key === "ArrowDown" || key === "ArrowLeft" || key === "ArrowRight" || key === "Home" || key === "End";
|
|
235
|
-
if (isArrowOrEdge && target.closest(SELF_CONSUMING_SELECTOR)) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const cell = target.closest(FOCUSABLE_SELECTOR);
|
|
239
|
-
if (key === "Tab") {
|
|
240
|
-
const allCells = queryFocusables(panel);
|
|
241
|
-
const linearIndex = cell ? allCells.indexOf(cell) : -1;
|
|
242
|
-
if (linearIndex === -1) return;
|
|
243
|
-
event.preventDefault();
|
|
244
|
-
if (event.shiftKey) {
|
|
245
|
-
if (linearIndex === 0) {
|
|
246
|
-
focusTrigger(context);
|
|
247
|
-
} else {
|
|
248
|
-
(_a = allCells[linearIndex - 1]) == null ? void 0 : _a.focus();
|
|
249
|
-
}
|
|
250
|
-
} else if (linearIndex === allCells.length - 1) {
|
|
251
|
-
onOpenChange(false);
|
|
252
|
-
focusNextAfterPanel(context, panel);
|
|
253
|
-
} else {
|
|
254
|
-
(_b = allCells[linearIndex + 1]) == null ? void 0 : _b.focus();
|
|
255
|
-
}
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
if (!cell || !isArrowOrEdge) return;
|
|
259
|
-
if (handleArrow(key, cell, panel, context)) {
|
|
260
|
-
event.preventDefault();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
}, [enabled, open, context, onOpenChange]);
|
|
266
|
-
}
|
|
267
|
-
function focusFirstItem(panel, attempt = 0) {
|
|
268
|
-
const firstItem = firstFocusable(panel);
|
|
269
|
-
if (firstItem) {
|
|
270
|
-
firstItem.focus();
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const view = panel.ownerDocument.defaultView;
|
|
274
|
-
if (attempt < 3 && view) {
|
|
275
|
-
view.requestAnimationFrame(() => focusFirstItem(panel, attempt + 1));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
exports.FOCUSABLE_SELECTOR = FOCUSABLE_SELECTOR;
|
|
280
|
-
exports.focusFirstItem = focusFirstItem;
|
|
281
|
-
exports.useMegaMenuNavigation = useMegaMenuNavigation;
|
|
282
|
-
//# sourceMappingURL=useMegaMenuNavigation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMegaMenuNavigation.js","sources":["../src/mega-menu/useMegaMenuNavigation.ts"],"sourcesContent":["import type { ElementProps, FloatingRootContext } from \"@floating-ui/react\";\nimport { useMemo } from \"react\";\n\nconst COLUMN_SELECTOR = \"[data-mega-menu-column]\";\nconst ACTIONS_SELECTOR = \"[data-mega-menu-actions]\";\n\nexport const FOCUSABLE_SELECTOR =\n 'a[href], button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n// Controls that own the arrow keys (caret, option lists, steppers); the engine\n// leaves their keys alone when focus is inside one.\nconst SELF_CONSUMING_SELECTOR =\n 'input, textarea, select, [contenteditable], [role=\"combobox\"], [role=\"listbox\"], [role=\"slider\"], [role=\"spinbutton\"], [role=\"textbox\"]';\n\n// aria-hidden / inert subtrees are out of the focus order; filtered by ancestor\n// lookup since `:not()` cannot match on an ancestor.\nconst HIDDEN_ANCESTOR_SELECTOR = '[aria-hidden=\"true\"], [inert]';\n\nfunction queryFocusables(root: HTMLElement): HTMLElement[] {\n return Array.from(\n root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).filter((el) => !el.closest(HIDDEN_ANCESTOR_SELECTOR));\n}\n\nfunction firstFocusable(root: HTMLElement | null): HTMLElement | null {\n return root ? (queryFocusables(root)[0] ?? null) : null;\n}\n\ninterface NavModel {\n /** Columns (`data-mega-menu-column`) in DOM order, each with ≥1 cell. */\n columns: HTMLElement[];\n /** Full-width actions row; the bottom of the center area. */\n actions: HTMLElement[];\n}\n\n/** Build the navigation model from the panel DOM at keypress time. */\nfunction buildModel(panel: HTMLElement): NavModel {\n const columns = Array.from(\n panel.querySelectorAll<HTMLElement>(COLUMN_SELECTOR),\n ).filter((el) => queryFocusables(el).length > 0);\n\n const actions = Array.from(\n panel.querySelectorAll<HTMLElement>(ACTIONS_SELECTOR),\n ).filter((el) => queryFocusables(el).length > 0);\n\n return { columns, actions };\n}\n\nfunction focusTrigger(context: FloatingRootContext) {\n const reference = context.elements.reference as HTMLElement | null;\n (firstFocusable(reference) ?? reference)?.focus();\n}\n\n/** Exit to the next nav-bar trigger and close. Returns false when there is none. */\nfunction focusNextTriggerAndClose(context: FloatingRootContext): boolean {\n const reference = context.elements.reference as HTMLElement | null;\n const trigger = firstFocusable(reference) ?? reference;\n const li = trigger?.closest(\"li\");\n const next =\n li?.nextElementSibling instanceof HTMLElement\n ? firstFocusable(li.nextElementSibling)\n : null;\n if (next) {\n context.onOpenChange(false);\n next.focus();\n return true;\n }\n return false;\n}\n\n/** True when the grid has collapsed to one stacked column (small viewport). */\nfunction columnsStacked(columns: HTMLElement[]): boolean {\n if (columns.length < 2) return false;\n const first = columns[0].getBoundingClientRect();\n const second = columns[1].getBoundingClientRect();\n return second.top >= first.bottom - 1;\n}\n\n/** Stacked layout: all arrows degrade to prev/next over every cell. */\nfunction handleLinear(\n key: string,\n cell: HTMLElement,\n panel: HTMLElement,\n context: FloatingRootContext,\n): boolean {\n const cells = queryFocusables(panel);\n const index = cells.indexOf(cell);\n if (index === -1) return false;\n\n switch (key) {\n case \"ArrowDown\":\n case \"ArrowRight\": {\n if (index < cells.length - 1) {\n cells[index + 1].focus();\n }\n return true;\n }\n case \"ArrowUp\":\n case \"ArrowLeft\": {\n if (index > 0) {\n cells[index - 1].focus();\n } else {\n focusTrigger(context);\n }\n return true;\n }\n case \"Home\": {\n cells[0]?.focus();\n return true;\n }\n case \"End\": {\n cells[cells.length - 1]?.focus();\n return true;\n }\n default:\n return false;\n }\n}\n\n/** Arrow/Home/End movement from `cell`. Returns `true` when the key was consumed. */\nfunction handleArrow(\n key: string,\n cell: HTMLElement,\n panel: HTMLElement,\n context: FloatingRootContext,\n): boolean {\n const { columns, actions } = buildModel(panel);\n\n if (columnsStacked(columns)) {\n return handleLinear(key, cell, panel, context);\n }\n\n const column = cell.closest<HTMLElement>(COLUMN_SELECTOR);\n const actionsEl = cell.closest<HTMLElement>(ACTIONS_SELECTOR);\n\n if (column) {\n const colIndex = columns.indexOf(column);\n const cells = queryFocusables(column);\n const rowIndex = cells.indexOf(cell);\n\n switch (key) {\n case \"ArrowDown\": {\n if (rowIndex < cells.length - 1) {\n cells[rowIndex + 1].focus();\n } else if (colIndex < columns.length - 1) {\n firstFocusable(columns[colIndex + 1])?.focus();\n } else if (actions.length > 0) {\n firstFocusable(actions[0])?.focus();\n } else {\n focusNextTriggerAndClose(context);\n }\n return true;\n }\n case \"ArrowUp\": {\n if (rowIndex > 0) {\n cells[rowIndex - 1].focus();\n } else {\n focusTrigger(context);\n }\n return true;\n }\n case \"ArrowRight\": {\n if (colIndex < columns.length - 1) {\n firstFocusable(columns[colIndex + 1])?.focus();\n return true;\n }\n // Right border column: exit to the next trigger and close if available\n if (\n rowIndex === cells.length - 1 &&\n focusNextTriggerAndClose(context)\n ) {\n return true;\n }\n // Wrap to the current trigger and keep the menu open,\n // mirroring Left in the first column.\n focusTrigger(context);\n return true;\n }\n case \"ArrowLeft\": {\n if (colIndex > 0) {\n firstFocusable(columns[colIndex - 1])?.focus();\n } else {\n focusTrigger(context);\n }\n return true;\n }\n case \"Home\": {\n cells[0]?.focus();\n return true;\n }\n case \"End\": {\n cells[cells.length - 1]?.focus();\n return true;\n }\n default:\n return false;\n }\n }\n\n if (actionsEl) {\n const cells = queryFocusables(actionsEl);\n const index = cells.indexOf(cell);\n\n switch (key) {\n case \"ArrowRight\": {\n if (index < cells.length - 1) {\n cells[index + 1].focus();\n } else if (!focusNextTriggerAndClose(context)) {\n // Last action with no next trigger: wrap to the current trigger.\n focusTrigger(context);\n }\n return true;\n }\n case \"ArrowLeft\": {\n if (index > 0) {\n cells[index - 1].focus();\n } else if (cell === firstFocusable(panel)) {\n focusTrigger(context);\n }\n return true;\n }\n case \"ArrowUp\": {\n if (columns.length > 0) {\n const lastColumnCells = queryFocusables(columns[columns.length - 1]);\n lastColumnCells[lastColumnCells.length - 1]?.focus();\n } else {\n focusTrigger(context);\n }\n return true;\n }\n case \"ArrowDown\": {\n if (index === cells.length - 1) {\n focusNextTriggerAndClose(context);\n }\n return true;\n }\n case \"Home\": {\n cells[0]?.focus();\n return true;\n }\n case \"End\": {\n cells[cells.length - 1]?.focus();\n return true;\n }\n default:\n return false;\n }\n }\n\n return false;\n}\n\n/** Focus the first document-focusable after the panel, once it has unmounted. */\nfunction focusNextAfterPanel(context: FloatingRootContext, panel: HTMLElement) {\n const reference = context.elements.reference as HTMLElement | null;\n const refFocusable = firstFocusable(reference) ?? reference;\n\n const nextLi = refFocusable?.closest(\"li\")?.nextElementSibling;\n const nextSibling =\n nextLi instanceof HTMLElement ? firstFocusable(nextLi) : null;\n\n const nextOutside =\n nextSibling ||\n (() => {\n const allFocusable = queryFocusables(\n panel.ownerDocument.documentElement,\n ).filter((el) => !panel.contains(el));\n const idx = refFocusable ? allFocusable.indexOf(refFocusable) : -1;\n return idx >= 0 ? allFocusable[idx + 1] : undefined;\n })();\n\n if (nextOutside) {\n const view = panel.ownerDocument.defaultView;\n view?.requestAnimationFrame(() => {\n view?.requestAnimationFrame(() => {\n nextOutside.focus();\n });\n });\n }\n}\n\nexport interface UseMegaMenuNavigationProps {\n /**\n * Whether the interaction is enabled.\n * @default true\n */\n enabled?: boolean;\n}\n\n/**\n * Floating-ui interaction hook for mega menu keyboard navigation. Handles keys\n * on the panel only; the trigger keys are owned by `MegaMenuTrigger`.\n */\nexport function useMegaMenuNavigation(\n context: FloatingRootContext,\n props: UseMegaMenuNavigationProps = {},\n): ElementProps {\n const { enabled = true } = props;\n const { open, onOpenChange } = context;\n\n return useMemo(() => {\n if (!enabled) {\n return {};\n }\n\n return {\n floating: {\n onKeyDown(event: React.KeyboardEvent) {\n if (!open) return;\n\n const panel = event.currentTarget as HTMLElement;\n const target = event.target as HTMLElement;\n const { key } = event;\n\n const isArrowOrEdge =\n key === \"ArrowUp\" ||\n key === \"ArrowDown\" ||\n key === \"ArrowLeft\" ||\n key === \"ArrowRight\" ||\n key === \"Home\" ||\n key === \"End\";\n\n // A self-consuming control keeps its own navigation keys.\n if (isArrowOrEdge && target.closest(SELF_CONSUMING_SELECTOR)) {\n return;\n }\n\n const cell = target.closest<HTMLElement>(FOCUSABLE_SELECTOR);\n\n // Tab walks every cell in layout order; the panel is portaled, so the\n // boundary transitions are handled manually.\n if (key === \"Tab\") {\n const allCells = queryFocusables(panel);\n const linearIndex = cell ? allCells.indexOf(cell) : -1;\n if (linearIndex === -1) return;\n event.preventDefault();\n if (event.shiftKey) {\n if (linearIndex === 0) {\n focusTrigger(context);\n } else {\n allCells[linearIndex - 1]?.focus();\n }\n } else if (linearIndex === allCells.length - 1) {\n onOpenChange(false);\n focusNextAfterPanel(context, panel);\n } else {\n allCells[linearIndex + 1]?.focus();\n }\n return;\n }\n\n if (!cell || !isArrowOrEdge) return;\n\n if (handleArrow(key, cell, panel, context)) {\n event.preventDefault();\n }\n },\n },\n };\n }, [enabled, open, context, onOpenChange]);\n}\n\n/** Focus the first navigable item inside a mega menu panel, retrying until rendered. */\nexport function focusFirstItem(panel: HTMLElement, attempt = 0): void {\n const firstItem = firstFocusable(panel);\n\n if (firstItem) {\n firstItem.focus();\n return;\n }\n\n const view = panel.ownerDocument.defaultView;\n if (attempt < 3 && view) {\n view.requestAnimationFrame(() => focusFirstItem(panel, attempt + 1));\n }\n}\n"],"names":["useMemo"],"mappings":";;;;AAGA,MAAM,eAA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KACF;AAAA,EACF,GAAG,CAAC,OAAA,EAAS,IAAA,EAAM,OAAA,EAAS,YAAY,CAAC,CAAA;AAC3C;AAGO,SAAS,cAAA,CAAe,KAAA,EAAoB,OAAA,GAAU,CAAA,EAAS;AACpE,EAAA,MAAM,SAAA,GAAY,eAAe,KAAK,CAAA;AAEtC,EAAA,IAAI,SAAA,EAAW;AACb,IAAA,SAAA,CAAU,KAAA,EAAM;AAChB,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,IAAA,GAAO,MAAM,aAAA,CAAc,WAAA;AACjC,EAAA,IAAI,OAAA,GAAU,KAAK,IAAA,EAAM;AACvB,IAAA,IAAA,CAAK,sBAAsB,MAAM,cAAA,CAAe,KAAA,EAAO,OAAA,GAAU,CAAC,CAAC,CAAA;AAAA,EACrE;AACF;;;;;;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@salt-ds/core');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
|
|
6
|
-
function usePageMargin(referenceEl) {
|
|
7
|
-
const density = core.useDensity();
|
|
8
|
-
const [pageMargin, setPageMargin] = react.useState(0);
|
|
9
|
-
core.useIsomorphicLayoutEffect(() => {
|
|
10
|
-
if (!(referenceEl == null ? void 0 : referenceEl.parentNode)) return;
|
|
11
|
-
const probe = referenceEl.ownerDocument.createElement("div");
|
|
12
|
-
probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;width:var(--saltMegaMenuPanel-pageMargin, var(--salt-layout-page-margin));";
|
|
13
|
-
referenceEl.insertAdjacentElement("afterend", probe);
|
|
14
|
-
const width = probe.getBoundingClientRect().width;
|
|
15
|
-
probe.remove();
|
|
16
|
-
setPageMargin((prev) => prev === width ? prev : width);
|
|
17
|
-
}, [referenceEl, density]);
|
|
18
|
-
return pageMargin;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.usePageMargin = usePageMargin;
|
|
22
|
-
//# sourceMappingURL=usePageMargin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePageMargin.js","sources":["../src/mega-menu/usePageMargin.ts"],"sourcesContent":["import { useDensity, useIsomorphicLayoutEffect } from \"@salt-ds/core\";\nimport { useState } from \"react\";\n\n/**\n * Resolves the panel's page-margin token to pixels for floating-ui padding, to\n * handle token (`--saltMegaMenuPanel-pageMargin`) override by consumers\n * (edge to edge example).\n */\nexport function usePageMargin(\n referenceEl: HTMLElement | null | undefined,\n): number {\n const density = useDensity();\n const [pageMargin, setPageMargin] = useState(0);\n // biome-ignore lint/correctness/useExhaustiveDependencies: density isn't read here — signal that the resolved token changed.\n useIsomorphicLayoutEffect(() => {\n if (!referenceEl?.parentNode) return;\n const probe = referenceEl.ownerDocument.createElement(\"div\");\n probe.style.cssText =\n \"position:absolute;visibility:hidden;pointer-events:none;width:var(--saltMegaMenuPanel-pageMargin, var(--salt-layout-page-margin));\";\n referenceEl.insertAdjacentElement(\"afterend\", probe);\n const width = probe.getBoundingClientRect().width;\n probe.remove();\n setPageMargin((prev) => (prev === width ? prev : width));\n }, [referenceEl, density]);\n return pageMargin;\n}\n"],"names":["useDensity","useState","useIsomorphicLayoutEffect"],"mappings":";;;;;AAQO,SAAS,cACd,WAAA,EACQ;AACR,EAAA,MAAM,UAAUA,eAAA,EAAW;AAC3B,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAIC,eAAS,CAAC,CAAA;AAE9C,EAAAC,8BAAA,CAA0B,MAAM;AAC9B,IAAA,IAAI,EAAC,2CAAa,UAAA,CAAA,EAAY;AAC9B,IAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,aAAA,CAAc,aAAA,CAAc,KAAK,CAAA;AAC3D,IAAA,KAAA,CAAM,MAAM,OAAA,GACV,oIAAA;AACF,IAAA,WAAA,CAAY,qBAAA,CAAsB,YAAY,KAAK,CAAA;AACnD,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,qBAAA,EAAsB,CAAE,KAAA;AAC5C,IAAA,KAAA,CAAM,MAAA,EAAO;AACb,IAAA,aAAA,CAAc,CAAC,IAAA,KAAU,IAAA,KAAS,KAAA,GAAQ,OAAO,KAAM,CAAA;AAAA,EACzD,CAAA,EAAG,CAAC,WAAA,EAAa,OAAO,CAAC,CAAA;AACzB,EAAA,OAAO,UAAA;AACT;;;;"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useFloatingRootContext, useInteractions, useClick, useDismiss } from '@floating-ui/react';
|
|
3
|
-
import { useControlled } from '@salt-ds/core';
|
|
4
|
-
import { useState, useRef, useCallback, useMemo } from 'react';
|
|
5
|
-
import { MegaMenuContext } from './MegaMenuContext.js';
|
|
6
|
-
import { useMegaMenuNavigation } from './useMegaMenuNavigation.js';
|
|
7
|
-
|
|
8
|
-
function MegaMenu({
|
|
9
|
-
children,
|
|
10
|
-
open,
|
|
11
|
-
defaultOpen = false,
|
|
12
|
-
onOpenChange,
|
|
13
|
-
placement = "bottom"
|
|
14
|
-
}) {
|
|
15
|
-
const [openState, setOpenState] = useControlled({
|
|
16
|
-
controlled: open,
|
|
17
|
-
default: defaultOpen,
|
|
18
|
-
name: "MegaMenu",
|
|
19
|
-
state: "open"
|
|
20
|
-
});
|
|
21
|
-
const [reference, setReference] = useState(null);
|
|
22
|
-
const [floating, setFloating] = useState(null);
|
|
23
|
-
const focusFirstItemOnOpenRef = useRef(false);
|
|
24
|
-
const [panelId, setPanelId] = useState();
|
|
25
|
-
const setOpen = useCallback(
|
|
26
|
-
(newOpen) => {
|
|
27
|
-
if (!newOpen) {
|
|
28
|
-
focusFirstItemOnOpenRef.current = false;
|
|
29
|
-
}
|
|
30
|
-
setOpenState(newOpen);
|
|
31
|
-
onOpenChange == null ? void 0 : onOpenChange(newOpen);
|
|
32
|
-
},
|
|
33
|
-
[onOpenChange]
|
|
34
|
-
);
|
|
35
|
-
const floatingRootContext = useFloatingRootContext({
|
|
36
|
-
open: openState,
|
|
37
|
-
onOpenChange: setOpen,
|
|
38
|
-
elements: { reference, floating }
|
|
39
|
-
});
|
|
40
|
-
const megaMenuNavigation = useMegaMenuNavigation(floatingRootContext);
|
|
41
|
-
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
42
|
-
useClick(floatingRootContext),
|
|
43
|
-
useDismiss(floatingRootContext),
|
|
44
|
-
megaMenuNavigation
|
|
45
|
-
]);
|
|
46
|
-
const contextValue = useMemo(
|
|
47
|
-
() => ({
|
|
48
|
-
openState,
|
|
49
|
-
floatingRootContext,
|
|
50
|
-
placement,
|
|
51
|
-
getFloatingProps,
|
|
52
|
-
getReferenceProps,
|
|
53
|
-
setFloating,
|
|
54
|
-
setReference,
|
|
55
|
-
setOpen,
|
|
56
|
-
focusFirstItemOnOpenRef,
|
|
57
|
-
panelId,
|
|
58
|
-
setPanelId
|
|
59
|
-
}),
|
|
60
|
-
[
|
|
61
|
-
openState,
|
|
62
|
-
floatingRootContext,
|
|
63
|
-
placement,
|
|
64
|
-
getFloatingProps,
|
|
65
|
-
getReferenceProps,
|
|
66
|
-
setOpen,
|
|
67
|
-
panelId
|
|
68
|
-
]
|
|
69
|
-
);
|
|
70
|
-
return /* @__PURE__ */ jsx(MegaMenuContext.Provider, { value: contextValue, children });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { MegaMenu };
|
|
74
|
-
//# sourceMappingURL=MegaMenu.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenu.js","sources":["../src/mega-menu/MegaMenu.tsx"],"sourcesContent":["import {\n useClick,\n useDismiss,\n useFloatingRootContext,\n useInteractions,\n} from \"@floating-ui/react\";\nimport { useControlled } from \"@salt-ds/core\";\nimport { type ReactNode, useCallback, useMemo, useRef, useState } from \"react\";\nimport { MegaMenuContext } from \"./MegaMenuContext\";\nimport { useMegaMenuNavigation } from \"./useMegaMenuNavigation\";\n\n/**\n * Supported placements for the mega menu panel.\n */\nexport type MegaMenuPlacement = \"bottom\" | \"bottom-start\" | \"bottom-end\";\n\nexport interface MegaMenuProps {\n /**\n * The content of the mega menu, typically `MegaMenuTrigger` and `MegaMenuPanel`.\n */\n children?: ReactNode;\n /**\n * Whether the mega menu is open. Use for controlled mode.\n */\n open?: boolean;\n /**\n * Whether the mega menu is initially open. Use for uncontrolled mode.\n * @default false\n */\n defaultOpen?: boolean;\n /**\n * Callback fired when the open state changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * The placement of the mega menu panel relative to the trigger.\n * @default \"bottom\"\n */\n placement?: MegaMenuPlacement;\n}\n\n/**\n * Root of a mega menu, coordinating its trigger and panel.\n *\n * Not intended to be nested inside another floating overlay (e.g. a dialog or\n * popover): the mega menu does not participate in floating-ui's `FloatingTree`\n */\nexport function MegaMenu({\n children,\n open,\n defaultOpen = false,\n onOpenChange,\n placement = \"bottom\",\n}: MegaMenuProps) {\n const [openState, setOpenState] = useControlled({\n controlled: open,\n default: defaultOpen,\n name: \"MegaMenu\",\n state: \"open\",\n });\n\n const [reference, setReference] = useState<HTMLElement | null>(null);\n const [floating, setFloating] = useState<HTMLElement | null>(null);\n const focusFirstItemOnOpenRef = useRef(false);\n const [panelId, setPanelId] = useState<string>();\n\n const setOpen = useCallback(\n (newOpen: boolean) => {\n if (!newOpen) {\n focusFirstItemOnOpenRef.current = false;\n }\n setOpenState(newOpen);\n onOpenChange?.(newOpen);\n },\n [onOpenChange],\n );\n\n const floatingRootContext = useFloatingRootContext({\n open: openState,\n onOpenChange: setOpen,\n elements: { reference, floating },\n });\n\n const megaMenuNavigation = useMegaMenuNavigation(floatingRootContext);\n\n const { getReferenceProps, getFloatingProps } = useInteractions([\n useClick(floatingRootContext),\n useDismiss(floatingRootContext),\n megaMenuNavigation,\n ]);\n\n const contextValue = useMemo(\n () => ({\n openState,\n floatingRootContext,\n placement,\n getFloatingProps,\n getReferenceProps,\n setFloating,\n setReference,\n setOpen,\n focusFirstItemOnOpenRef,\n panelId,\n setPanelId,\n }),\n [\n openState,\n floatingRootContext,\n placement,\n getFloatingProps,\n getReferenceProps,\n setOpen,\n panelId,\n ],\n );\n\n return (\n <MegaMenuContext.Provider value={contextValue}>\n {children}\n </MegaMenuContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;AA+CO,SAAS,QAAA,CAAS;AAAA,EACvB,QAAA;AAAA,EACA,IAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,YAAA;AAAA,EACA,SAAA,GAAY;AACd,CAAA,EAAkB;AAChB,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,aAAA,CAAc;AAAA,IAC9C,UAAA,EAAY,IAAA;AAAA,IACZ,OAAA,EAAS,WAAA;AAAA,IACT,IAAA,EAAM,UAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAA6B,IAAI,CAAA;AACnE,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAA6B,IAAI,CAAA;AACjE,EAAA,MAAM,uBAAA,GAA0B,OAAO,KAAK,CAAA;AAC5C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,QAAA,EAAiB;AAE/C,EAAA,MAAM,OAAA,GAAU,WAAA;AAAA,IACd,CAAC,OAAA,KAAqB;AACpB,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,uBAAA,CAAwB,OAAA,GAAU,KAAA;AAAA,MACpC;AACA,MAAA,YAAA,CAAa,OAAO,CAAA;AACpB,MAAA,YAAA,IAAA,IAAA,GAAA,MAAA,GAAA,YAAA,CAAe,OAAA,CAAA;AAAA,IACjB,CAAA;AAAA,IACA,CAAC,YAAY;AAAA,GACf;AAEA,EAAA,MAAM,sBAAsB,sBAAA,CAAuB;AAAA,IACjD,IAAA,EAAM,SAAA;AAAA,IACN,YAAA,EAAc,OAAA;AAAA,IACd,QAAA,EAAU,EAAE,SAAA,EAAW,QAAA;AAAS,GACjC,CAAA;AAED,EAAA,MAAM,kBAAA,GAAqB,sBAAsB,mBAAmB,CAAA;AAEpE,EAAA,MAAM,EAAE,iBAAA,EAAmB,gBAAA,EAAiB,GAAI,eAAA,CAAgB;AAAA,IAC9D,SAAS,mBAAmB,CAAA;AAAA,IAC5B,WAAW,mBAAmB,CAAA;AAAA,IAC9B;AAAA,GACD,CAAA;AAED,EAAA,MAAM,YAAA,GAAe,OAAA;AAAA,IACnB,OAAO;AAAA,MACL,SAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,gBAAA;AAAA,MACA,iBAAA;AAAA,MACA,WAAA;AAAA,MACA,YAAA;AAAA,MACA,OAAA;AAAA,MACA,uBAAA;AAAA,MACA,OAAA;AAAA,MACA;AAAA,KACF,CAAA;AAAA,IACA;AAAA,MACE,SAAA;AAAA,MACA,mBAAA;AAAA,MACA,SAAA;AAAA,MACA,gBAAA;AAAA,MACA,iBAAA;AAAA,MACA,OAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAA,2BACG,eAAA,CAAgB,QAAA,EAAhB,EAAyB,KAAA,EAAO,cAC9B,QAAA,EACH,CAAA;AAEJ;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuActions.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { makePrefixer } from '@salt-ds/core';
|
|
3
|
-
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
4
|
-
import { useWindow } from '@salt-ds/window';
|
|
5
|
-
import { clsx } from 'clsx';
|
|
6
|
-
import { forwardRef } from 'react';
|
|
7
|
-
import css_248z from './MegaMenuActions.css.js';
|
|
8
|
-
|
|
9
|
-
const withBaseName = makePrefixer("saltMegaMenuActions");
|
|
10
|
-
const MegaMenuActions = forwardRef(
|
|
11
|
-
function MegaMenuActions2({ className, ...rest }, ref) {
|
|
12
|
-
const targetWindow = useWindow();
|
|
13
|
-
useComponentCssInjection({
|
|
14
|
-
testId: "salt-mega-menu-actions",
|
|
15
|
-
css: css_248z,
|
|
16
|
-
window: targetWindow
|
|
17
|
-
});
|
|
18
|
-
return /* @__PURE__ */ jsx(
|
|
19
|
-
"div",
|
|
20
|
-
{
|
|
21
|
-
"data-mega-menu-actions": "",
|
|
22
|
-
className: clsx(withBaseName(), className),
|
|
23
|
-
ref,
|
|
24
|
-
...rest
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
export { MegaMenuActions };
|
|
31
|
-
//# sourceMappingURL=MegaMenuActions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuActions.js","sources":["../src/mega-menu/MegaMenuActions.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport {\n type ComponentPropsWithoutRef,\n forwardRef,\n type ReactNode,\n} from \"react\";\nimport megaMenuActionsCss from \"./MegaMenuActions.css\";\n\nconst withBaseName = makePrefixer(\"saltMegaMenuActions\");\n\nexport interface MegaMenuActionsProps extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The content of the actions. Place `MegaMenuActions` inside\n * `MegaMenuContent`, after `MegaMenuGroups`; it renders as a band beneath the\n * groups, spanning their width.\n */\n children?: ReactNode;\n}\n\nexport const MegaMenuActions = forwardRef<HTMLDivElement, MegaMenuActionsProps>(\n function MegaMenuActions({ className, ...rest }, ref) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-mega-menu-actions\",\n css: megaMenuActionsCss,\n window: targetWindow,\n });\n\n return (\n <div\n data-mega-menu-actions=\"\"\n className={clsx(withBaseName(), className)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\n"],"names":["MegaMenuActions","megaMenuActionsCss"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe,aAAa,qBAAqB,CAAA;AAWhD,MAAM,eAAA,GAAkB,UAAA;AAAA,EAC7B,SAASA,gBAAAA,CAAgB,EAAE,WAAW,GAAG,IAAA,IAAQ,GAAA,EAAK;AACpD,IAAA,MAAM,eAAe,SAAA,EAAU;AAC/B,IAAA,wBAAA,CAAyB;AAAA,MACvB,MAAA,EAAQ,wBAAA;AAAA,MACR,GAAA,EAAKC,QAAA;AAAA,MACL,MAAA,EAAQ;AAAA,KACT,CAAA;AAED,IAAA,uBACE,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,wBAAA,EAAuB,EAAA;AAAA,QACvB,SAAA,EAAW,IAAA,CAAK,YAAA,EAAa,EAAG,SAAS,CAAA;AAAA,QACzC,GAAA;AAAA,QACC,GAAG;AAAA;AAAA,KACN;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuAside.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { makePrefixer } from '@salt-ds/core';
|
|
3
|
-
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
4
|
-
import { useWindow } from '@salt-ds/window';
|
|
5
|
-
import { clsx } from 'clsx';
|
|
6
|
-
import { forwardRef } from 'react';
|
|
7
|
-
import css_248z from './MegaMenuAside.css.js';
|
|
8
|
-
|
|
9
|
-
const withBaseName = makePrefixer("saltMegaMenuAside");
|
|
10
|
-
const MegaMenuAside = forwardRef(
|
|
11
|
-
function MegaMenuAside2({ className, ...rest }, ref) {
|
|
12
|
-
const targetWindow = useWindow();
|
|
13
|
-
useComponentCssInjection({
|
|
14
|
-
testId: "salt-mega-menu-aside",
|
|
15
|
-
css: css_248z,
|
|
16
|
-
window: targetWindow
|
|
17
|
-
});
|
|
18
|
-
return /* @__PURE__ */ jsx(
|
|
19
|
-
"aside",
|
|
20
|
-
{
|
|
21
|
-
"data-mega-menu-column": "",
|
|
22
|
-
className: clsx(withBaseName(), className),
|
|
23
|
-
ref,
|
|
24
|
-
...rest
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
export { MegaMenuAside };
|
|
31
|
-
//# sourceMappingURL=MegaMenuAside.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuAside.js","sources":["../src/mega-menu/MegaMenuAside.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport {\n type ComponentPropsWithoutRef,\n forwardRef,\n type ReactNode,\n} from \"react\";\nimport megaMenuAsideCss from \"./MegaMenuAside.css\";\n\nconst withBaseName = makePrefixer(\"saltMegaMenuAside\");\n\nexport interface MegaMenuAsideProps extends ComponentPropsWithoutRef<\"aside\"> {\n /**\n * The content. Renders to the left of `MegaMenuContent` when placed before\n * it, and to the right when placed after.\n */\n children?: ReactNode;\n}\n\nexport const MegaMenuAside = forwardRef<HTMLElement, MegaMenuAsideProps>(\n function MegaMenuAside({ className, ...rest }, ref) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-mega-menu-aside\",\n css: megaMenuAsideCss,\n window: targetWindow,\n });\n\n // Side content is also a navigation column (`data-mega-menu-column`).\n return (\n <aside\n data-mega-menu-column=\"\"\n className={clsx(withBaseName(), className)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\n"],"names":["MegaMenuAside","megaMenuAsideCss"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe,aAAa,mBAAmB,CAAA;AAU9C,MAAM,aAAA,GAAgB,UAAA;AAAA,EAC3B,SAASA,cAAAA,CAAc,EAAE,WAAW,GAAG,IAAA,IAAQ,GAAA,EAAK;AAClD,IAAA,MAAM,eAAe,SAAA,EAAU;AAC/B,IAAA,wBAAA,CAAyB;AAAA,MACvB,MAAA,EAAQ,sBAAA;AAAA,MACR,GAAA,EAAKC,QAAA;AAAA,MACL,MAAA,EAAQ;AAAA,KACT,CAAA;AAGD,IAAA,uBACE,GAAA;AAAA,MAAC,OAAA;AAAA,MAAA;AAAA,QACC,uBAAA,EAAsB,EAAA;AAAA,QACtB,SAAA,EAAW,IAAA,CAAK,YAAA,EAAa,EAAG,SAAS,CAAA;AAAA,QACzC,GAAA;AAAA,QACC,GAAG;AAAA;AAAA,KACN;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var css_248z = ".saltMegaMenuContent {\n display: flex;\n flex-direction: column;\n gap: var(--salt-spacing-300);\n padding: var(--salt-spacing-300);\n min-width: 0;\n flex: 0 1 auto;\n max-inline-size: var(--saltMegaMenuPanel-availableWidth);\n box-sizing: border-box;\n}\n";
|
|
2
|
-
|
|
3
|
-
export { css_248z as default };
|
|
4
|
-
//# sourceMappingURL=MegaMenuContent.css.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuContent.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { makePrefixer } from '@salt-ds/core';
|
|
3
|
-
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
4
|
-
import { useWindow } from '@salt-ds/window';
|
|
5
|
-
import { clsx } from 'clsx';
|
|
6
|
-
import { forwardRef } from 'react';
|
|
7
|
-
import css_248z from './MegaMenuContent.css.js';
|
|
8
|
-
|
|
9
|
-
const withBaseName = makePrefixer("saltMegaMenuContent");
|
|
10
|
-
const MegaMenuContent = forwardRef(
|
|
11
|
-
function MegaMenuContent2({ children, className, ...rest }, ref) {
|
|
12
|
-
const targetWindow = useWindow();
|
|
13
|
-
useComponentCssInjection({
|
|
14
|
-
testId: "salt-mega-menu-content",
|
|
15
|
-
css: css_248z,
|
|
16
|
-
window: targetWindow
|
|
17
|
-
});
|
|
18
|
-
return /* @__PURE__ */ jsx("div", { className: clsx(withBaseName(), className), ref, ...rest, children });
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export { MegaMenuContent };
|
|
23
|
-
//# sourceMappingURL=MegaMenuContent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuContent.js","sources":["../src/mega-menu/MegaMenuContent.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport {\n type ComponentPropsWithoutRef,\n forwardRef,\n type ReactNode,\n} from \"react\";\nimport megaMenuContentCss from \"./MegaMenuContent.css\";\n\nconst withBaseName = makePrefixer(\"saltMegaMenuContent\");\n\nexport interface MegaMenuContentProps extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The content of the mega menu navigation area, typically a `MegaMenuGroups`\n * and an optional `MegaMenuActions`.\n */\n children?: ReactNode;\n}\n\nexport const MegaMenuContent = forwardRef<HTMLDivElement, MegaMenuContentProps>(\n function MegaMenuContent({ children, className, ...rest }, ref) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-mega-menu-content\",\n css: megaMenuContentCss,\n window: targetWindow,\n });\n\n return (\n <div className={clsx(withBaseName(), className)} ref={ref} {...rest}>\n {children}\n </div>\n );\n },\n);\n"],"names":["MegaMenuContent","megaMenuContentCss"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe,aAAa,qBAAqB,CAAA;AAUhD,MAAM,eAAA,GAAkB,UAAA;AAAA,EAC7B,SAASA,iBAAgB,EAAE,QAAA,EAAU,WAAW,GAAG,IAAA,IAAQ,GAAA,EAAK;AAC9D,IAAA,MAAM,eAAe,SAAA,EAAU;AAC/B,IAAA,wBAAA,CAAyB;AAAA,MACvB,MAAA,EAAQ,wBAAA;AAAA,MACR,GAAA,EAAKC,QAAA;AAAA,MACL,MAAA,EAAQ;AAAA,KACT,CAAA;AAED,IAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAW,IAAA,CAAK,YAAA,EAAa,EAAG,SAAS,CAAA,EAAG,GAAA,EAAW,GAAG,IAAA,EAC5D,QAAA,EACH,CAAA;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuContext.js","sources":["../src/mega-menu/MegaMenuContext.ts"],"sourcesContent":["import type { FloatingRootContext } from \"@floating-ui/react\";\nimport { createContext } from \"@salt-ds/core\";\nimport type {\n Dispatch,\n HTMLProps,\n MutableRefObject,\n SetStateAction,\n} from \"react\";\nimport type { MegaMenuPlacement } from \"./MegaMenu\";\n\nexport interface MegaMenuContextValue {\n /** Whether the mega menu is currently open. */\n openState: boolean;\n /** Toggle or set the open state of the mega menu. */\n setOpen: (open: boolean) => void;\n /** The floating-ui root context for coordinating interactions. */\n floatingRootContext: FloatingRootContext;\n /** The placement of the mega menu panel relative to the trigger. */\n placement: MegaMenuPlacement;\n /** Props getter for the trigger (reference) element. Merges floating-ui interaction props with user props. */\n getReferenceProps: (\n userProps?: HTMLProps<Element> | undefined,\n ) => Record<string, unknown>;\n /** Props getter for the floating panel element. Merges floating-ui interaction props with user props. */\n getFloatingProps: (\n userProps?: HTMLProps<HTMLElement> | undefined,\n ) => Record<string, unknown>;\n /** Ref setter for the floating panel element. */\n setFloating: Dispatch<SetStateAction<HTMLElement | null>>;\n /** Ref setter for the trigger (reference) element. */\n setReference: Dispatch<SetStateAction<HTMLElement | null>>;\n /** Whether the first item should receive focus when the panel opens. */\n focusFirstItemOnOpenRef: MutableRefObject<boolean>;\n /** The id of the mega menu panel, used for aria-controls on the trigger. */\n panelId: string | undefined;\n /** Registers the panel's id so the trigger's aria-controls stays in sync. */\n setPanelId: Dispatch<SetStateAction<string | undefined>>;\n}\n\nexport const MegaMenuContext = createContext<MegaMenuContextValue | undefined>(\n \"MegaMenuContext\",\n undefined,\n);\n"],"names":[],"mappings":";;AAuCO,MAAM,eAAA,GAAkB,aAAA;AAAA,EAC7B,iBAAA;AAAA,EACA;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MegaMenuGroup.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { makePrefixer } from '@salt-ds/core';
|
|
3
|
-
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
4
|
-
import { useWindow } from '@salt-ds/window';
|
|
5
|
-
import { clsx } from 'clsx';
|
|
6
|
-
import { forwardRef, useState, useMemo } from 'react';
|
|
7
|
-
import css_248z from './MegaMenuGroup.css.js';
|
|
8
|
-
import { MegaMenuGroupContext } from './MegaMenuGroupContext.js';
|
|
9
|
-
|
|
10
|
-
const withBaseName = makePrefixer("saltMegaMenuGroup");
|
|
11
|
-
const MegaMenuGroup = forwardRef(
|
|
12
|
-
function MegaMenuGroup2({ children, className, ...rest }, ref) {
|
|
13
|
-
const targetWindow = useWindow();
|
|
14
|
-
useComponentCssInjection({
|
|
15
|
-
testId: "salt-mega-menu-group",
|
|
16
|
-
css: css_248z,
|
|
17
|
-
window: targetWindow
|
|
18
|
-
});
|
|
19
|
-
const [headingId, setHeadingId] = useState(void 0);
|
|
20
|
-
const contextValue = useMemo(
|
|
21
|
-
() => ({ headingId, setHeadingId }),
|
|
22
|
-
[headingId]
|
|
23
|
-
);
|
|
24
|
-
return /* @__PURE__ */ jsx(MegaMenuGroupContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
25
|
-
"div",
|
|
26
|
-
{
|
|
27
|
-
"data-mega-menu-column": "",
|
|
28
|
-
className: clsx(withBaseName(), className),
|
|
29
|
-
ref,
|
|
30
|
-
...rest,
|
|
31
|
-
children
|
|
32
|
-
}
|
|
33
|
-
) });
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
export { MegaMenuGroup };
|
|
38
|
-
//# sourceMappingURL=MegaMenuGroup.js.map
|