@primer/components 0.0.0-20211030141453 → 0.0.0-20211030151352
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 +7 -1
- package/dist/browser.esm.js +1 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +1 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +3 -3
- 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 +12 -3
- 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/ActionList/Item.js +3 -3
- 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 +10 -3
- 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,91 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ActionMenu = void 0;
|
7
|
+
|
8
|
+
var _Button = _interopRequireDefault(require("./Button"));
|
9
|
+
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
11
|
+
|
12
|
+
var _AnchoredOverlay = require("./AnchoredOverlay");
|
13
|
+
|
14
|
+
var _useProvidedStateOrCreate = require("./hooks/useProvidedStateOrCreate");
|
15
|
+
|
16
|
+
var _hooks = require("./hooks");
|
17
|
+
|
18
|
+
var _Divider = require("./ActionList2/Divider");
|
19
|
+
|
20
|
+
var _MenuContext = require("./ActionList2/MenuContext");
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
const ActionMenuBase = ({
|
25
|
+
anchorRef: externalAnchorRef,
|
26
|
+
open,
|
27
|
+
onOpenChange,
|
28
|
+
overlayProps,
|
29
|
+
children
|
30
|
+
}) => {
|
31
|
+
const [combinedOpenState, setCombinedOpenState] = (0, _useProvidedStateOrCreate.useProvidedStateOrCreate)(open, onOpenChange, false);
|
32
|
+
const anchorRef = (0, _hooks.useProvidedRefOrCreate)(externalAnchorRef);
|
33
|
+
|
34
|
+
const onOpen = _react.default.useCallback(() => setCombinedOpenState(true), [setCombinedOpenState]);
|
35
|
+
|
36
|
+
const onClose = _react.default.useCallback(() => setCombinedOpenState(false), [setCombinedOpenState]);
|
37
|
+
|
38
|
+
let renderAnchor = null;
|
39
|
+
const contents = [];
|
40
|
+
|
41
|
+
_react.default.Children.map(children, child => {
|
42
|
+
if (child.type === MenuButton || child.type === Anchor) {
|
43
|
+
renderAnchor = anchorProps => /*#__PURE__*/_react.default.cloneElement(child, anchorProps);
|
44
|
+
} else {
|
45
|
+
contents.push(child);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
return /*#__PURE__*/_react.default.createElement(_AnchoredOverlay.AnchoredOverlay, {
|
50
|
+
renderAnchor: renderAnchor,
|
51
|
+
anchorRef: anchorRef,
|
52
|
+
open: combinedOpenState,
|
53
|
+
onOpen: onOpen,
|
54
|
+
onClose: onClose,
|
55
|
+
overlayProps: overlayProps
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_MenuContext.MenuContext.Provider, {
|
57
|
+
value: {
|
58
|
+
parent: 'ActionMenu',
|
59
|
+
listRole: 'menu',
|
60
|
+
itemRole: 'menuitem',
|
61
|
+
afterSelect: onClose
|
62
|
+
}
|
63
|
+
}, contents));
|
64
|
+
};
|
65
|
+
|
66
|
+
ActionMenuBase.displayName = "ActionMenuBase";
|
67
|
+
|
68
|
+
const Anchor = /*#__PURE__*/_react.default.forwardRef(({
|
69
|
+
children,
|
70
|
+
...anchorProps
|
71
|
+
}, anchorRef) => {
|
72
|
+
return /*#__PURE__*/_react.default.cloneElement(children, { ...anchorProps,
|
73
|
+
ref: anchorRef
|
74
|
+
});
|
75
|
+
});
|
76
|
+
/** this component is syntactical sugar 🍭 */
|
77
|
+
|
78
|
+
|
79
|
+
const MenuButton = /*#__PURE__*/_react.default.forwardRef((props, anchorRef) => {
|
80
|
+
return /*#__PURE__*/_react.default.createElement(Anchor, {
|
81
|
+
ref: anchorRef
|
82
|
+
}, /*#__PURE__*/_react.default.createElement(_Button.default, props));
|
83
|
+
});
|
84
|
+
|
85
|
+
ActionMenuBase.displayName = 'ActionMenu';
|
86
|
+
const ActionMenu = Object.assign(ActionMenuBase, {
|
87
|
+
Button: MenuButton,
|
88
|
+
Anchor,
|
89
|
+
Divider: _Divider.Divider
|
90
|
+
});
|
91
|
+
exports.ActionMenu = ActionMenu;
|
package/lib/drafts.d.ts
CHANGED
package/lib/drafts.js
CHANGED
@@ -28,4 +28,17 @@ Object.keys(_NewButton).forEach(function (key) {
|
|
28
28
|
return _NewButton[key];
|
29
29
|
}
|
30
30
|
});
|
31
|
+
});
|
32
|
+
|
33
|
+
var _ActionMenu = require("./ActionMenu2");
|
34
|
+
|
35
|
+
Object.keys(_ActionMenu).forEach(function (key) {
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
37
|
+
if (key in exports && exports[key] === _ActionMenu[key]) return;
|
38
|
+
Object.defineProperty(exports, key, {
|
39
|
+
enumerable: true,
|
40
|
+
get: function () {
|
41
|
+
return _ActionMenu[key];
|
42
|
+
}
|
43
|
+
});
|
31
44
|
});
|
@@ -93,7 +93,7 @@ export const TextContainer = styled.span.withConfig({
|
|
93
93
|
const BaseVisualContainer = styled.div.withConfig({
|
94
94
|
displayName: "Item__BaseVisualContainer",
|
95
95
|
componentId: "jqpvy8-4"
|
96
|
-
})(["height:20px;width:", ";margin-right:", ";display:flex;justify-content:center;align-items:center;"], get('space.3'), get('space.2'));
|
96
|
+
})(["height:20px;width:", ";margin-right:", ";display:flex;justify-content:center;align-items:center;flex-shrink:0;"], get('space.3'), get('space.2'));
|
97
97
|
const ColoredVisualContainer = styled(BaseVisualContainer).withConfig({
|
98
98
|
displayName: "Item__ColoredVisualContainer",
|
99
99
|
componentId: "jqpvy8-5"
|
@@ -104,7 +104,7 @@ const ColoredVisualContainer = styled(BaseVisualContainer).withConfig({
|
|
104
104
|
const LeadingVisualContainer = styled(ColoredVisualContainer).withConfig({
|
105
105
|
displayName: "Item__LeadingVisualContainer",
|
106
106
|
componentId: "jqpvy8-6"
|
107
|
-
})(["
|
107
|
+
})(["display:flex;flex-direction:column;justify-content:center;"]);
|
108
108
|
const TrailingContent = styled(ColoredVisualContainer).withConfig({
|
109
109
|
displayName: "Item__TrailingContent",
|
110
110
|
componentId: "jqpvy8-7"
|
@@ -119,7 +119,7 @@ const DescriptionContainer = styled.span.withConfig({
|
|
119
119
|
const MultiSelectIcon = styled.svg.withConfig({
|
120
120
|
displayName: "Item__MultiSelectIcon",
|
121
121
|
componentId: "jqpvy8-9"
|
122
|
-
})(["rect{fill:", ";stroke:", ";
|
122
|
+
})(["rect{fill:", ";stroke:", ";}path{fill:", ";boxshadow:", ";opacity:", ";}"], ({
|
123
123
|
selected
|
124
124
|
}) => selected ? get('colors.accent.fg') : get('colors.canvas.default'), ({
|
125
125
|
selected
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
import React from 'react';
|
2
|
+
import { SxProp } from '../sx';
|
2
3
|
/**
|
3
4
|
* Visually separates `Item`s or `Group`s in an `ActionList`.
|
4
5
|
*/
|
5
|
-
export declare
|
6
|
+
export declare const Divider: React.FC<SxProp>;
|
@@ -1,23 +1,26 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import Box from '../Box';
|
3
3
|
import { get } from '../constants';
|
4
|
-
|
4
|
+
import { merge } from '../sx';
|
5
5
|
/**
|
6
6
|
* Visually separates `Item`s or `Group`s in an `ActionList`.
|
7
7
|
*/
|
8
|
-
|
8
|
+
|
9
|
+
export const Divider = ({
|
10
|
+
sx = {}
|
11
|
+
}) => {
|
9
12
|
return /*#__PURE__*/React.createElement(Box, {
|
10
13
|
as: "li",
|
11
14
|
role: "separator",
|
12
|
-
sx: {
|
15
|
+
sx: merge({
|
13
16
|
height: 1,
|
14
17
|
backgroundColor: 'actionListItem.inlineDivider',
|
15
18
|
marginTop: theme => `calc(${get('space.2')(theme)} - 1px)`,
|
16
19
|
marginBottom: 2,
|
17
20
|
listStyle: 'none' // hide the ::marker inserted by browser's stylesheet
|
18
21
|
|
19
|
-
},
|
22
|
+
}, sx),
|
20
23
|
"data-component": "ActionList.Divider"
|
21
24
|
});
|
22
|
-
}
|
25
|
+
};
|
23
26
|
Divider.displayName = "Divider";
|
@@ -8,6 +8,7 @@ import Box from '../Box';
|
|
8
8
|
import sx, { merge } from '../sx';
|
9
9
|
import createSlots from '../utils/create-slots';
|
10
10
|
import { ListContext } from './List';
|
11
|
+
import { MenuContext } from './MenuContext';
|
11
12
|
import { Selection } from './Selection';
|
12
13
|
export const getVariantStyles = (variant, disabled) => {
|
13
14
|
if (disabled) {
|
@@ -54,6 +55,7 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
54
55
|
onSelect,
|
55
56
|
sx: sxProp = {},
|
56
57
|
id,
|
58
|
+
role,
|
57
59
|
_PrivateItemWrapper,
|
58
60
|
...props
|
59
61
|
}, forwardedRef) => {
|
@@ -61,6 +63,10 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
61
63
|
variant: listVariant,
|
62
64
|
showDividers
|
63
65
|
} = React.useContext(ListContext);
|
66
|
+
const {
|
67
|
+
itemRole,
|
68
|
+
afterSelect
|
69
|
+
} = React.useContext(MenuContext);
|
64
70
|
const {
|
65
71
|
theme
|
66
72
|
} = useTheme();
|
@@ -135,16 +141,23 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
135
141
|
const clickHandler = React.useCallback(event => {
|
136
142
|
if (typeof onSelect !== 'function') return;
|
137
143
|
if (disabled) return;
|
138
|
-
|
139
|
-
|
144
|
+
|
145
|
+
if (!event.defaultPrevented) {
|
146
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
147
|
+
|
148
|
+
if (typeof afterSelect === 'function') afterSelect();
|
149
|
+
}
|
150
|
+
}, [onSelect, disabled, afterSelect]);
|
140
151
|
const keyPressHandler = React.useCallback(event => {
|
141
152
|
if (typeof onSelect !== 'function') return;
|
142
153
|
if (disabled) return;
|
143
154
|
|
144
155
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
145
|
-
onSelect(event);
|
156
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
157
|
+
|
158
|
+
if (typeof afterSelect === 'function') afterSelect();
|
146
159
|
}
|
147
|
-
}, [onSelect, disabled]); // use props.id if provided, otherwise generate one.
|
160
|
+
}, [onSelect, disabled, afterSelect]); // use props.id if provided, otherwise generate one.
|
148
161
|
|
149
162
|
const labelId = useSSRSafeId(id);
|
150
163
|
const inlineDescriptionId = useSSRSafeId(id && `${id}--inline-description`);
|
@@ -166,7 +179,8 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
166
179
|
"aria-disabled": disabled ? true : undefined,
|
167
180
|
tabIndex: disabled || _PrivateItemWrapper ? undefined : 0,
|
168
181
|
"aria-labelledby": `${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`,
|
169
|
-
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined
|
182
|
+
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined,
|
183
|
+
role: role || itemRole
|
170
184
|
}, props), /*#__PURE__*/React.createElement(ItemWrapper, null, /*#__PURE__*/React.createElement(Selection, {
|
171
185
|
selected: selected
|
172
186
|
}), slots.LeadingVisual, /*#__PURE__*/React.createElement(Box, {
|
@@ -3,6 +3,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
3
3
|
import React from 'react';
|
4
4
|
import styled from 'styled-components';
|
5
5
|
import sx, { merge } from '../sx';
|
6
|
+
import { MenuContext } from './MenuContext';
|
6
7
|
export const ListContext = /*#__PURE__*/React.createContext({});
|
7
8
|
const ListBox = styled.ul.withConfig({
|
8
9
|
displayName: "List__ListBox",
|
@@ -12,6 +13,7 @@ export const List = /*#__PURE__*/React.forwardRef(({
|
|
12
13
|
variant = 'inset',
|
13
14
|
selectionVariant,
|
14
15
|
showDividers = false,
|
16
|
+
role,
|
15
17
|
sx: sxProp = {},
|
16
18
|
...props
|
17
19
|
}, forwardedRef) => {
|
@@ -21,8 +23,14 @@ export const List = /*#__PURE__*/React.forwardRef(({
|
|
21
23
|
// reset ul styles
|
22
24
|
paddingY: variant === 'inset' ? 2 : 0
|
23
25
|
};
|
26
|
+
/** if list is inside a Menu, it will get a role from the Menu */
|
27
|
+
|
28
|
+
const {
|
29
|
+
listRole
|
30
|
+
} = React.useContext(MenuContext);
|
24
31
|
return /*#__PURE__*/React.createElement(ListBox, _extends({
|
25
|
-
sx: merge(styles, sxProp)
|
32
|
+
sx: merge(styles, sxProp),
|
33
|
+
role: role || listRole
|
26
34
|
}, props, {
|
27
35
|
ref: forwardedRef
|
28
36
|
}), /*#__PURE__*/React.createElement(ListContext.Provider, {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/** This context can be used by components that compose ActionList inside a Menu */
|
2
|
+
import React from 'react';
|
3
|
+
declare type ContextProps = {
|
4
|
+
parent?: string;
|
5
|
+
listRole?: string;
|
6
|
+
itemRole?: string;
|
7
|
+
afterSelect?: () => void;
|
8
|
+
};
|
9
|
+
export declare const MenuContext: React.Context<ContextProps>;
|
10
|
+
export {};
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
2
2
|
import { CheckIcon } from '@primer/octicons-react';
|
3
3
|
import { ListContext } from './List';
|
4
4
|
import { GroupContext } from './Group';
|
5
|
+
import { MenuContext } from './MenuContext';
|
5
6
|
import { LeadingVisualContainer } from './Visuals';
|
6
7
|
export const Selection = ({
|
7
8
|
selected
|
@@ -12,6 +13,9 @@ export const Selection = ({
|
|
12
13
|
const {
|
13
14
|
selectionVariant: groupSelectionVariant
|
14
15
|
} = React.useContext(GroupContext);
|
16
|
+
const {
|
17
|
+
parent
|
18
|
+
} = React.useContext(MenuContext);
|
15
19
|
/** selectionVariant in Group can override the selectionVariant in List root */
|
16
20
|
|
17
21
|
const selectionVariant = typeof groupSelectionVariant !== 'undefined' ? groupSelectionVariant : listSelectionVariant; // if selectionVariant is not set on List, don't show selection
|
@@ -22,6 +26,11 @@ export const Selection = ({
|
|
22
26
|
return null;
|
23
27
|
}
|
24
28
|
|
29
|
+
if (parent === 'ActionMenu') {
|
30
|
+
throw new Error('ActionList cannot have a selectionVariant inside ActionMenu, please use DropdownMenu or SelectPanel instead. More information: https://primer.style/design/components/action-list#application');
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
|
25
34
|
if (selectionVariant === 'single') {
|
26
35
|
return /*#__PURE__*/React.createElement(LeadingVisualContainer, null, selected && /*#__PURE__*/React.createElement(CheckIcon, null));
|
27
36
|
}
|
@@ -37,9 +46,7 @@ export const Selection = ({
|
|
37
46
|
sx: {
|
38
47
|
rect: {
|
39
48
|
fill: selected ? 'accent.fg' : 'canvas.default',
|
40
|
-
stroke: selected ? 'accent.fg' : 'border.default'
|
41
|
-
shapeRendering: 'auto' // this is a workaround to override global style in github/github
|
42
|
-
|
49
|
+
stroke: selected ? 'accent.fg' : 'border.default'
|
43
50
|
},
|
44
51
|
path: {
|
45
52
|
fill: 'fg.onEmphasis',
|
@@ -1,5 +1,4 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
import { Divider } from './Divider';
|
3
2
|
export type { ListProps as ActionListProps } from './List';
|
4
3
|
export type { GroupProps } from './Group';
|
5
4
|
export type { ItemProps } from './Item';
|
@@ -26,7 +25,7 @@ export declare const ActionList: import("@radix-ui/react-polymorphic").ForwardRe
|
|
26
25
|
referrerPolicy?: import("react").HTMLAttributeReferrerPolicy | undefined;
|
27
26
|
}>;
|
28
27
|
/** Visually separates `Item`s or `Group`s in an `ActionList`. */
|
29
|
-
Divider:
|
28
|
+
Divider: import("react").FC<import("../sx").SxProp>;
|
30
29
|
/** Secondary text which provides additional information about an `Item`. */
|
31
30
|
Description: import("react").FC<import("./Description").DescriptionProps>;
|
32
31
|
/** Icon (or similar) positioned before `Item` text. */
|