@dmsi/wedgekit-react 0.0.2
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/README.md +35 -0
- package/dist/chunk-27KIIUAR.js +59 -0
- package/dist/chunk-2G2E2JMA.js +123 -0
- package/dist/chunk-4C66DLIJ.js +51 -0
- package/dist/chunk-4RD5ZF2V.js +55 -0
- package/dist/chunk-4RJKB7LC.js +14 -0
- package/dist/chunk-4T7F5BZZ.js +26 -0
- package/dist/chunk-5GOBP2JS.js +53 -0
- package/dist/chunk-6ZY524ID.js +42 -0
- package/dist/chunk-AWQSSKCK.js +32 -0
- package/dist/chunk-BNHSAFMP.js +93 -0
- package/dist/chunk-BWRHL2AG.js +439 -0
- package/dist/chunk-DKKYR6DS.js +132 -0
- package/dist/chunk-E5ALT5W7.js +182 -0
- package/dist/chunk-FY7PTP6E.js +322 -0
- package/dist/chunk-GTCSRHPF.js +119 -0
- package/dist/chunk-I2UVVKQI.js +12 -0
- package/dist/chunk-IGQVA7SC.js +41 -0
- package/dist/chunk-K3IKUSZW.js +59 -0
- package/dist/chunk-KENSVWOY.js +151 -0
- package/dist/chunk-KX3O6GJ6.js +138 -0
- package/dist/chunk-L4UM372R.js +253 -0
- package/dist/chunk-ORMEWXMH.js +37 -0
- package/dist/chunk-Q3FKEKIN.js +23 -0
- package/dist/chunk-SEKKGFM6.js +28 -0
- package/dist/chunk-SY3HT54E.js +91 -0
- package/dist/chunk-TAW5ZZ4Z.js +346 -0
- package/dist/chunk-TRUPPHBQ.js +109 -0
- package/dist/chunk-TU55CHXU.js +30 -0
- package/dist/chunk-TWZZB4WO.js +114 -0
- package/dist/chunk-TYI74BSP.js +62 -0
- package/dist/chunk-U42SKNR6.js +104 -0
- package/dist/chunk-UU3FA6LV.js +72 -0
- package/dist/chunk-WVUIIBRR.js +51 -0
- package/dist/chunk-XUIPGYP5.js +39 -0
- package/dist/chunk-Z4UCFUF7.js +299 -0
- package/dist/components/Breadcrumbs.cjs +376 -0
- package/dist/components/Breadcrumbs.js +90 -0
- package/dist/components/Button.cjs +319 -0
- package/dist/components/Button.js +8 -0
- package/dist/components/CalendarRange.cjs +520 -0
- package/dist/components/CalendarRange.js +13 -0
- package/dist/components/Caption.cjs +283 -0
- package/dist/components/Caption.js +80 -0
- package/dist/components/Checkbox.cjs +378 -0
- package/dist/components/Checkbox.js +11 -0
- package/dist/components/ContentTab.cjs +382 -0
- package/dist/components/ContentTab.js +10 -0
- package/dist/components/ContentTabs.cjs +472 -0
- package/dist/components/ContentTabs.js +98 -0
- package/dist/components/DMSiLogo.cjs +79 -0
- package/dist/components/DMSiLogo.js +56 -0
- package/dist/components/DataGrid.cjs +3113 -0
- package/dist/components/DataGrid.js +758 -0
- package/dist/components/DataGridCell.cjs +1907 -0
- package/dist/components/DataGridCell.js +24 -0
- package/dist/components/DataTable.cjs +791 -0
- package/dist/components/DataTable.js +720 -0
- package/dist/components/DateInput.cjs +1130 -0
- package/dist/components/DateInput.js +170 -0
- package/dist/components/DateRangeInput.cjs +1131 -0
- package/dist/components/DateRangeInput.js +171 -0
- package/dist/components/DebugJson.cjs +50 -0
- package/dist/components/DebugJson.js +27 -0
- package/dist/components/Display.cjs +234 -0
- package/dist/components/Display.js +12 -0
- package/dist/components/EditingContext.cjs +73 -0
- package/dist/components/EditingContext.js +35 -0
- package/dist/components/FilterGroup.cjs +1431 -0
- package/dist/components/FilterGroup.js +231 -0
- package/dist/components/FullViewportBox.cjs +35 -0
- package/dist/components/FullViewportBox.js +12 -0
- package/dist/components/Grid.cjs +69 -0
- package/dist/components/Grid.js +36 -0
- package/dist/components/GridContainer.cjs +125 -0
- package/dist/components/GridContainer.js +92 -0
- package/dist/components/Heading.cjs +238 -0
- package/dist/components/Heading.js +14 -0
- package/dist/components/HorizontalDivider.cjs +33 -0
- package/dist/components/HorizontalDivider.js +10 -0
- package/dist/components/Icon.cjs +98 -0
- package/dist/components/Icon.js +7 -0
- package/dist/components/Input.cjs +672 -0
- package/dist/components/Input.js +21 -0
- package/dist/components/InputGroup.cjs +270 -0
- package/dist/components/InputGroup.js +60 -0
- package/dist/components/Label.cjs +223 -0
- package/dist/components/Label.js +8 -0
- package/dist/components/Link.cjs +262 -0
- package/dist/components/Link.js +8 -0
- package/dist/components/List.cjs +37 -0
- package/dist/components/List.js +14 -0
- package/dist/components/LiveChatComponent.cjs +63 -0
- package/dist/components/LiveChatComponent.js +40 -0
- package/dist/components/LogoAgilityTopBar.cjs +115 -0
- package/dist/components/LogoAgilityTopBar.js +92 -0
- package/dist/components/LogoDMSiTopBar.cjs +79 -0
- package/dist/components/LogoDMSiTopBar.js +7 -0
- package/dist/components/LogoMillworkTopBar.cjs +221 -0
- package/dist/components/LogoMillworkTopBar.js +198 -0
- package/dist/components/MainBar.cjs +211 -0
- package/dist/components/MainBar.js +65 -0
- package/dist/components/Menu.cjs +437 -0
- package/dist/components/Menu.js +11 -0
- package/dist/components/MenuOption.cjs +483 -0
- package/dist/components/MenuOption.js +13 -0
- package/dist/components/MobileDataGrid.cjs +658 -0
- package/dist/components/MobileDataGrid.js +125 -0
- package/dist/components/Modal.cjs +783 -0
- package/dist/components/Modal.js +245 -0
- package/dist/components/ModalButtons.cjs +385 -0
- package/dist/components/ModalButtons.js +10 -0
- package/dist/components/ModalContent.cjs +57 -0
- package/dist/components/ModalContent.js +7 -0
- package/dist/components/ModalHeader.cjs +426 -0
- package/dist/components/ModalHeader.js +11 -0
- package/dist/components/ModalScrim.cjs +64 -0
- package/dist/components/ModalScrim.js +7 -0
- package/dist/components/NavigationTab.cjs +431 -0
- package/dist/components/NavigationTab.js +10 -0
- package/dist/components/NavigationTabs.cjs +477 -0
- package/dist/components/NavigationTabs.js +56 -0
- package/dist/components/Notification.cjs +640 -0
- package/dist/components/Notification.js +117 -0
- package/dist/components/OptionPill.cjs +478 -0
- package/dist/components/OptionPill.js +11 -0
- package/dist/components/Paragraph.cjs +231 -0
- package/dist/components/Paragraph.js +8 -0
- package/dist/components/Password.cjs +700 -0
- package/dist/components/Password.js +53 -0
- package/dist/components/ProjectBar.cjs +242 -0
- package/dist/components/ProjectBar.js +63 -0
- package/dist/components/Radio.cjs +349 -0
- package/dist/components/Radio.js +131 -0
- package/dist/components/Search.cjs +767 -0
- package/dist/components/Search.js +12 -0
- package/dist/components/Select.cjs +758 -0
- package/dist/components/Select.js +12 -0
- package/dist/components/SideMenu.cjs +54 -0
- package/dist/components/SideMenu.js +21 -0
- package/dist/components/SideMenuGroup.cjs +422 -0
- package/dist/components/SideMenuGroup.js +83 -0
- package/dist/components/SideMenuItem.cjs +388 -0
- package/dist/components/SideMenuItem.js +70 -0
- package/dist/components/Stack.cjs +138 -0
- package/dist/components/Stack.js +7 -0
- package/dist/components/StatusPill.cjs +265 -0
- package/dist/components/StatusPill.js +52 -0
- package/dist/components/Stepper.cjs +885 -0
- package/dist/components/Stepper.js +105 -0
- package/dist/components/Subheader.cjs +226 -0
- package/dist/components/Subheader.js +8 -0
- package/dist/components/Surface.cjs +98 -0
- package/dist/components/Surface.js +40 -0
- package/dist/components/Swatch.cjs +1728 -0
- package/dist/components/Swatch.js +1319 -0
- package/dist/components/Textarea.cjs +269 -0
- package/dist/components/Textarea.js +96 -0
- package/dist/components/Theme.cjs +36 -0
- package/dist/components/Theme.js +7 -0
- package/dist/components/Time.cjs +1118 -0
- package/dist/components/Time.js +353 -0
- package/dist/components/Toast.cjs +644 -0
- package/dist/components/Toast.js +218 -0
- package/dist/components/Tooltip.cjs +273 -0
- package/dist/components/Tooltip.js +9 -0
- package/dist/components/TopBar.cjs +352 -0
- package/dist/components/TopBar.js +132 -0
- package/dist/components/useInfiniteScroll.cjs +57 -0
- package/dist/components/useInfiniteScroll.js +8 -0
- package/dist/components/useMatchesMedia.cjs +53 -0
- package/dist/components/useMatchesMedia.js +9 -0
- package/dist/components/useMenuSystem.cjs +358 -0
- package/dist/components/useMenuSystem.js +11 -0
- package/dist/components/useMounted.cjs +39 -0
- package/dist/components/useMounted.js +8 -0
- package/dist/fonts.css +21 -0
- package/dist/icons-light[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/icons-normal[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/index.css +4401 -0
- package/dist/open-sans-55T6A4JE.woff2 +0 -0
- package/dist/types.cjs +18 -0
- package/dist/types.js +0 -0
- package/package.json +66 -0
- package/src/brand.css +125 -0
- package/src/classNames.ts +144 -0
- package/src/components/Breadcrumbs.tsx +116 -0
- package/src/components/Button.tsx +210 -0
- package/src/components/CalendarRange.tsx +429 -0
- package/src/components/Caption.tsx +101 -0
- package/src/components/Checkbox.tsx +196 -0
- package/src/components/ContentTab.tsx +66 -0
- package/src/components/ContentTabs.tsx +103 -0
- package/src/components/DMSiLogo.tsx +32 -0
- package/src/components/DataGrid.tsx +948 -0
- package/src/components/DataGridCell.tsx +384 -0
- package/src/components/DataTable.tsx +835 -0
- package/src/components/DateInput.tsx +188 -0
- package/src/components/DateRangeInput.tsx +179 -0
- package/src/components/DebugJson.tsx +24 -0
- package/src/components/Display.tsx +60 -0
- package/src/components/EditingContext.tsx +40 -0
- package/src/components/FilterGroup.tsx +234 -0
- package/src/components/FullViewportBox.tsx +11 -0
- package/src/components/Grid.tsx +75 -0
- package/src/components/GridContainer.tsx +124 -0
- package/src/components/Heading.tsx +66 -0
- package/src/components/HorizontalDivider.tsx +3 -0
- package/src/components/Icon.tsx +36 -0
- package/src/components/Input.tsx +511 -0
- package/src/components/InputGroup.tsx +51 -0
- package/src/components/Label.tsx +40 -0
- package/src/components/Link.tsx +106 -0
- package/src/components/List.tsx +10 -0
- package/src/components/LiveChatComponent.tsx +56 -0
- package/src/components/LogoAgilityTopBar.tsx +53 -0
- package/src/components/LogoDMSiTopBar.tsx +32 -0
- package/src/components/LogoMillworkTopBar.tsx +118 -0
- package/src/components/MainBar.tsx +83 -0
- package/src/components/Menu.tsx +286 -0
- package/src/components/MenuOption.tsx +275 -0
- package/src/components/MobileDataGrid.tsx +135 -0
- package/src/components/Modal.tsx +271 -0
- package/src/components/ModalButtons.tsx +44 -0
- package/src/components/ModalContent.tsx +23 -0
- package/src/components/ModalHeader.tsx +41 -0
- package/src/components/ModalScrim.tsx +35 -0
- package/src/components/NavigationTab.tsx +89 -0
- package/src/components/NavigationTabs.tsx +63 -0
- package/src/components/Notification.tsx +120 -0
- package/src/components/OptionPill.tsx +114 -0
- package/src/components/Paragraph.tsx +49 -0
- package/src/components/Password.tsx +46 -0
- package/src/components/ProjectBar.tsx +76 -0
- package/src/components/Radio.tsx +140 -0
- package/src/components/Search.tsx +129 -0
- package/src/components/Select.tsx +104 -0
- package/src/components/SideMenu.tsx +21 -0
- package/src/components/SideMenuGroup.tsx +81 -0
- package/src/components/SideMenuItem.tsx +90 -0
- package/src/components/Stack.tsx +179 -0
- package/src/components/StatusPill.tsx +51 -0
- package/src/components/Stepper.tsx +91 -0
- package/src/components/Subheader.tsx +44 -0
- package/src/components/Surface.tsx +34 -0
- package/src/components/Swatch.tsx +1066 -0
- package/src/components/Textarea.tsx +101 -0
- package/src/components/Theme.tsx +13 -0
- package/src/components/Time.tsx +438 -0
- package/src/components/Toast.tsx +244 -0
- package/src/components/Tooltip.tsx +137 -0
- package/src/components/TopBar.tsx +124 -0
- package/src/components/useInfiniteScroll.tsx +40 -0
- package/src/components/useMatchesMedia.tsx +28 -0
- package/src/components/useMenuSystem.tsx +367 -0
- package/src/components/useMounted.tsx +14 -0
- package/src/darkmode.css +140 -0
- package/src/fonts.css +23 -0
- package/src/index.css +509 -0
- package/src/index.tsx +2 -0
- package/src/types.ts +149 -0
- package/src/utils/formatting.tsx +81 -0
- package/src/utils.ts +23 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __objRest = (source, exclude) => {
|
|
27
|
+
var target = {};
|
|
28
|
+
for (var prop in source)
|
|
29
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
if (source != null && __getOwnPropSymbols)
|
|
32
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
var __export = (target, all) => {
|
|
39
|
+
for (var name in all)
|
|
40
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
41
|
+
};
|
|
42
|
+
var __copyProps = (to, from, except, desc) => {
|
|
43
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
44
|
+
for (let key of __getOwnPropNames(from))
|
|
45
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
46
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
47
|
+
}
|
|
48
|
+
return to;
|
|
49
|
+
};
|
|
50
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
51
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
52
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
53
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
54
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
55
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
56
|
+
mod
|
|
57
|
+
));
|
|
58
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
59
|
+
|
|
60
|
+
// src/components/Menu.tsx
|
|
61
|
+
var Menu_exports = {};
|
|
62
|
+
__export(Menu_exports, {
|
|
63
|
+
Menu: () => Menu
|
|
64
|
+
});
|
|
65
|
+
module.exports = __toCommonJS(Menu_exports);
|
|
66
|
+
var import_clsx = __toESM(require("clsx"), 1);
|
|
67
|
+
var import_react3 = require("react");
|
|
68
|
+
var import_react_dom = require("react-dom");
|
|
69
|
+
|
|
70
|
+
// src/components/useMenuSystem.tsx
|
|
71
|
+
var import_react2 = require("react");
|
|
72
|
+
|
|
73
|
+
// src/components/useMatchesMedia.tsx
|
|
74
|
+
var import_react = require("react");
|
|
75
|
+
var useMatchesMedia = (query) => {
|
|
76
|
+
const [matches, setMatches] = (0, import_react.useState)(
|
|
77
|
+
() => typeof window !== "undefined" ? window.matchMedia(query).matches : false
|
|
78
|
+
);
|
|
79
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
80
|
+
const mediaQueryList = window.matchMedia(query);
|
|
81
|
+
const listener = (event) => {
|
|
82
|
+
setMatches(event.matches);
|
|
83
|
+
};
|
|
84
|
+
mediaQueryList.addEventListener("change", listener);
|
|
85
|
+
setMatches(mediaQueryList.matches);
|
|
86
|
+
return () => {
|
|
87
|
+
mediaQueryList.removeEventListener("change", listener);
|
|
88
|
+
};
|
|
89
|
+
}, [query]);
|
|
90
|
+
return matches;
|
|
91
|
+
};
|
|
92
|
+
var useMatchesMobile = () => {
|
|
93
|
+
const isMobile = useMatchesMedia("(width < 48rem)");
|
|
94
|
+
return isMobile;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/components/useMenuSystem.tsx
|
|
98
|
+
function useMenuPosition(elementRef, position = "bottom", options) {
|
|
99
|
+
const [menuPosition, setMenuPosition] = (0, import_react2.useState)({
|
|
100
|
+
top: 0,
|
|
101
|
+
left: 0,
|
|
102
|
+
minWidth: 0
|
|
103
|
+
});
|
|
104
|
+
const isMobile = useMatchesMobile();
|
|
105
|
+
const updatePosition = (0, import_react2.useCallback)(() => {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
107
|
+
if (!(elementRef == null ? void 0 : elementRef.current)) return;
|
|
108
|
+
const triggerRect = elementRef.current.getBoundingClientRect();
|
|
109
|
+
const menuRect = (_b = (_a = options == null ? void 0 : options.menuRef) == null ? void 0 : _a.current) == null ? void 0 : _b.getBoundingClientRect();
|
|
110
|
+
const viewportWidth = window.innerWidth;
|
|
111
|
+
const menuWidth = (menuRect == null ? void 0 : menuRect.width) || triggerRect.width;
|
|
112
|
+
const topOffset = (_c = options == null ? void 0 : options.topOffset) != null ? _c : 4;
|
|
113
|
+
let top = 0;
|
|
114
|
+
let left = 0;
|
|
115
|
+
if (position === "bottom" || position === "bottom-right") {
|
|
116
|
+
top = triggerRect.top + triggerRect.height + topOffset;
|
|
117
|
+
} else {
|
|
118
|
+
top = triggerRect.top;
|
|
119
|
+
}
|
|
120
|
+
if (position === "bottom") {
|
|
121
|
+
left = triggerRect.left + window.scrollX;
|
|
122
|
+
} else if (position === "bottom-right") {
|
|
123
|
+
left = triggerRect.right + window.scrollX - menuWidth;
|
|
124
|
+
} else if (position === "right") {
|
|
125
|
+
left = triggerRect.right + window.scrollX;
|
|
126
|
+
}
|
|
127
|
+
const overflowsLeftViewport = left + menuWidth > viewportWidth;
|
|
128
|
+
if (overflowsLeftViewport) {
|
|
129
|
+
left = triggerRect.left - menuWidth;
|
|
130
|
+
}
|
|
131
|
+
if (isMobile) {
|
|
132
|
+
left = triggerRect.left + menuWidth > viewportWidth ? Math.max(viewportWidth - menuWidth, 0) - 8 : triggerRect.left;
|
|
133
|
+
top = ((_f = (_e = (_d = elementRef.current.parentElement) == null ? void 0 : _d.getBoundingClientRect()) == null ? void 0 : _e.top) != null ? _f : 0) + ((_i = (_h = (_g = elementRef.current.parentElement) == null ? void 0 : _g.getBoundingClientRect()) == null ? void 0 : _h.height) != null ? _i : 0) + topOffset;
|
|
134
|
+
}
|
|
135
|
+
setMenuPosition({
|
|
136
|
+
top,
|
|
137
|
+
left,
|
|
138
|
+
minWidth: triggerRect.width
|
|
139
|
+
});
|
|
140
|
+
}, [elementRef, position, options == null ? void 0 : options.menuRef, options == null ? void 0 : options.topOffset, isMobile]);
|
|
141
|
+
(0, import_react2.useEffect)(() => {
|
|
142
|
+
if (!(options == null ? void 0 : options.isOpen) || !(options == null ? void 0 : options.setIsOpen)) return;
|
|
143
|
+
const handleClickOutside = (event) => {
|
|
144
|
+
var _a, _b, _c, _d, _e;
|
|
145
|
+
const target = event.target;
|
|
146
|
+
if ((_a = elementRef.current) == null ? void 0 : _a.contains(target)) return;
|
|
147
|
+
if ((_c = (_b = options.menuRef) == null ? void 0 : _b.current) == null ? void 0 : _c.contains(target)) return;
|
|
148
|
+
if ((_d = options.additionalRefs) == null ? void 0 : _d.some((ref) => {
|
|
149
|
+
var _a2;
|
|
150
|
+
return (_a2 = ref.current) == null ? void 0 : _a2.contains(target);
|
|
151
|
+
}))
|
|
152
|
+
return;
|
|
153
|
+
(_e = options.setIsOpen) == null ? void 0 : _e.call(options, false);
|
|
154
|
+
};
|
|
155
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
156
|
+
return () => {
|
|
157
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
158
|
+
};
|
|
159
|
+
}, [
|
|
160
|
+
options,
|
|
161
|
+
elementRef,
|
|
162
|
+
options == null ? void 0 : options.isOpen,
|
|
163
|
+
options == null ? void 0 : options.setIsOpen,
|
|
164
|
+
options == null ? void 0 : options.menuRef,
|
|
165
|
+
options == null ? void 0 : options.additionalRefs
|
|
166
|
+
]);
|
|
167
|
+
(0, import_react2.useEffect)(() => {
|
|
168
|
+
updatePosition();
|
|
169
|
+
const resizeObserver = new ResizeObserver(updatePosition);
|
|
170
|
+
if (elementRef == null ? void 0 : elementRef.current) {
|
|
171
|
+
resizeObserver.observe(elementRef.current);
|
|
172
|
+
}
|
|
173
|
+
window.addEventListener("scroll", updatePosition);
|
|
174
|
+
window.addEventListener("resize", updatePosition);
|
|
175
|
+
return () => {
|
|
176
|
+
resizeObserver.disconnect();
|
|
177
|
+
window.removeEventListener("scroll", updatePosition);
|
|
178
|
+
window.removeEventListener("resize", updatePosition);
|
|
179
|
+
};
|
|
180
|
+
}, [elementRef, updatePosition]);
|
|
181
|
+
return { menuPosition, updatePosition };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/utils.ts
|
|
185
|
+
function findDocumentRoot(element) {
|
|
186
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
187
|
+
throw new Error(
|
|
188
|
+
"findDocumentRoot can only be used in a browser environment."
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
if (!element || !(element instanceof Node)) {
|
|
192
|
+
return window.document.body;
|
|
193
|
+
}
|
|
194
|
+
var currentElement = element;
|
|
195
|
+
while (currentElement && currentElement.parentNode) {
|
|
196
|
+
if (currentElement.parentNode === document) {
|
|
197
|
+
return document.body;
|
|
198
|
+
} else if (currentElement.parentNode instanceof DocumentFragment) {
|
|
199
|
+
return currentElement.parentNode;
|
|
200
|
+
} else {
|
|
201
|
+
currentElement = currentElement.parentNode;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return window.document.body;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/components/Menu.tsx
|
|
208
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
209
|
+
var Menu = (_a) => {
|
|
210
|
+
var _b = _a, {
|
|
211
|
+
children,
|
|
212
|
+
className,
|
|
213
|
+
ref,
|
|
214
|
+
positionTo,
|
|
215
|
+
mobilePositionTo,
|
|
216
|
+
show,
|
|
217
|
+
setShow,
|
|
218
|
+
position = "bottom",
|
|
219
|
+
maxHeight: customMaxHeight,
|
|
220
|
+
topOffset,
|
|
221
|
+
mobileBackMenuOption,
|
|
222
|
+
mobileHide,
|
|
223
|
+
useDefaultMinWidth,
|
|
224
|
+
autoFocusOff,
|
|
225
|
+
menuName
|
|
226
|
+
} = _b, props = __objRest(_b, [
|
|
227
|
+
"children",
|
|
228
|
+
"className",
|
|
229
|
+
"ref",
|
|
230
|
+
"positionTo",
|
|
231
|
+
"mobilePositionTo",
|
|
232
|
+
"show",
|
|
233
|
+
"setShow",
|
|
234
|
+
"position",
|
|
235
|
+
"maxHeight",
|
|
236
|
+
"topOffset",
|
|
237
|
+
"mobileBackMenuOption",
|
|
238
|
+
"mobileHide",
|
|
239
|
+
"useDefaultMinWidth",
|
|
240
|
+
"autoFocusOff",
|
|
241
|
+
"menuName"
|
|
242
|
+
]);
|
|
243
|
+
const internalRef = (0, import_react3.useRef)(null);
|
|
244
|
+
const actualRef = ref || internalRef;
|
|
245
|
+
const [maxHeight, setMaxHeight] = (0, import_react3.useState)("180px");
|
|
246
|
+
const isMobile = useMatchesMobile();
|
|
247
|
+
const { menuPosition, updatePosition } = useMenuPosition(
|
|
248
|
+
isMobile && mobilePositionTo ? mobilePositionTo : positionTo,
|
|
249
|
+
position,
|
|
250
|
+
{
|
|
251
|
+
isOpen: show,
|
|
252
|
+
setIsOpen: setShow,
|
|
253
|
+
menuRef: internalRef,
|
|
254
|
+
topOffset
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
(0, import_react3.useEffect)(() => {
|
|
258
|
+
const raf = requestAnimationFrame(() => {
|
|
259
|
+
if (!actualRef || !actualRef.current || customMaxHeight) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (actualRef.current.childElementCount > 4) {
|
|
263
|
+
let accumulatedHeight = 0;
|
|
264
|
+
Array.from(actualRef.current.children).forEach((child, index) => {
|
|
265
|
+
if (index >= 5) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
accumulatedHeight += child.clientHeight;
|
|
269
|
+
});
|
|
270
|
+
accumulatedHeight = accumulatedHeight / 5 * 4.5;
|
|
271
|
+
setMaxHeight(`${accumulatedHeight}px`);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
return () => {
|
|
275
|
+
cancelAnimationFrame(raf);
|
|
276
|
+
};
|
|
277
|
+
}, [actualRef, customMaxHeight]);
|
|
278
|
+
(0, import_react3.useEffect)(() => {
|
|
279
|
+
if (!show) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
initializeMenuFocus();
|
|
283
|
+
updatePosition();
|
|
284
|
+
}, [show, updatePosition]);
|
|
285
|
+
(0, import_react3.useEffect)(() => {
|
|
286
|
+
if (!show || !setShow) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const handleEscapeKey = (event) => {
|
|
290
|
+
var _a2;
|
|
291
|
+
if (event.key !== "Escape") {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
setShow(false);
|
|
295
|
+
(_a2 = positionTo == null ? void 0 : positionTo.current) == null ? void 0 : _a2.focus();
|
|
296
|
+
};
|
|
297
|
+
document.addEventListener("keydown", handleEscapeKey);
|
|
298
|
+
return () => {
|
|
299
|
+
document.removeEventListener("keydown", handleEscapeKey);
|
|
300
|
+
};
|
|
301
|
+
}, [show, setShow, positionTo]);
|
|
302
|
+
return show && (0, import_react_dom.createPortal)(
|
|
303
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
304
|
+
"div",
|
|
305
|
+
__spreadProps(__spreadValues({
|
|
306
|
+
ref: setRefs,
|
|
307
|
+
className: (0, import_clsx.default)(
|
|
308
|
+
"shadow-4 rounded-base bg-background-grouped-primary-normal overflow-x-hidden overflow-y-auto flex flex-col outline-0",
|
|
309
|
+
"fixed",
|
|
310
|
+
"z-50",
|
|
311
|
+
mobileHide && "opacity-0 pointer-events-none",
|
|
312
|
+
className
|
|
313
|
+
)
|
|
314
|
+
}, props), {
|
|
315
|
+
style: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, props.style), {
|
|
316
|
+
maxHeight: customMaxHeight || maxHeight
|
|
317
|
+
}), menuPosition), {
|
|
318
|
+
minWidth: useDefaultMinWidth ? "212px" : menuPosition.minWidth
|
|
319
|
+
}),
|
|
320
|
+
onKeyDown: handleKeydown,
|
|
321
|
+
onMouseDown: stopPropagation,
|
|
322
|
+
onMouseUp: stopPropagation,
|
|
323
|
+
onTouchStart: stopPropagation,
|
|
324
|
+
onTouchEnd: stopPropagation,
|
|
325
|
+
tabIndex: -1,
|
|
326
|
+
"data-menu": menuName != null ? menuName : "",
|
|
327
|
+
children: [
|
|
328
|
+
mobileBackMenuOption == null ? void 0 : mobileBackMenuOption(),
|
|
329
|
+
children
|
|
330
|
+
]
|
|
331
|
+
})
|
|
332
|
+
),
|
|
333
|
+
findDocumentRoot(internalRef.current)
|
|
334
|
+
);
|
|
335
|
+
function handleKeydown(e) {
|
|
336
|
+
var _a2, _b2;
|
|
337
|
+
if (!internalRef.current) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (e.key !== "Escape") {
|
|
341
|
+
e.stopPropagation();
|
|
342
|
+
}
|
|
343
|
+
const menuOptions = Array.from(
|
|
344
|
+
internalRef.current.querySelectorAll('[role="menuitem"]')
|
|
345
|
+
);
|
|
346
|
+
if (menuOptions.length === 0) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
let currentIndex = -1;
|
|
350
|
+
const focusedElement = document.activeElement;
|
|
351
|
+
for (let i = 0; i < menuOptions.length; i++) {
|
|
352
|
+
if (menuOptions[i] === focusedElement) {
|
|
353
|
+
currentIndex = i;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
switch (e.key) {
|
|
358
|
+
case "ArrowDown": {
|
|
359
|
+
e.preventDefault();
|
|
360
|
+
const nextIndex = currentIndex < menuOptions.length - 1 ? currentIndex + 1 : 0;
|
|
361
|
+
menuOptions[nextIndex].focus();
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case "ArrowUp": {
|
|
365
|
+
e.preventDefault();
|
|
366
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : menuOptions.length - 1;
|
|
367
|
+
menuOptions[prevIndex].focus();
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case "Home":
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
menuOptions[0].focus();
|
|
373
|
+
break;
|
|
374
|
+
case "End":
|
|
375
|
+
e.preventDefault();
|
|
376
|
+
menuOptions[menuOptions.length - 1].focus();
|
|
377
|
+
break;
|
|
378
|
+
case "Enter":
|
|
379
|
+
case " ":
|
|
380
|
+
case "ArrowRight":
|
|
381
|
+
e.preventDefault();
|
|
382
|
+
if (currentIndex >= 0) {
|
|
383
|
+
menuOptions[currentIndex].click();
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
case "ArrowLeft":
|
|
387
|
+
e.preventDefault();
|
|
388
|
+
(_a2 = positionTo == null ? void 0 : positionTo.current) == null ? void 0 : _a2.click();
|
|
389
|
+
(_b2 = positionTo == null ? void 0 : positionTo.current) == null ? void 0 : _b2.focus();
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function initializeMenuFocus() {
|
|
394
|
+
var _a2, _b2, _c;
|
|
395
|
+
if (!autoFocusOff) {
|
|
396
|
+
(_a2 = internalRef.current) == null ? void 0 : _a2.focus();
|
|
397
|
+
}
|
|
398
|
+
const selectedOption = (_b2 = internalRef.current) == null ? void 0 : _b2.querySelector(
|
|
399
|
+
"[data-selected]"
|
|
400
|
+
);
|
|
401
|
+
const firstMenuItem = (_c = internalRef.current) == null ? void 0 : _c.querySelector(
|
|
402
|
+
'[role="menuitem"]'
|
|
403
|
+
);
|
|
404
|
+
const targetElement = selectedOption || firstMenuItem;
|
|
405
|
+
if (!targetElement) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
targetElement.scrollIntoView({
|
|
409
|
+
block: "nearest",
|
|
410
|
+
behavior: "instant"
|
|
411
|
+
});
|
|
412
|
+
if (autoFocusOff) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
requestAnimationFrame(() => {
|
|
416
|
+
targetElement.focus();
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
function setRefs(node) {
|
|
420
|
+
internalRef.current = node;
|
|
421
|
+
if (ref) {
|
|
422
|
+
if (typeof ref === "function") {
|
|
423
|
+
ref(node);
|
|
424
|
+
} else {
|
|
425
|
+
ref.current = node;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function stopPropagation(e) {
|
|
430
|
+
e.stopPropagation();
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
Menu.displayName = "Menu";
|
|
434
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
435
|
+
0 && (module.exports = {
|
|
436
|
+
Menu
|
|
437
|
+
});
|