@dmsi/wedgekit-react 0.0.550 → 0.0.552
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/dist/{chunk-U3QGZAVS.js → chunk-JADOJNBI.js} +4 -4
- package/dist/{chunk-N2KPADIL.js → chunk-WNGFRQ4Y.js} +7 -7
- package/dist/{chunk-ZVY3TLXL.js → chunk-ZIPJMN2E.js} +4 -4
- package/dist/components/Alert.js +2 -2
- package/dist/components/CalendarRange.js +10 -10
- package/dist/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.js +10 -10
- package/dist/components/DataGrid/ColumnSelectorHeaderCell/index.js +10 -10
- package/dist/components/DataGrid/PinnedColumns.js +10 -10
- package/dist/components/DataGrid/TableBody/LoadingCell.js +10 -10
- package/dist/components/DataGrid/TableBody/TableBodyRow.js +10 -10
- package/dist/components/DataGrid/TableBody/index.js +10 -10
- package/dist/components/DataGrid/index.js +10 -10
- package/dist/components/DataGrid/utils.js +10 -10
- package/dist/components/DateInput.js +10 -10
- package/dist/components/DateRangeInput.js +10 -10
- package/dist/components/FilterGroup.js +5 -5
- package/dist/components/MobileDataGrid/ColumnSelector/index.js +10 -10
- package/dist/components/MobileDataGrid/MobileDataGridHeader.js +10 -10
- package/dist/components/MobileDataGrid/RowDetailModalProvider/index.js +5 -5
- package/dist/components/MobileDataGrid/index.js +10 -10
- package/dist/components/Modal.js +4 -4
- package/dist/components/ModalButtons.js +2 -2
- package/dist/components/ModalHeader.js +2 -2
- package/dist/components/NavigationTab.js +2 -2
- package/dist/components/NavigationTabs.js +2 -2
- package/dist/components/NestedMenu.js +3 -3
- package/dist/components/Notification.js +3 -3
- package/dist/components/OptionPill.js +2 -2
- package/dist/components/PDFViewer/DownloadIcon.js +2 -2
- package/dist/components/PDFViewer/PDFNavigation.js +2 -2
- package/dist/components/PDFViewer/index.js +6 -6
- package/dist/components/ProductImagePreview/index.js +1 -1
- package/dist/components/Stepper.js +3 -3
- package/dist/components/Toast.js +3 -3
- package/dist/components/Upload.js +3 -3
- package/dist/components/index.js +16 -16
- package/package.json +8 -9
- package/src/brand.css +0 -125
- package/src/classNames.ts +0 -174
- package/src/components/AccessChangerTabItem.tsx +0 -71
- package/src/components/Accordion.tsx +0 -108
- package/src/components/Alert.tsx +0 -81
- package/src/components/Breadcrumbs.tsx +0 -142
- package/src/components/Button.tsx +0 -216
- package/src/components/CalendarRange.tsx +0 -628
- package/src/components/Caption.tsx +0 -144
- package/src/components/Card.tsx +0 -88
- package/src/components/Checkbox.tsx +0 -206
- package/src/components/CompactImagesPreview.tsx +0 -135
- package/src/components/ContentTab.tsx +0 -84
- package/src/components/ContentTabs.tsx +0 -136
- package/src/components/DMSiLogo.tsx +0 -33
- package/src/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.tsx +0 -35
- package/src/components/DataGrid/ColumnSelectorHeaderCell/index.tsx +0 -74
- package/src/components/DataGrid/PinnedColumns.tsx +0 -183
- package/src/components/DataGrid/TableBody/LoadingCell.tsx +0 -44
- package/src/components/DataGrid/TableBody/TableBodyRow.tsx +0 -157
- package/src/components/DataGrid/TableBody/index.tsx +0 -185
- package/src/components/DataGrid/index.tsx +0 -756
- package/src/components/DataGrid/types.ts +0 -98
- package/src/components/DataGrid/utils.tsx +0 -15
- package/src/components/DataGridCell.tsx +0 -526
- package/src/components/DataTable.tsx +0 -881
- package/src/components/DateInput.tsx +0 -306
- package/src/components/DateRangeInput.tsx +0 -758
- package/src/components/DebugJson.tsx +0 -28
- package/src/components/Display.tsx +0 -66
- package/src/components/EditingContext.tsx +0 -43
- package/src/components/EmptyCartIcon.tsx +0 -18
- package/src/components/FilterGroup.tsx +0 -264
- package/src/components/FullViewportBox.tsx +0 -19
- package/src/components/Grid.tsx +0 -97
- package/src/components/Heading.tsx +0 -72
- package/src/components/HorizontalDivider.tsx +0 -22
- package/src/components/Icon.tsx +0 -39
- package/src/components/ImagePlaceholder.tsx +0 -22
- package/src/components/Input.tsx +0 -609
- package/src/components/InputGroup.tsx +0 -59
- package/src/components/Label.tsx +0 -46
- package/src/components/Link.tsx +0 -117
- package/src/components/List.tsx +0 -18
- package/src/components/ListGroup.tsx +0 -82
- package/src/components/LiveChatComponent.tsx +0 -56
- package/src/components/LoadingScrim.tsx +0 -33
- package/src/components/LogoAgilityTopBar.tsx +0 -54
- package/src/components/LogoDMSiTopBar.tsx +0 -33
- package/src/components/LogoMillworkTopBar.tsx +0 -119
- package/src/components/MainBar.tsx +0 -91
- package/src/components/MaxViewportBox.tsx +0 -19
- package/src/components/Menu.tsx +0 -316
- package/src/components/MenuOption.tsx +0 -330
- package/src/components/MobileDataGrid/ColumnList.tsx +0 -66
- package/src/components/MobileDataGrid/ColumnSelector/index.tsx +0 -97
- package/src/components/MobileDataGrid/GridContextProvider/GridContext.tsx +0 -25
- package/src/components/MobileDataGrid/GridContextProvider/index.tsx +0 -132
- package/src/components/MobileDataGrid/GridContextProvider/useGridContext.ts +0 -10
- package/src/components/MobileDataGrid/MobileDataGridCard/MobileDataGridColumn.tsx +0 -27
- package/src/components/MobileDataGrid/MobileDataGridCard/index.tsx +0 -138
- package/src/components/MobileDataGrid/MobileDataGridHeader.tsx +0 -81
- package/src/components/MobileDataGrid/RowDetailModalProvider/ModalContent.tsx +0 -42
- package/src/components/MobileDataGrid/RowDetailModalProvider/index.tsx +0 -68
- package/src/components/MobileDataGrid/dataGridReducer.ts +0 -55
- package/src/components/MobileDataGrid/index.tsx +0 -92
- package/src/components/MobileDataGrid/types.ts +0 -4
- package/src/components/Modal.tsx +0 -312
- package/src/components/ModalButtons.tsx +0 -62
- package/src/components/ModalContent.tsx +0 -31
- package/src/components/ModalHeader.tsx +0 -78
- package/src/components/ModalScrim.tsx +0 -42
- package/src/components/NavigationTab.tsx +0 -95
- package/src/components/NavigationTabs.tsx +0 -70
- package/src/components/NestedMenu.tsx +0 -131
- package/src/components/Notification.tsx +0 -128
- package/src/components/OptionPill.tsx +0 -139
- package/src/components/OrderCheckIcon.tsx +0 -19
- package/src/components/PDFViewer/DownloadIcon.tsx +0 -25
- package/src/components/PDFViewer/PDFElement.tsx +0 -90
- package/src/components/PDFViewer/PDFNavigation.tsx +0 -68
- package/src/components/PDFViewer/PDFPage.tsx +0 -34
- package/src/components/PDFViewer/index.tsx +0 -128
- package/src/components/Pagination.tsx +0 -182
- package/src/components/Paragraph.tsx +0 -55
- package/src/components/Password.tsx +0 -62
- package/src/components/ProductImagePreview/CarouselPagination.tsx +0 -54
- package/src/components/ProductImagePreview/MobileImageCarousel.tsx +0 -226
- package/src/components/ProductImagePreview/ProductPrimaryImage.tsx +0 -219
- package/src/components/ProductImagePreview/Thumbnail.tsx +0 -55
- package/src/components/ProductImagePreview/ZoomWindow.tsx +0 -136
- package/src/components/ProductImagePreview/index.tsx +0 -182
- package/src/components/ProductImagePreview/useProductImagePreview.ts +0 -211
- package/src/components/ProjectBar.tsx +0 -82
- package/src/components/Radio.tsx +0 -146
- package/src/components/Search.tsx +0 -152
- package/src/components/SearchResultImage/index.tsx +0 -39
- package/src/components/Select.tsx +0 -114
- package/src/components/SideMenu.tsx +0 -30
- package/src/components/SideMenuGroup.tsx +0 -95
- package/src/components/SideMenuItem.tsx +0 -109
- package/src/components/SimpleTable.tsx +0 -77
- package/src/components/SkeletonParagraph.tsx +0 -31
- package/src/components/Spinner.tsx +0 -32
- package/src/components/Stack.tsx +0 -347
- package/src/components/StatusPill.tsx +0 -59
- package/src/components/Stepper.tsx +0 -128
- package/src/components/Subheader.tsx +0 -50
- package/src/components/Surface.tsx +0 -37
- package/src/components/Swatch.tsx +0 -1341
- package/src/components/Textarea.tsx +0 -102
- package/src/components/Theme.tsx +0 -27
- package/src/components/Time.tsx +0 -460
- package/src/components/Toast.tsx +0 -268
- package/src/components/Tooltip.tsx +0 -159
- package/src/components/TopBar.tsx +0 -139
- package/src/components/Upload.tsx +0 -107
- package/src/components/WorldpayIframe.tsx +0 -7
- package/src/components/index.ts +0 -34
- package/src/components/useMenuSystem.tsx +0 -456
- package/src/components/useMounted.tsx +0 -14
- package/src/darkmode.css +0 -278
- package/src/fonts.css +0 -23
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useInfiniteScroll.tsx +0 -40
- package/src/hooks/useKeydown.ts +0 -42
- package/src/hooks/useMatchesMedia.ts +0 -18
- package/src/hooks/useTableLayout.ts +0 -106
- package/src/index.css +0 -800
- package/src/index.tsx +0 -5
- package/src/types.ts +0 -150
- package/src/utils/date.ts +0 -236
- package/src/utils/formatting.tsx +0 -81
- package/src/utils/index.ts +0 -4
- package/src/utils/mergeObjectArrays.ts +0 -18
- package/src/utils.ts +0 -24
- package/dist/{chunk-7FQ7PGUF.js → chunk-7COWXCPA.js} +3 -3
- package/dist/{chunk-NKCFYM7A.js → chunk-7SFFUICM.js} +3 -3
- package/dist/{chunk-25RZP3VR.js → chunk-AKJUBFJK.js} +3 -3
- package/dist/{chunk-TAPYQBQU.js → chunk-CMMQTIVM.js} +3 -3
- package/dist/{chunk-GYEXSNFP.js → chunk-FWCVZWE6.js} +3 -3
- package/dist/{chunk-MV6W7OMC.js → chunk-QMMPHXVE.js} +3 -3
- package/dist/{chunk-GG5OZTI5.js → chunk-XRE52QTN.js} +3 -3
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useState, useRef, useEffect, RefObject, useCallback } from "react";
|
|
4
|
-
import { useMatchesMobile } from "../hooks";
|
|
5
|
-
|
|
6
|
-
type MenuPosition = {
|
|
7
|
-
top: number;
|
|
8
|
-
left: number;
|
|
9
|
-
minWidth: number;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function useSubMenuSystem(
|
|
13
|
-
mobilePositionTo: RefObject<HTMLElement | null>,
|
|
14
|
-
) {
|
|
15
|
-
const [activeMenus, setActiveMenus] = useState<{ [level: number]: string }>(
|
|
16
|
-
{},
|
|
17
|
-
);
|
|
18
|
-
const [activeMenu, setActiveMenu] = useState("");
|
|
19
|
-
const [currentSubMenuLevel, setCurrentSubMenuLevel] = useState<number | null>(
|
|
20
|
-
null,
|
|
21
|
-
);
|
|
22
|
-
const menuRootRef = useRef<HTMLDivElement>(null);
|
|
23
|
-
const subMenuRefs = useRef<{ [id: string]: HTMLElement | null }>({});
|
|
24
|
-
const hoverTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
25
|
-
const closeTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
26
|
-
const mouseStopTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
27
|
-
const isMouseMovingRef = useRef(false);
|
|
28
|
-
const pendingOpenActionRef = useRef<(() => void) | null>(null);
|
|
29
|
-
const pendingCloseActionRef = useRef<(() => void) | null>(null);
|
|
30
|
-
const isMobile = useMatchesMobile();
|
|
31
|
-
|
|
32
|
-
const toggleMenu = (menuId: string, level: number) => {
|
|
33
|
-
if (closeTimeoutRef.current) {
|
|
34
|
-
clearTimeout(closeTimeoutRef.current);
|
|
35
|
-
closeTimeoutRef.current = null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
setActiveMenu(menuId);
|
|
39
|
-
setCurrentSubMenuLevel(level);
|
|
40
|
-
|
|
41
|
-
setActiveMenus((prev) => {
|
|
42
|
-
const newActiveMenus = { ...prev };
|
|
43
|
-
if (newActiveMenus[level] === menuId) {
|
|
44
|
-
delete newActiveMenus[level];
|
|
45
|
-
} else {
|
|
46
|
-
newActiveMenus[level] = menuId;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
Object.keys(newActiveMenus).forEach((key) => {
|
|
50
|
-
if (Number(key) > level) {
|
|
51
|
-
delete newActiveMenus[Number(key)];
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return newActiveMenus;
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const openMenu = (menuId: string, level: number) => {
|
|
60
|
-
if (closeTimeoutRef.current) {
|
|
61
|
-
clearTimeout(closeTimeoutRef.current);
|
|
62
|
-
closeTimeoutRef.current = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setActiveMenus((prev) => {
|
|
66
|
-
const newActiveMenus = { ...prev };
|
|
67
|
-
newActiveMenus[level] = menuId;
|
|
68
|
-
|
|
69
|
-
Object.keys(newActiveMenus).forEach((key) => {
|
|
70
|
-
if (Number(key) > level) {
|
|
71
|
-
delete newActiveMenus[Number(key)];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return newActiveMenus;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const executePendingActions = useCallback(() => {
|
|
80
|
-
if (pendingCloseActionRef.current) {
|
|
81
|
-
pendingCloseActionRef.current();
|
|
82
|
-
pendingCloseActionRef.current = null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (pendingOpenActionRef.current) {
|
|
86
|
-
pendingOpenActionRef.current();
|
|
87
|
-
pendingOpenActionRef.current = null;
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const openMenuWithDelay = (menuId: string, level: number, delay = 150) => {
|
|
92
|
-
if (isMobile) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
pendingOpenActionRef.current = () => {
|
|
97
|
-
if (hoverTimeoutRef.current) {
|
|
98
|
-
clearTimeout(hoverTimeoutRef.current);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
hoverTimeoutRef.current = setTimeout(() => {
|
|
102
|
-
openMenu(menuId, level);
|
|
103
|
-
}, delay);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!isMouseMovingRef.current) {
|
|
107
|
-
executePendingActions();
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const closeMenuWithDelay = (level: number, delay = 500) => {
|
|
112
|
-
if (isMobile) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
pendingCloseActionRef.current = () => {
|
|
117
|
-
if (hoverTimeoutRef.current) {
|
|
118
|
-
clearTimeout(hoverTimeoutRef.current);
|
|
119
|
-
hoverTimeoutRef.current = null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
closeTimeoutRef.current = setTimeout(() => {
|
|
123
|
-
closeSubMenuLevel(level);
|
|
124
|
-
}, delay);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!isMouseMovingRef.current) {
|
|
128
|
-
executePendingActions();
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const handleMouseMove = () => {
|
|
133
|
-
isMouseMovingRef.current = true;
|
|
134
|
-
|
|
135
|
-
if (mouseStopTimeoutRef.current) {
|
|
136
|
-
clearTimeout(mouseStopTimeoutRef.current);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
mouseStopTimeoutRef.current = setTimeout(() => {
|
|
140
|
-
isMouseMovingRef.current = false;
|
|
141
|
-
executePendingActions();
|
|
142
|
-
}, 200);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const cancelCloseTimeout = () => {
|
|
146
|
-
if (isMobile) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (mouseStopTimeoutRef.current) {
|
|
151
|
-
clearTimeout(mouseStopTimeoutRef.current);
|
|
152
|
-
mouseStopTimeoutRef.current = null;
|
|
153
|
-
isMouseMovingRef.current = false;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const closeSubMenuLevel = (level: number) => {
|
|
158
|
-
setActiveMenus((prev) => {
|
|
159
|
-
const newActiveMenus = { ...prev };
|
|
160
|
-
|
|
161
|
-
delete newActiveMenus[level];
|
|
162
|
-
|
|
163
|
-
Object.keys(newActiveMenus).forEach((key) => {
|
|
164
|
-
if (Number(key) >= level) {
|
|
165
|
-
delete newActiveMenus[Number(key)];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
if (isMobile) {
|
|
170
|
-
const newSubMenuLevel = level - 1;
|
|
171
|
-
setCurrentSubMenuLevel(newSubMenuLevel);
|
|
172
|
-
const newActiveMenu = newActiveMenus[newSubMenuLevel];
|
|
173
|
-
|
|
174
|
-
if (Object.keys(newActiveMenus).length > 0 && newActiveMenu) {
|
|
175
|
-
setActiveMenu(newActiveMenu);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return newActiveMenus;
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const registerSubMenu = (id: string, element: HTMLElement | null) => {
|
|
184
|
-
subMenuRefs.current[id] = element;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const isMenuActive = (menuId: string, level: number) => {
|
|
188
|
-
return activeMenus[level] === menuId;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
193
|
-
if (Object.keys(activeMenus).length === 0) return;
|
|
194
|
-
|
|
195
|
-
const target = event.target as Node;
|
|
196
|
-
|
|
197
|
-
if (menuRootRef.current?.contains(target)) return;
|
|
198
|
-
|
|
199
|
-
const isInsideActiveSubmenu = Object.values(activeMenus).some((id) => {
|
|
200
|
-
const submenuEl = subMenuRefs.current[id];
|
|
201
|
-
return submenuEl?.contains(target);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
if (!isInsideActiveSubmenu) {
|
|
205
|
-
setActiveMenus({});
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
210
|
-
return () => {
|
|
211
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
212
|
-
};
|
|
213
|
-
}, [activeMenus]);
|
|
214
|
-
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
return () => {
|
|
217
|
-
if (hoverTimeoutRef.current) {
|
|
218
|
-
clearTimeout(hoverTimeoutRef.current);
|
|
219
|
-
}
|
|
220
|
-
if (closeTimeoutRef.current) {
|
|
221
|
-
clearTimeout(closeTimeoutRef.current);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}, []);
|
|
225
|
-
|
|
226
|
-
const getAllFocusableMenuElements = (): HTMLElement[] => {
|
|
227
|
-
const elements: HTMLElement[] = [];
|
|
228
|
-
|
|
229
|
-
if (menuRootRef.current) {
|
|
230
|
-
elements.push(
|
|
231
|
-
...(Array.from(menuRootRef.current.children) as HTMLElement[]),
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
Object.values(activeMenus).forEach((menuId) => {
|
|
236
|
-
const submenuEl = subMenuRefs.current[menuId];
|
|
237
|
-
if (submenuEl) {
|
|
238
|
-
elements.push(...(Array.from(submenuEl.children) as HTMLElement[]));
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
return elements;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const findCurrentMenuLevel = (element: Element): number => {
|
|
246
|
-
let current = element.parentElement;
|
|
247
|
-
while (current) {
|
|
248
|
-
const level = current.getAttribute("data-menu-level");
|
|
249
|
-
if (level !== null) {
|
|
250
|
-
return parseInt(level, 10);
|
|
251
|
-
}
|
|
252
|
-
current = current.parentElement;
|
|
253
|
-
}
|
|
254
|
-
return 0;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const getMenuElementsAtLevel = (level: number): HTMLElement[] => {
|
|
258
|
-
if (level === 0 && menuRootRef.current) {
|
|
259
|
-
return Array.from(menuRootRef.current.children) as HTMLElement[];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const menuId = Object.entries(activeMenus).find(([, id]) => {
|
|
263
|
-
const submenuEl = subMenuRefs.current[id];
|
|
264
|
-
return (
|
|
265
|
-
submenuEl &&
|
|
266
|
-
submenuEl.getAttribute("data-menu-level") === level.toString()
|
|
267
|
-
);
|
|
268
|
-
})?.[1];
|
|
269
|
-
|
|
270
|
-
if (menuId) {
|
|
271
|
-
const submenuEl = subMenuRefs.current[menuId];
|
|
272
|
-
if (submenuEl) {
|
|
273
|
-
return Array.from(submenuEl.children) as HTMLElement[];
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return [];
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
return {
|
|
281
|
-
menuRootRef,
|
|
282
|
-
activeMenus,
|
|
283
|
-
openMenu,
|
|
284
|
-
isMenuActive,
|
|
285
|
-
registerSubMenu,
|
|
286
|
-
closeSubMenuLevel,
|
|
287
|
-
getAllFocusableMenuElements,
|
|
288
|
-
findCurrentMenuLevel,
|
|
289
|
-
getMenuElementsAtLevel,
|
|
290
|
-
mobileHide: isMobile && Object.keys(activeMenus).length > 0,
|
|
291
|
-
listeners: {
|
|
292
|
-
onSubMenuHover: openMenuWithDelay,
|
|
293
|
-
onSubMenuLeave: closeMenuWithDelay,
|
|
294
|
-
onSubMenuEnter: cancelCloseTimeout,
|
|
295
|
-
onMouseMove: handleMouseMove,
|
|
296
|
-
toggleMenu,
|
|
297
|
-
mobilePositionTo,
|
|
298
|
-
activeMenu,
|
|
299
|
-
currentSubMenuLevel,
|
|
300
|
-
closeSubMenuLevel,
|
|
301
|
-
},
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export function useMenuPosition(
|
|
306
|
-
elementRef: RefObject<HTMLElement | null>,
|
|
307
|
-
position: "right" | "bottom" | "bottom-right" = "bottom",
|
|
308
|
-
options?: {
|
|
309
|
-
isOpen?: boolean;
|
|
310
|
-
setIsOpen?: (isOpen: boolean) => void;
|
|
311
|
-
menuRef?: RefObject<HTMLElement | null>;
|
|
312
|
-
additionalRefs?: RefObject<HTMLElement | null>[];
|
|
313
|
-
topOffset?: number | null;
|
|
314
|
-
isMobile?: boolean;
|
|
315
|
-
},
|
|
316
|
-
) {
|
|
317
|
-
const [menuPosition, setMenuPosition] = useState<MenuPosition>({
|
|
318
|
-
top: 0,
|
|
319
|
-
left: 0,
|
|
320
|
-
minWidth: 0,
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
const isMobile = options?.isMobile;
|
|
324
|
-
|
|
325
|
-
const updatePosition = useCallback(() => {
|
|
326
|
-
if (!elementRef?.current) return;
|
|
327
|
-
|
|
328
|
-
const triggerRect = elementRef.current.getBoundingClientRect();
|
|
329
|
-
const menuRect = options?.menuRef?.current?.getBoundingClientRect();
|
|
330
|
-
const viewportWidth = window.innerWidth;
|
|
331
|
-
|
|
332
|
-
const menuWidth = menuRect?.width || triggerRect.width;
|
|
333
|
-
const topOffset = options?.topOffset ?? 4;
|
|
334
|
-
|
|
335
|
-
let top = 0;
|
|
336
|
-
let left = 0;
|
|
337
|
-
|
|
338
|
-
if (position === "bottom" || position === "bottom-right") {
|
|
339
|
-
top = triggerRect.top + triggerRect.height + topOffset;
|
|
340
|
-
} else {
|
|
341
|
-
top = triggerRect.top;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (position === "bottom") {
|
|
345
|
-
left = triggerRect.left + window.scrollX;
|
|
346
|
-
} else if (position === "bottom-right") {
|
|
347
|
-
left = triggerRect.right + window.scrollX - menuWidth;
|
|
348
|
-
} else if (position === "right") {
|
|
349
|
-
if (isMobile) {
|
|
350
|
-
left = triggerRect.left + window.scrollX
|
|
351
|
-
} else {
|
|
352
|
-
left = triggerRect.right + window.scrollX;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const overflowsRightViewport = left + menuWidth > viewportWidth;
|
|
357
|
-
|
|
358
|
-
if (overflowsRightViewport) {
|
|
359
|
-
const newLeft = triggerRect.left - menuWidth;
|
|
360
|
-
const overflowsLeftViewport = newLeft < 0;
|
|
361
|
-
|
|
362
|
-
if (overflowsLeftViewport) {
|
|
363
|
-
left = (viewportWidth - menuWidth) / 2;
|
|
364
|
-
} else {
|
|
365
|
-
left = newLeft;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (isMobile && position === "right") {
|
|
370
|
-
top = triggerRect.top + triggerRect.height + topOffset;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (isMobile && menuWidth > viewportWidth) {
|
|
374
|
-
left = 0;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
setMenuPosition({
|
|
378
|
-
top,
|
|
379
|
-
left,
|
|
380
|
-
minWidth: triggerRect.width,
|
|
381
|
-
});
|
|
382
|
-
}, [elementRef, position, options?.menuRef, options?.topOffset, isMobile]);
|
|
383
|
-
|
|
384
|
-
useEffect(() => {
|
|
385
|
-
if (!options?.isOpen || !options?.setIsOpen) return;
|
|
386
|
-
|
|
387
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
388
|
-
const target = event.target as Node;
|
|
389
|
-
if (elementRef.current?.contains(target)) return;
|
|
390
|
-
if (options.menuRef?.current?.contains(target)) return;
|
|
391
|
-
if (options.additionalRefs?.some((ref) => ref.current?.contains(target)))
|
|
392
|
-
return;
|
|
393
|
-
|
|
394
|
-
options.setIsOpen?.(false);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
398
|
-
return () => {
|
|
399
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
400
|
-
};
|
|
401
|
-
}, [
|
|
402
|
-
options,
|
|
403
|
-
elementRef,
|
|
404
|
-
options?.isOpen,
|
|
405
|
-
options?.setIsOpen,
|
|
406
|
-
options?.menuRef,
|
|
407
|
-
options?.additionalRefs,
|
|
408
|
-
]);
|
|
409
|
-
|
|
410
|
-
useEffect(() => {
|
|
411
|
-
updatePosition();
|
|
412
|
-
|
|
413
|
-
const resizeObserver = new ResizeObserver(updatePosition);
|
|
414
|
-
if (elementRef?.current) {
|
|
415
|
-
resizeObserver.observe(elementRef.current);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
window.addEventListener("scroll", updatePosition);
|
|
419
|
-
|
|
420
|
-
const hideMenuWhenParentIsScrolled = () => {
|
|
421
|
-
options?.setIsOpen?.(false);
|
|
422
|
-
}
|
|
423
|
-
const scrollableAncestors = getScrollableAncestors(elementRef.current);
|
|
424
|
-
scrollableAncestors.forEach(ancestor => ancestor.addEventListener("scroll", hideMenuWhenParentIsScrolled));
|
|
425
|
-
|
|
426
|
-
window.addEventListener("resize", updatePosition);
|
|
427
|
-
|
|
428
|
-
return () => {
|
|
429
|
-
resizeObserver.disconnect();
|
|
430
|
-
window.removeEventListener("scroll", updatePosition);
|
|
431
|
-
scrollableAncestors.forEach(ancestor => ancestor.removeEventListener("scroll", hideMenuWhenParentIsScrolled))
|
|
432
|
-
window.removeEventListener("resize", updatePosition);
|
|
433
|
-
};
|
|
434
|
-
}, [elementRef, updatePosition]);
|
|
435
|
-
|
|
436
|
-
return { menuPosition, updatePosition };
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function getScrollableAncestors(element: HTMLElement | null): HTMLElement[] {
|
|
440
|
-
if (!element) {
|
|
441
|
-
return []
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const scrollables: HTMLElement[] = [];
|
|
445
|
-
let parent = element.parentElement;
|
|
446
|
-
|
|
447
|
-
while (parent) {
|
|
448
|
-
const overflowY = window.getComputedStyle(parent).overflowY;
|
|
449
|
-
if (overflowY === 'auto' || overflowY === 'scroll') {
|
|
450
|
-
scrollables.push(parent);
|
|
451
|
-
}
|
|
452
|
-
parent = parent.parentElement;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return scrollables;
|
|
456
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export const useMounted = () => {
|
|
6
|
-
const [isMounted, setIsMounted] = useState(false);
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
setIsMounted(true);
|
|
10
|
-
return () => setIsMounted(false);
|
|
11
|
-
}, []);
|
|
12
|
-
|
|
13
|
-
return isMounted;
|
|
14
|
-
};
|