@jobber/components 6.98.2 → 6.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Autocomplete/index.mjs +1 -1
- package/dist/Card/index.cjs +2 -0
- package/dist/Card/index.mjs +2 -0
- package/dist/ComboboxContent-es.js +1 -1
- package/dist/DataDump/index.cjs +2 -0
- package/dist/DataDump/index.mjs +2 -0
- package/dist/DatePicker-es.js +1 -1
- package/dist/InputNumber/index.cjs +1954 -7663
- package/dist/InputNumber/index.mjs +1909 -7618
- package/dist/Menu/Menu.d.ts +27 -76
- package/dist/Menu/Menu.types.d.ts +183 -0
- package/dist/Menu/constants.d.ts +13 -0
- package/dist/Menu/index.cjs +2 -0
- package/dist/Menu/index.d.ts +2 -1
- package/dist/Menu/index.mjs +2 -0
- package/dist/Menu-cjs.js +260 -26
- package/dist/Menu-es.js +264 -30
- package/dist/Modal/Modal.types.d.ts +5 -0
- package/dist/Modal/index.cjs +35 -7
- package/dist/Modal/index.mjs +37 -9
- package/dist/Modal/useModal.d.ts +4 -2
- package/dist/Page/index.cjs +2 -0
- package/dist/Page/index.mjs +2 -0
- package/dist/Popover-es.js +1 -1
- package/dist/RecurringSelect/index.cjs +1 -0
- package/dist/RecurringSelect/index.mjs +1 -0
- package/dist/Toast/index.d.ts +1 -0
- package/dist/Tooltip-es.js +1 -1
- package/dist/Tree-cjs.js +11867 -0
- package/dist/Tree-es.js +11820 -0
- package/dist/floating-ui.react-es.js +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/dist/styles.css +108 -12
- package/dist/useScrollToActive-es.js +1 -1
- package/dist/utils/meta/meta.json +9 -0
- package/package.json +2 -2
package/dist/Menu-cjs.js
CHANGED
|
@@ -5,34 +5,124 @@ var classnames = require('classnames');
|
|
|
5
5
|
var framerMotion = require('framer-motion');
|
|
6
6
|
var jobberHooks = require('@jobber/hooks');
|
|
7
7
|
var floatingUi_react = require('./floating-ui.react-cjs.js');
|
|
8
|
+
var Tree = require('./Tree-cjs.js');
|
|
9
|
+
require('react-dom');
|
|
8
10
|
var Button = require('./Button-cjs.js');
|
|
9
11
|
var Typography = require('./Typography-cjs.js');
|
|
10
12
|
var Icon = require('./Icon-cjs.js');
|
|
11
13
|
var useFormFieldFocus = require('./useFormFieldFocus-cjs.js');
|
|
12
14
|
var maxHeight = require('./maxHeight-cjs.js');
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
/*
|
|
17
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
18
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
20
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
23
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
24
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
25
|
+
* governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const $3b117e43dc0ca95d$export$27c701ed9e449e99 = /*#__PURE__*/ (React).forwardRef(({ children: children, ...props }, ref)=>{
|
|
31
|
+
ref = (Tree.$df56164dff5785e2$export$4338b53315abf666)(ref);
|
|
32
|
+
let { pressProps: pressProps } = (Tree.$f6c31cce2adf654f$export$45712eceda6fad21)({
|
|
33
|
+
...props,
|
|
34
|
+
ref: ref
|
|
35
|
+
});
|
|
36
|
+
let { focusableProps: focusableProps } = (Tree.$f645667febf57a63$export$4c014de7c8940b4c)(props, ref);
|
|
37
|
+
let child = (React).Children.only(children);
|
|
38
|
+
(React.useEffect)(()=>{
|
|
39
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
40
|
+
let el = ref.current;
|
|
41
|
+
if (!el || !(el instanceof (Tree.$431fbd86ca7dc216$export$f21a1ffae260145a)(el).Element)) {
|
|
42
|
+
console.error('<Pressable> child must forward its ref to a DOM element.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!props.isDisabled && !(Tree.$b4b717babfbb907b$export$4c063cf1350e6fed)(el)) {
|
|
46
|
+
console.warn('<Pressable> child must be focusable. Please ensure the tabIndex prop is passed through.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (el.localName !== 'button' && el.localName !== 'input' && el.localName !== 'select' && el.localName !== 'textarea' && el.localName !== 'a' && el.localName !== 'area' && el.localName !== 'summary') {
|
|
50
|
+
let role = el.getAttribute('role');
|
|
51
|
+
if (!role) console.warn('<Pressable> child must have an interactive ARIA role.');
|
|
52
|
+
else if (// https://w3c.github.io/aria/#widget_roles
|
|
53
|
+
role !== 'application' && role !== 'button' && role !== 'checkbox' && role !== 'combobox' && role !== 'gridcell' && role !== 'link' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio' && role !== 'option' && role !== 'radio' && role !== 'searchbox' && role !== 'separator' && role !== 'slider' && role !== 'spinbutton' && role !== 'switch' && role !== 'tab' && role !== 'textbox' && role !== 'treeitem') console.warn(`<Pressable> child must have an interactive ARIA role. Got "${role}".`);
|
|
54
|
+
}
|
|
55
|
+
}, [
|
|
56
|
+
ref,
|
|
57
|
+
props.isDisabled
|
|
58
|
+
]);
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
let childRef = parseInt((React).version, 10) < 19 ? child.ref : child.props.ref;
|
|
61
|
+
return /*#__PURE__*/ (React).cloneElement(child, {
|
|
62
|
+
...(Tree.$3ef42575df84b30b$export$9d1611c77c2fe928)(pressProps, focusableProps, child.props),
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
ref: (Tree.$5dc95899b306f630$export$c9058316764c140e)(childRef, ref)
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
var styles = {"wrapper":"fpi0W91w2ag-","floatingContainer":"ba-Kj6mvQUw-","menu":"-DayvgvIcVo-","legacySection":"VsRRunpS6Yo-","separator":"jnggqK3YTIU-","triggerWrapper":"oRQQVVq-yxA-","ariaMenu":"QInUBKqkrl0-","ariaItem":"bWR8m7-LKg4-","ariaSection":"PH5vvtLgvXI-","ariaSectionHeader":"iJjIifpa9bk-","sectionHeader":"Bq7pLWj3jm4-","legacyAction":"P4Sdaq0-lZs-","action":"M1BgN-oCmKw-","destructive":"U9ihZZavz9w-","overlay":"_7we5hh6kYs8-","fullWidth":"_5OJ7B6mFcwk-","screenReaderOnly":"Bzvkz60bwWE-","spinning":"_0-VzuzHdi8o-"};
|
|
15
69
|
|
|
16
70
|
const SMALL_SCREEN_BREAKPOINT = 490;
|
|
17
71
|
const MENU_OFFSET = 6;
|
|
18
72
|
const MENU_MAX_HEIGHT_PERCENTAGE = 72;
|
|
73
|
+
const Y_TRANSLATION_DESKTOP = 10;
|
|
74
|
+
const Y_TRANSLATION_MOBILE = 150;
|
|
75
|
+
const MENU_ANIMATION_DURATION = 0.25;
|
|
76
|
+
const OVERLAY_ANIMATION_DURATION = 0.15;
|
|
77
|
+
const MENU_ANIMATION_CONFIG = {
|
|
78
|
+
duration: MENU_ANIMATION_DURATION,
|
|
79
|
+
type: "tween",
|
|
80
|
+
};
|
|
81
|
+
const OVERLAY_ANIMATION_CONFIG = {
|
|
82
|
+
duration: OVERLAY_ANIMATION_DURATION,
|
|
83
|
+
type: "tween",
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const composeOverlayVariation = {
|
|
87
|
+
hidden: { opacity: 0 },
|
|
88
|
+
visible: { opacity: 1 },
|
|
89
|
+
};
|
|
19
90
|
const variation = {
|
|
20
91
|
overlayStartStop: { opacity: 0 },
|
|
21
92
|
startOrStop: (placement) => {
|
|
22
|
-
let y =
|
|
93
|
+
let y = Y_TRANSLATION_DESKTOP;
|
|
23
94
|
if (placement === null || placement === void 0 ? void 0 : placement.includes("bottom"))
|
|
24
95
|
y *= -1;
|
|
25
|
-
if (
|
|
26
|
-
y =
|
|
96
|
+
if (isMobileDevice())
|
|
97
|
+
y = Y_TRANSLATION_MOBILE;
|
|
27
98
|
return { opacity: 0, y };
|
|
28
99
|
},
|
|
29
100
|
done: { opacity: 1, y: 0 },
|
|
30
101
|
};
|
|
102
|
+
function isMobileDevice() {
|
|
103
|
+
if (typeof window === "undefined") {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return window.innerWidth <= SMALL_SCREEN_BREAKPOINT;
|
|
107
|
+
}
|
|
108
|
+
function isLegacy(props) {
|
|
109
|
+
return "items" in props;
|
|
110
|
+
}
|
|
111
|
+
const MotionMenu = framerMotion.motion.create(Tree.$3674c52c6b3c5bce$export$d9b273488cd8ce6f);
|
|
112
|
+
// Single implementation
|
|
113
|
+
function Menu(props) {
|
|
114
|
+
if (isLegacy(props)) {
|
|
115
|
+
return React.createElement(MenuLegacy, Object.assign({}, props));
|
|
116
|
+
}
|
|
117
|
+
return (React.createElement(MenuComposable, { onOpenChange: props.onOpenChange, open: props.open, defaultOpen: props.defaultOpen }, props.children));
|
|
118
|
+
}
|
|
31
119
|
// eslint-disable-next-line max-statements
|
|
32
|
-
function
|
|
120
|
+
function MenuLegacy({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
33
121
|
var _a;
|
|
34
122
|
const [visible, setVisible] = React.useState(false);
|
|
35
123
|
const [referenceElement, setReferenceElement] = React.useState(null);
|
|
124
|
+
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
125
|
+
const listRef = React.useRef([]);
|
|
36
126
|
const { width } = jobberHooks.useWindowDimensions();
|
|
37
127
|
const buttonID = React.useId();
|
|
38
128
|
const menuID = React.useId();
|
|
@@ -40,9 +130,8 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
40
130
|
const wrapperClasses = classnames(styles.wrapper, {
|
|
41
131
|
[styles.fullWidth]: fullWidth,
|
|
42
132
|
});
|
|
43
|
-
//
|
|
133
|
+
// Ensure focus returns to the activator when closed
|
|
44
134
|
jobberHooks.useRefocusOnActivator(visible);
|
|
45
|
-
const menuRef = jobberHooks.useFocusTrap(visible);
|
|
46
135
|
const isLargeScreen = width >= SMALL_SCREEN_BREAKPOINT;
|
|
47
136
|
const middleware = React.useMemo(() => {
|
|
48
137
|
if (isLargeScreen) {
|
|
@@ -71,7 +160,9 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
71
160
|
}, [isLargeScreen]);
|
|
72
161
|
const { refs, floatingStyles, context } = floatingUi_react.useFloating({
|
|
73
162
|
open: visible,
|
|
74
|
-
onOpenChange:
|
|
163
|
+
onOpenChange: (isOpen) => {
|
|
164
|
+
setVisible(isOpen);
|
|
165
|
+
},
|
|
75
166
|
placement: "bottom-start",
|
|
76
167
|
strategy: "fixed",
|
|
77
168
|
middleware,
|
|
@@ -81,7 +172,13 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
81
172
|
whileElementsMounted: floatingUi_react.autoUpdate,
|
|
82
173
|
});
|
|
83
174
|
const dismiss = floatingUi_react.useDismiss(context);
|
|
84
|
-
const
|
|
175
|
+
const listNavigation = floatingUi_react.useListNavigation(context, {
|
|
176
|
+
listRef,
|
|
177
|
+
activeIndex,
|
|
178
|
+
onNavigate: setActiveIndex,
|
|
179
|
+
loop: true,
|
|
180
|
+
});
|
|
181
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = floatingUi_react.useInteractions([dismiss, listNavigation]);
|
|
85
182
|
const positionAttributes = isLargeScreen
|
|
86
183
|
? {
|
|
87
184
|
style: floatingStyles,
|
|
@@ -90,8 +187,17 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
90
187
|
if (!activator) {
|
|
91
188
|
activator = (React.createElement(Button.Button, { fullWidth: true, label: "More Actions", icon: "more", type: "secondary" }));
|
|
92
189
|
}
|
|
190
|
+
let itemIndexCounter = 0;
|
|
191
|
+
const renderedSections = items === null || items === void 0 ? void 0 : items.map((item, key) => (React.createElement("div", { key: key, className: styles.legacySection },
|
|
192
|
+
item.header && (React.createElement(SectionHeader, { text: item.header, UNSAFE_style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.header, UNSAFE_className: UNSAFE_className === null || UNSAFE_className === void 0 ? void 0 : UNSAFE_className.header })),
|
|
193
|
+
item.actions.map(action => {
|
|
194
|
+
const currentIndex = itemIndexCounter++;
|
|
195
|
+
return (React.createElement(Action, Object.assign({ UNSAFE_style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.action, UNSAFE_className: UNSAFE_className === null || UNSAFE_className === void 0 ? void 0 : UNSAFE_className.action, sectionLabel: item.header, key: action.label, tabIndex: activeIndex === currentIndex ? 0 : -1, setItemNode: node => {
|
|
196
|
+
listRef.current[currentIndex] = node;
|
|
197
|
+
}, getItemProps: getItemProps }, action)));
|
|
198
|
+
}))));
|
|
93
199
|
return (React.createElement("div", { className: wrapperClasses, onClick: handleParentClick },
|
|
94
|
-
React.createElement("div", { ref: setReferenceElement }, React.cloneElement(activator, {
|
|
200
|
+
React.createElement("div", Object.assign({ ref: setReferenceElement }, getReferenceProps()), React.cloneElement(activator, {
|
|
95
201
|
onClick: toggle(activator.props.onClick),
|
|
96
202
|
id: buttonID,
|
|
97
203
|
ariaControls: menuID,
|
|
@@ -100,16 +206,14 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
100
206
|
})),
|
|
101
207
|
React.createElement(MenuPortal, null,
|
|
102
208
|
React.createElement(framerMotion.AnimatePresence, null, visible && (React.createElement(React.Fragment, null,
|
|
103
|
-
React.createElement(framerMotion.motion.div, { className: styles.overlay, onClick: toggle(), variants: variation, initial: "overlayStartStop", animate: "done", exit: "overlayStartStop", transition: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
item.header && (React.createElement(SectionHeader, { text: item.header, UNSAFE_style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.header, UNSAFE_className: UNSAFE_className === null || UNSAFE_className === void 0 ? void 0 : UNSAFE_className.header })),
|
|
112
|
-
item.actions.map(action => (React.createElement(Action, Object.assign({ UNSAFE_style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.action, UNSAFE_className: UNSAFE_className === null || UNSAFE_className === void 0 ? void 0 : UNSAFE_className.action, sectionLabel: item.header, key: action.label }, action))))))))))))))));
|
|
209
|
+
React.createElement(framerMotion.motion.div, { className: styles.overlay, onClick: toggle(), variants: variation, initial: "overlayStartStop", animate: "done", exit: "overlayStartStop", transition: Object.assign({}, OVERLAY_ANIMATION_CONFIG) }),
|
|
210
|
+
React.createElement("div", Object.assign({ ref: refs.setFloating, className: styles.floatingContainer }, getFloatingProps({
|
|
211
|
+
onKeyDown: event => {
|
|
212
|
+
if (event.key === "Tab") {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
}), positionAttributes, useFormFieldFocus.formFieldFocusAttribute), items.length > 0 && (React.createElement(framerMotion.motion.div, { className: classnames(styles.menu, UNSAFE_className === null || UNSAFE_className === void 0 ? void 0 : UNSAFE_className.menu), role: "menu", "data-elevation": "elevated", "aria-labelledby": buttonID, id: menuID, onClick: hide, variants: variation, initial: "startOrStop", animate: "done", exit: "startOrStop", custom: context === null || context === void 0 ? void 0 : context.placement, transition: Object.assign({}, MENU_ANIMATION_CONFIG), style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.menu }, renderedSections)))))))));
|
|
113
217
|
function toggle(callbackPassthrough) {
|
|
114
218
|
return (event) => {
|
|
115
219
|
setVisible(!visible);
|
|
@@ -118,6 +222,7 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
118
222
|
}
|
|
119
223
|
function hide() {
|
|
120
224
|
setVisible(false);
|
|
225
|
+
setActiveIndex(null);
|
|
121
226
|
}
|
|
122
227
|
function handleParentClick(event) {
|
|
123
228
|
// Since the menu is being rendered within the same parent as the activator,
|
|
@@ -129,20 +234,32 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
|
|
|
129
234
|
}
|
|
130
235
|
function SectionHeader({ text, UNSAFE_style, UNSAFE_className, }) {
|
|
131
236
|
return (React.createElement("div", { className: classnames(styles.sectionHeader, UNSAFE_className), "aria-hidden": true, style: UNSAFE_style },
|
|
132
|
-
React.createElement(
|
|
237
|
+
React.createElement(DefaultHeaderContent, null, text)));
|
|
133
238
|
}
|
|
134
|
-
function Action(
|
|
135
|
-
const
|
|
136
|
-
const buttonClasses = classnames(styles.action, {
|
|
239
|
+
function Action(props) {
|
|
240
|
+
const { label, sectionLabel, icon, iconColor, destructive, UNSAFE_style, UNSAFE_className, onClick, tabIndex, setItemNode, getItemProps, } = props;
|
|
241
|
+
const buttonClasses = classnames(styles.action, styles.legacyAction, {
|
|
137
242
|
[styles.destructive]: destructive,
|
|
138
243
|
});
|
|
139
|
-
return (React.createElement("button", {
|
|
244
|
+
return (React.createElement("button", Object.assign({ className: classnames(buttonClasses, UNSAFE_className), style: UNSAFE_style, key: label, type: "button" }, getItemProps({
|
|
245
|
+
ref: setItemNode,
|
|
246
|
+
role: "menuitem",
|
|
247
|
+
onClick,
|
|
248
|
+
tabIndex,
|
|
249
|
+
})),
|
|
250
|
+
React.createElement(DefaultItemContent, { label: label, icon: icon, iconColor: iconColor, destructive: destructive, sectionLabel: sectionLabel })));
|
|
251
|
+
}
|
|
252
|
+
function DefaultItemContent({ label, icon, iconColor, destructive, sectionLabel, }) {
|
|
253
|
+
return (React.createElement(React.Fragment, null,
|
|
140
254
|
icon && (React.createElement("div", null,
|
|
141
255
|
React.createElement(Icon.Icon, { color: destructive ? "destructive" : iconColor, name: icon }))),
|
|
142
|
-
React.createElement(Typography.Typography, { element: "span", fontWeight: "semiBold", textColor: "text" },
|
|
256
|
+
React.createElement(Typography.Typography, { element: "span", fontWeight: "semiBold", textColor: destructive ? "destructive" : "text" },
|
|
143
257
|
sectionLabel && (React.createElement("span", { className: styles.screenReaderOnly }, sectionLabel)),
|
|
144
258
|
label)));
|
|
145
259
|
}
|
|
260
|
+
function DefaultHeaderContent({ children, }) {
|
|
261
|
+
return (React.createElement(Typography.Typography, { element: "h6", size: "base", textColor: "textSecondary", fontWeight: "regular", textCase: "none" }, children));
|
|
262
|
+
}
|
|
146
263
|
function MenuPortal({ children }) {
|
|
147
264
|
const mounted = jobberHooks.useIsMounted();
|
|
148
265
|
if (!(mounted === null || mounted === void 0 ? void 0 : mounted.current)) {
|
|
@@ -150,5 +267,122 @@ function MenuPortal({ children }) {
|
|
|
150
267
|
}
|
|
151
268
|
return React.createElement(floatingUi_react.FloatingPortal, null, children);
|
|
152
269
|
}
|
|
270
|
+
const MenuAnimationContext = React.createContext(null);
|
|
271
|
+
function useMenuAnimation() {
|
|
272
|
+
const ctx = React.useContext(MenuAnimationContext);
|
|
273
|
+
if (!ctx) {
|
|
274
|
+
throw new Error("MenuAnimationContext used outside provider");
|
|
275
|
+
}
|
|
276
|
+
return ctx;
|
|
277
|
+
}
|
|
278
|
+
function MenuComposable({ children, onOpenChange, open, defaultOpen, }) {
|
|
279
|
+
const isInitiallyOpen = Boolean(open !== null && open !== void 0 ? open : defaultOpen);
|
|
280
|
+
const [animation, setAnimation] = React.useState(isInitiallyOpen ? "visible" : "unmounted");
|
|
281
|
+
const derivedAnimation = getDerivedAnimation(open, animation);
|
|
282
|
+
return (React.createElement(MenuAnimationContext.Provider, { value: { state: derivedAnimation, setState: setAnimation } },
|
|
283
|
+
React.createElement(Tree.$3674c52c6b3c5bce$export$27d2ad3c5815583e, { isOpen: open, defaultOpen: defaultOpen, onOpenChange: isOpen => {
|
|
284
|
+
setAnimation(isOpen ? "visible" : "hidden");
|
|
285
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(isOpen);
|
|
286
|
+
} }, children)));
|
|
287
|
+
}
|
|
288
|
+
function getDerivedAnimation(open, animation) {
|
|
289
|
+
const isControlled = open !== undefined;
|
|
290
|
+
if (!isControlled)
|
|
291
|
+
return animation;
|
|
292
|
+
if (open)
|
|
293
|
+
return "visible";
|
|
294
|
+
// When controlled and closing, allow local state to progress to "unmounted"
|
|
295
|
+
// so the Popover can be removed from the DOM once exit completes.
|
|
296
|
+
return animation === "unmounted" ? "unmounted" : "hidden";
|
|
297
|
+
}
|
|
298
|
+
const MenuTriggerComposable = React.forwardRef(function MenuTriggerComposable({ ariaLabel, children }, ref) {
|
|
299
|
+
return (React.createElement($3b117e43dc0ca95d$export$27c701ed9e449e99, { "aria-label": ariaLabel },
|
|
300
|
+
React.createElement("div", { role: "button", className: styles.triggerWrapper, ref: ref }, children)));
|
|
301
|
+
});
|
|
302
|
+
function MenuContentComposable({ children, UNSAFE_style, UNSAFE_className, }) {
|
|
303
|
+
const { state: animation, setState } = useMenuAnimation();
|
|
304
|
+
const isMobile = isMobileDevice();
|
|
305
|
+
return (React.createElement(React.Fragment, null,
|
|
306
|
+
React.createElement(Tree.$07b14b47974efb58$export$5b6b19405a83ff9d, { isExiting: animation === "hidden", placement: "bottom start", offset: MENU_OFFSET }, ({ placement }) => {
|
|
307
|
+
const directionModifier = (placement === null || placement === void 0 ? void 0 : placement.includes("bottom")) ? -1 : 1;
|
|
308
|
+
const variants = isMobile
|
|
309
|
+
? {
|
|
310
|
+
hidden: { opacity: 0, y: Y_TRANSLATION_MOBILE },
|
|
311
|
+
visible: { opacity: 1, y: 0 },
|
|
312
|
+
}
|
|
313
|
+
: {
|
|
314
|
+
hidden: {
|
|
315
|
+
opacity: 0,
|
|
316
|
+
y: Y_TRANSLATION_DESKTOP * directionModifier,
|
|
317
|
+
},
|
|
318
|
+
visible: { opacity: 1, y: 0 },
|
|
319
|
+
};
|
|
320
|
+
return (React.createElement(MotionMenu, { key: `menu-content-${placement !== null && placement !== void 0 ? placement : "pending"}`, className: classnames(styles.menu, styles.ariaMenu, UNSAFE_className), style: UNSAFE_style, variants: variants, initial: "hidden",
|
|
321
|
+
// placement is null on first render cycle, so we need to wait for it to be defined
|
|
322
|
+
animate: placement ? animation : false, transition: Object.assign({}, MENU_ANIMATION_CONFIG), onAnimationComplete: animationState => {
|
|
323
|
+
setState(prev => animationState === "hidden" && prev === "hidden"
|
|
324
|
+
? "unmounted"
|
|
325
|
+
: prev);
|
|
326
|
+
} }, children));
|
|
327
|
+
}),
|
|
328
|
+
isMobile && React.createElement(MenuMobileUnderlay, { animation: animation })));
|
|
329
|
+
}
|
|
330
|
+
function MenuMobileUnderlay({ animation }) {
|
|
331
|
+
if (animation === "unmounted")
|
|
332
|
+
return null;
|
|
333
|
+
return (React.createElement(framerMotion.motion.div, { key: "menu-mobile-underlay", variants: composeOverlayVariation, initial: "hidden", transition: Object.assign({}, OVERLAY_ANIMATION_CONFIG), className: styles.overlay, animate: animation }));
|
|
334
|
+
}
|
|
335
|
+
function MenuSeparatorComposable({ UNSAFE_style, UNSAFE_className, }) {
|
|
336
|
+
return (React.createElement(Tree.$431f98aba6844401$export$1ff3c3f08ae963c0, { className: classnames(styles.separator, UNSAFE_className), style: UNSAFE_style, "data-testid": "ATL-Menu-Separator" }));
|
|
337
|
+
}
|
|
338
|
+
function MenuSectionComposable({ children, UNSAFE_style, UNSAFE_className, ariaLabel, }) {
|
|
339
|
+
return (React.createElement(Tree.$3674c52c6b3c5bce$export$4b1545b4f2016d26, { "aria-label": ariaLabel, className: classnames(styles.ariaSection, UNSAFE_className), style: UNSAFE_style }, children));
|
|
340
|
+
}
|
|
341
|
+
function MenuHeaderComposable(props) {
|
|
342
|
+
const { UNSAFE_style, UNSAFE_className } = props;
|
|
343
|
+
return (React.createElement(Tree.$72a5793c14baf454$export$8b251419efc915eb, { className: classnames(styles.sectionHeader, styles.ariaSectionHeader, UNSAFE_className), style: UNSAFE_style }, props.children));
|
|
344
|
+
}
|
|
345
|
+
const MenuItemComposable = React.forwardRef(function MenuItemComposable(props, ref) {
|
|
346
|
+
const { UNSAFE_style, UNSAFE_className } = props;
|
|
347
|
+
const className = classnames(styles.action, styles.ariaItem, UNSAFE_className);
|
|
348
|
+
if (props.href) {
|
|
349
|
+
const { href, target, rel, onClick } = props;
|
|
350
|
+
return (React.createElement(Tree.$3674c52c6b3c5bce$export$2ce376c2cc3355c8, { ref: ref, className: className, style: UNSAFE_style, textValue: props.textValue, href: href, target: target, rel: rel, onClick: onClick },
|
|
351
|
+
React.createElement(MenuItemContext.Provider, { value: { destructive: props.destructive } }, props.children)));
|
|
352
|
+
}
|
|
353
|
+
return (React.createElement(Tree.$3674c52c6b3c5bce$export$2ce376c2cc3355c8, { ref: ref, className: className, style: UNSAFE_style, textValue: props.textValue, onAction: () => {
|
|
354
|
+
var _a;
|
|
355
|
+
// Zero-arg activation for non-link items
|
|
356
|
+
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
357
|
+
} },
|
|
358
|
+
React.createElement(MenuItemContext.Provider, { value: { destructive: props.destructive } }, props.children)));
|
|
359
|
+
});
|
|
360
|
+
const MenuItemContext = React.createContext(null);
|
|
361
|
+
function useMenuItemContext() {
|
|
362
|
+
const ctx = React.useContext(MenuItemContext);
|
|
363
|
+
return ctx !== null && ctx !== void 0 ? ctx : {};
|
|
364
|
+
}
|
|
365
|
+
function MenuItemIconComposable(props) {
|
|
366
|
+
const { destructive } = useMenuItemContext();
|
|
367
|
+
return (React.createElement("div", { "data-menu-slot": "icon" },
|
|
368
|
+
React.createElement(Icon.Icon, Object.assign({}, props, { color: destructive ? "destructive" : props.color }))));
|
|
369
|
+
}
|
|
370
|
+
function MenuItemLabelComposable(props) {
|
|
371
|
+
const { destructive } = useMenuItemContext();
|
|
372
|
+
return (React.createElement("div", { "data-menu-slot": "label" },
|
|
373
|
+
React.createElement(Typography.Typography, { element: "span", fontWeight: "semiBold", textColor: destructive ? "destructive" : "text" }, props.children)));
|
|
374
|
+
}
|
|
375
|
+
function MenuHeaderLabel(props) {
|
|
376
|
+
return React.createElement(DefaultHeaderContent, null, props.children);
|
|
377
|
+
}
|
|
378
|
+
Menu.Section = MenuSectionComposable;
|
|
379
|
+
Menu.Header = MenuHeaderComposable;
|
|
380
|
+
Menu.Item = MenuItemComposable;
|
|
381
|
+
Menu.Trigger = MenuTriggerComposable;
|
|
382
|
+
Menu.Content = MenuContentComposable;
|
|
383
|
+
Menu.Separator = MenuSeparatorComposable;
|
|
384
|
+
Menu.ItemIcon = MenuItemIconComposable;
|
|
385
|
+
Menu.ItemLabel = MenuItemLabelComposable;
|
|
386
|
+
Menu.HeaderLabel = MenuHeaderLabel;
|
|
153
387
|
|
|
154
388
|
exports.Menu = Menu;
|