@react-spectrum/menu 3.11.1-nightly.3894 → 3.11.1-nightly.3901
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/import.mjs +185 -325
- package/dist/main.css +1 -1
- package/dist/main.js +181 -322
- package/dist/main.js.map +1 -1
- package/dist/module.js +185 -325
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +4 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +28 -29
- package/src/Menu.tsx +35 -40
- package/src/MenuItem.tsx +18 -49
- package/src/MenuTrigger.tsx +0 -1
- package/src/context.ts +1 -26
- package/src/index.ts +2 -3
- package/src/MenuDialogTrigger.tsx +0 -87
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2023 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {classNames, SlotProvider, useIsMobileDevice} from '@react-spectrum/utils';
|
|
14
|
-
import {DismissButton} from '@react-aria/overlays';
|
|
15
|
-
import helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';
|
|
16
|
-
import {ItemProps} from '@react-types/shared';
|
|
17
|
-
import {MenuDialogContext, useMenuStateContext} from './context';
|
|
18
|
-
import {Modal, Popover} from '@react-spectrum/overlays';
|
|
19
|
-
import React, {Key, ReactElement, useRef} from 'react';
|
|
20
|
-
import {useOverlayTriggerState} from '@react-stately/overlays';
|
|
21
|
-
|
|
22
|
-
export interface SpectrumMenuDialogTriggerProps<T> extends ItemProps<T> {
|
|
23
|
-
isUnavailable?: boolean,
|
|
24
|
-
targetKey: Key
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function MenuDialogTrigger<T>(props: SpectrumMenuDialogTriggerProps<T>): ReactElement {
|
|
28
|
-
let {isUnavailable} = props;
|
|
29
|
-
|
|
30
|
-
let {state: menuState} = useMenuStateContext();
|
|
31
|
-
let state = useOverlayTriggerState({isOpen: menuState.expandedKeys.has(props.targetKey), onOpenChange: (val) => {
|
|
32
|
-
if (!val) {
|
|
33
|
-
if (menuState.expandedKeys.has(props.targetKey)) {
|
|
34
|
-
menuState.toggleKey(props.targetKey);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}});
|
|
38
|
-
let slots = {};
|
|
39
|
-
if (isUnavailable) {
|
|
40
|
-
slots = {
|
|
41
|
-
dialog: {UNSAFE_className: classNames(helpStyles, 'react-spectrum-ContextualHelp-dialog')},
|
|
42
|
-
content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},
|
|
43
|
-
footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
let [trigger] = React.Children.toArray(props.children);
|
|
47
|
-
let [, content] = props.children as [ReactElement, ReactElement];
|
|
48
|
-
|
|
49
|
-
let isMobile = useIsMobileDevice();
|
|
50
|
-
let triggerRef = useRef<HTMLLIElement>(null);
|
|
51
|
-
return (
|
|
52
|
-
<>
|
|
53
|
-
<MenuDialogContext.Provider value={{isUnavailable, triggerRef}}>{trigger}</MenuDialogContext.Provider>
|
|
54
|
-
<SlotProvider slots={slots}>
|
|
55
|
-
{
|
|
56
|
-
isMobile ? (
|
|
57
|
-
<Modal state={state} isDismissable>
|
|
58
|
-
<DismissButton onDismiss={state.close} />
|
|
59
|
-
{content}
|
|
60
|
-
<DismissButton onDismiss={state.close} />
|
|
61
|
-
</Modal>
|
|
62
|
-
) : (
|
|
63
|
-
<Popover state={state} triggerRef={triggerRef} placement="end top" hideArrow offset={-10} isNonModal shouldContainFocus={false}>{content}</Popover>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
</SlotProvider>
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
MenuDialogTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {
|
|
72
|
-
let [trigger] = React.Children.toArray(props.children) as ReactElement[];
|
|
73
|
-
let [, content] = props.children as [ReactElement, ReactElement];
|
|
74
|
-
|
|
75
|
-
yield {
|
|
76
|
-
element: React.cloneElement(trigger, {...trigger.props, hasChildItems: true}),
|
|
77
|
-
wrapper: (element) => (
|
|
78
|
-
<MenuDialogTrigger key={element.key} targetKey={element.key} {...props}>
|
|
79
|
-
{element}
|
|
80
|
-
{content}
|
|
81
|
-
</MenuDialogTrigger>
|
|
82
|
-
)
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
let _Item = MenuDialogTrigger as <T>(props: ItemProps<T> & {isUnavailable?: boolean}) => JSX.Element;
|
|
87
|
-
export {_Item as MenuDialogTrigger};
|