@primer/components 0.0.0-20211111716 → 0.0.0-2021111174919
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 +5 -1
- package/lib/ActionList2/Divider.d.ts +3 -2
- package/lib/ActionList2/Divider.js +10 -5
- package/lib/ActionList2/Item.js +21 -5
- package/lib/ActionList2/List.js +11 -1
- package/lib/ActionList2/MenuContext.d.ts +10 -0
- package/lib/ActionList2/MenuContext.js +15 -0
- package/lib/ActionList2/Selection.js +11 -0
- package/lib/ActionList2/index.d.ts +1 -2
- package/lib/ActionMenu2.d.ts +310 -0
- package/lib/ActionMenu2.js +91 -0
- package/lib/drafts.d.ts +1 -0
- package/lib/drafts.js +13 -0
- package/lib-esm/ActionList2/Divider.d.ts +3 -2
- package/lib-esm/ActionList2/Divider.js +8 -5
- package/lib-esm/ActionList2/Item.js +19 -5
- package/lib-esm/ActionList2/List.js +9 -1
- package/lib-esm/ActionList2/MenuContext.d.ts +10 -0
- package/lib-esm/ActionList2/MenuContext.js +3 -0
- package/lib-esm/ActionList2/Selection.js +9 -0
- package/lib-esm/ActionList2/index.d.ts +1 -2
- package/lib-esm/ActionMenu2.d.ts +310 -0
- package/lib-esm/ActionMenu2.js +67 -0
- package/lib-esm/drafts.d.ts +1 -0
- package/lib-esm/drafts.js +2 -1
- package/package.json +1 -1
@@ -0,0 +1,67 @@
|
|
1
|
+
import Button from './Button';
|
2
|
+
import React from 'react';
|
3
|
+
import { AnchoredOverlay } from './AnchoredOverlay';
|
4
|
+
import { useProvidedStateOrCreate } from './hooks/useProvidedStateOrCreate';
|
5
|
+
import { useProvidedRefOrCreate } from './hooks';
|
6
|
+
import { Divider } from './ActionList2/Divider';
|
7
|
+
import { MenuContext as ActionListMenuContext } from './ActionList2/MenuContext';
|
8
|
+
|
9
|
+
const ActionMenuBase = ({
|
10
|
+
anchorRef: externalAnchorRef,
|
11
|
+
open,
|
12
|
+
onOpenChange,
|
13
|
+
overlayProps,
|
14
|
+
children
|
15
|
+
}) => {
|
16
|
+
const [combinedOpenState, setCombinedOpenState] = useProvidedStateOrCreate(open, onOpenChange, false);
|
17
|
+
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
18
|
+
const onOpen = React.useCallback(() => setCombinedOpenState(true), [setCombinedOpenState]);
|
19
|
+
const onClose = React.useCallback(() => setCombinedOpenState(false), [setCombinedOpenState]);
|
20
|
+
let renderAnchor = null;
|
21
|
+
const contents = [];
|
22
|
+
React.Children.map(children, child => {
|
23
|
+
if (child.type === MenuButton || child.type === Anchor) {
|
24
|
+
renderAnchor = anchorProps => /*#__PURE__*/React.cloneElement(child, anchorProps);
|
25
|
+
} else {
|
26
|
+
contents.push(child);
|
27
|
+
}
|
28
|
+
});
|
29
|
+
return /*#__PURE__*/React.createElement(AnchoredOverlay, {
|
30
|
+
renderAnchor: renderAnchor,
|
31
|
+
anchorRef: anchorRef,
|
32
|
+
open: combinedOpenState,
|
33
|
+
onOpen: onOpen,
|
34
|
+
onClose: onClose,
|
35
|
+
overlayProps: overlayProps
|
36
|
+
}, /*#__PURE__*/React.createElement(ActionListMenuContext.Provider, {
|
37
|
+
value: {
|
38
|
+
parent: 'ActionMenu',
|
39
|
+
listRole: 'menu',
|
40
|
+
itemRole: 'menuitem',
|
41
|
+
afterSelect: onClose
|
42
|
+
}
|
43
|
+
}, contents));
|
44
|
+
};
|
45
|
+
|
46
|
+
ActionMenuBase.displayName = "ActionMenuBase";
|
47
|
+
const Anchor = /*#__PURE__*/React.forwardRef(({
|
48
|
+
children,
|
49
|
+
...anchorProps
|
50
|
+
}, anchorRef) => {
|
51
|
+
return /*#__PURE__*/React.cloneElement(children, { ...anchorProps,
|
52
|
+
ref: anchorRef
|
53
|
+
});
|
54
|
+
});
|
55
|
+
/** this component is syntactical sugar 🍭 */
|
56
|
+
|
57
|
+
const MenuButton = /*#__PURE__*/React.forwardRef((props, anchorRef) => {
|
58
|
+
return /*#__PURE__*/React.createElement(Anchor, {
|
59
|
+
ref: anchorRef
|
60
|
+
}, /*#__PURE__*/React.createElement(Button, props));
|
61
|
+
});
|
62
|
+
ActionMenuBase.displayName = 'ActionMenu';
|
63
|
+
export const ActionMenu = Object.assign(ActionMenuBase, {
|
64
|
+
Button: MenuButton,
|
65
|
+
Anchor,
|
66
|
+
Divider
|
67
|
+
});
|
package/lib-esm/drafts.d.ts
CHANGED
package/lib-esm/drafts.js
CHANGED