@primer/components 0.0.0-2021101914018 → 0.0.0-2021101914535
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 +6 -4
- package/lib/ActionList2/Divider.d.ts +3 -2
- package/lib/ActionList2/Divider.js +10 -5
- package/lib/ActionList2/Divider.jsx +5 -4
- package/lib/ActionList2/Group.d.ts +2 -28
- package/lib/ActionList2/Group.js +6 -55
- package/lib/ActionList2/Group.jsx +4 -33
- package/lib/ActionList2/Item.js +21 -5
- package/lib/ActionList2/Item.jsx +14 -5
- package/lib/ActionList2/List.d.ts +1 -1
- package/lib/ActionList2/List.js +11 -1
- package/lib/ActionList2/List.jsx +5 -2
- package/lib/ActionList2/index.d.ts +1 -2
- package/lib/ActionMenu2.d.ts +360 -0
- package/lib/ActionMenu2.js +92 -0
- package/lib/ActionMenu2.jsx +42 -0
- package/lib/Autocomplete/Autocomplete.d.ts +6 -6
- package/lib/Autocomplete/AutocompleteInput.d.ts +6 -6
- package/lib/Button/Button.d.ts +9 -9
- package/lib/Button/ButtonClose.d.ts +10 -10
- package/lib/Button/ButtonDanger.d.ts +9 -9
- package/lib/Button/ButtonInvisible.d.ts +9 -9
- package/lib/Button/ButtonOutline.d.ts +9 -9
- package/lib/Button/ButtonPrimary.d.ts +9 -9
- package/lib/CircleOcticon.d.ts +2 -2
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +24 -24
- package/lib/DropdownMenu/DropdownButton.d.ts +11 -11
- package/lib/FilterList.d.ts +2 -2
- package/lib/Position.d.ts +4 -4
- package/lib/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +6 -6
- package/lib/Timeline.d.ts +2 -2
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/drafts.d.ts +1 -0
- package/lib/drafts.js +1 -0
- package/lib-esm/ActionList2/Divider.d.ts +3 -2
- package/lib-esm/ActionList2/Divider.js +8 -5
- package/lib-esm/ActionList2/Group.d.ts +2 -28
- package/lib-esm/ActionList2/Group.js +5 -52
- package/lib-esm/ActionList2/Item.js +19 -5
- package/lib-esm/ActionList2/List.d.ts +1 -1
- package/lib-esm/ActionList2/List.js +9 -1
- package/lib-esm/ActionList2/index.d.ts +1 -2
- package/lib-esm/ActionMenu2.d.ts +360 -0
- package/lib-esm/ActionMenu2.js +66 -0
- package/lib-esm/Autocomplete/Autocomplete.d.ts +6 -6
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +6 -6
- package/lib-esm/Button/Button.d.ts +9 -9
- package/lib-esm/Button/ButtonClose.d.ts +10 -10
- package/lib-esm/Button/ButtonDanger.d.ts +9 -9
- package/lib-esm/Button/ButtonInvisible.d.ts +9 -9
- package/lib-esm/Button/ButtonOutline.d.ts +9 -9
- package/lib-esm/Button/ButtonPrimary.d.ts +9 -9
- package/lib-esm/CircleOcticon.d.ts +2 -2
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +24 -24
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +11 -11
- package/lib-esm/FilterList.d.ts +2 -2
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +6 -6
- package/lib-esm/Timeline.d.ts +2 -2
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/drafts.d.ts +1 -0
- package/lib-esm/drafts.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# @primer/components
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-2021101914535
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
7
|
+
- [#1619](https://github.com/primer/react/pull/1619) [`38e45b33`](https://github.com/primer/react/commit/38e45b33c5efe70134d2459e39ddcfb66941957d) Thanks [@siddharthkp](https://github.com/siddharthkp)! - Add composable `ActionMenu` to `@primer/components/drafts`
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
- Fake entry to force publishing
|
|
10
12
|
|
|
11
13
|
## 31.2.0
|
|
12
14
|
|
|
@@ -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>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Divider =
|
|
6
|
+
exports.Divider = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
@@ -11,25 +11,30 @@ var _Box = _interopRequireDefault(require("../Box"));
|
|
|
11
11
|
|
|
12
12
|
var _constants = require("../constants");
|
|
13
13
|
|
|
14
|
+
var _sx = require("../sx");
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Visually separates `Item`s or `Group`s in an `ActionList`.
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
const Divider = ({
|
|
22
|
+
sx = {}
|
|
23
|
+
}) => {
|
|
20
24
|
return /*#__PURE__*/_react.default.createElement(_Box.default, {
|
|
21
25
|
as: "li",
|
|
22
26
|
role: "separator",
|
|
23
|
-
sx: {
|
|
27
|
+
sx: (0, _sx.merge)({
|
|
24
28
|
height: 1,
|
|
25
29
|
backgroundColor: 'actionListItem.inlineDivider',
|
|
26
30
|
marginTop: theme => `calc(${(0, _constants.get)('space.2')(theme)} - 1px)`,
|
|
27
31
|
marginBottom: 2,
|
|
28
32
|
listStyle: 'none' // hide the ::marker inserted by browser's stylesheet
|
|
29
33
|
|
|
30
|
-
},
|
|
34
|
+
}, sx),
|
|
31
35
|
"data-component": "ActionList.Divider"
|
|
32
36
|
});
|
|
33
|
-
}
|
|
37
|
+
};
|
|
34
38
|
|
|
39
|
+
exports.Divider = Divider;
|
|
35
40
|
Divider.displayName = "Divider";
|
|
@@ -7,16 +7,17 @@ exports.Divider = void 0;
|
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const Box_1 = __importDefault(require("../Box"));
|
|
9
9
|
const constants_1 = require("../constants");
|
|
10
|
+
const sx_1 = require("../sx");
|
|
10
11
|
/**
|
|
11
12
|
* Visually separates `Item`s or `Group`s in an `ActionList`.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
return (<Box_1.default as="li" role="separator" sx={{
|
|
14
|
+
const Divider = ({ sx = {} }) => {
|
|
15
|
+
return (<Box_1.default as="li" role="separator" sx={sx_1.merge({
|
|
15
16
|
height: 1,
|
|
16
17
|
backgroundColor: 'actionListItem.inlineDivider',
|
|
17
18
|
marginTop: (theme) => `calc(${constants_1.get('space.2')(theme)} - 1px)`,
|
|
18
19
|
marginBottom: 2,
|
|
19
20
|
listStyle: 'none' // hide the ::marker inserted by browser's stylesheet
|
|
20
|
-
}} data-component="ActionList.Divider"/>);
|
|
21
|
-
}
|
|
21
|
+
}, sx)} data-component="ActionList.Divider"/>);
|
|
22
|
+
};
|
|
22
23
|
exports.Divider = Divider;
|
|
@@ -1,37 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SxProp } from '../sx';
|
|
3
|
+
import { HeaderProps } from './Header';
|
|
3
4
|
import { ListProps } from './List';
|
|
4
|
-
|
|
5
|
-
export declare type GroupProps = {
|
|
6
|
-
/**
|
|
7
|
-
* Style variations. Usage is discretionary.
|
|
8
|
-
*
|
|
9
|
-
* - `"filled"` - Superimposed on a background, offset from nearby content
|
|
10
|
-
* - `"subtle"` - Relatively less offset from nearby content
|
|
11
|
-
*/
|
|
12
|
-
variant?: 'subtle' | 'filled';
|
|
13
|
-
/**
|
|
14
|
-
* Primary text which names a `Group`.
|
|
15
|
-
*/
|
|
16
|
-
title?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Secondary text which provides additional information about a `Group`.
|
|
19
|
-
*/
|
|
20
|
-
auxiliaryText?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The ARIA role describing the function of the list inside `Group` component. `listbox` or `menu` are a common values.
|
|
23
|
-
*/
|
|
24
|
-
role?: AriaRole;
|
|
25
|
-
} & SxProp & {
|
|
26
|
-
/**
|
|
27
|
-
* Whether multiple Items or a single Item can be selected in the Group. Overrides value on ActionList root.
|
|
28
|
-
*/
|
|
5
|
+
export declare type GroupProps = HeaderProps & SxProp & {
|
|
29
6
|
selectionVariant?: ListProps['selectionVariant'] | false;
|
|
30
7
|
};
|
|
31
8
|
declare type ContextProps = Pick<GroupProps, 'selectionVariant'>;
|
|
32
9
|
export declare const GroupContext: React.Context<ContextProps>;
|
|
33
10
|
export declare const Group: React.FC<GroupProps>;
|
|
34
|
-
export declare type HeaderProps = Pick<GroupProps, 'variant' | 'title' | 'auxiliaryText'> & {
|
|
35
|
-
labelId: string;
|
|
36
|
-
};
|
|
37
11
|
export {};
|
package/lib/ActionList2/Group.js
CHANGED
|
@@ -7,11 +7,9 @@ exports.Group = exports.GroupContext = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _ssr = require("@react-aria/ssr");
|
|
11
|
-
|
|
12
10
|
var _Box = _interopRequireDefault(require("../Box"));
|
|
13
11
|
|
|
14
|
-
var
|
|
12
|
+
var _Header = require("./Header");
|
|
15
13
|
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
@@ -23,14 +21,12 @@ exports.GroupContext = GroupContext;
|
|
|
23
21
|
|
|
24
22
|
const Group = ({
|
|
25
23
|
title,
|
|
26
|
-
variant
|
|
24
|
+
variant,
|
|
27
25
|
auxiliaryText,
|
|
28
26
|
selectionVariant,
|
|
29
|
-
role,
|
|
30
27
|
sx = {},
|
|
31
28
|
...props
|
|
32
29
|
}) => {
|
|
33
|
-
const labelId = (0, _ssr.useSSRSafeId)();
|
|
34
30
|
return /*#__PURE__*/_react.default.createElement(_Box.default, _extends({
|
|
35
31
|
as: "li",
|
|
36
32
|
sx: {
|
|
@@ -41,11 +37,10 @@ const Group = ({
|
|
|
41
37
|
// hide the ::marker inserted by browser's stylesheet
|
|
42
38
|
...sx
|
|
43
39
|
}
|
|
44
|
-
}, props), title && /*#__PURE__*/_react.default.createElement(Header, {
|
|
40
|
+
}, props), title && /*#__PURE__*/_react.default.createElement(_Header.Header, {
|
|
45
41
|
title: title,
|
|
46
42
|
variant: variant,
|
|
47
|
-
auxiliaryText: auxiliaryText
|
|
48
|
-
labelId: labelId
|
|
43
|
+
auxiliaryText: auxiliaryText
|
|
49
44
|
}), /*#__PURE__*/_react.default.createElement(GroupContext.Provider, {
|
|
50
45
|
value: {
|
|
51
46
|
selectionVariant
|
|
@@ -54,53 +49,9 @@ const Group = ({
|
|
|
54
49
|
as: "ul",
|
|
55
50
|
sx: {
|
|
56
51
|
paddingInlineStart: 0
|
|
57
|
-
}
|
|
58
|
-
"aria-labelledby": title ? labelId : undefined,
|
|
59
|
-
role: role
|
|
52
|
+
}
|
|
60
53
|
}, props.children)));
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
exports.Group = Group;
|
|
64
|
-
Group.displayName = "Group";
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Displays the name and description of a `Group`.
|
|
68
|
-
*
|
|
69
|
-
* For visual presentation only. It's hidden from screen readers.
|
|
70
|
-
*/
|
|
71
|
-
const Header = ({
|
|
72
|
-
variant,
|
|
73
|
-
title,
|
|
74
|
-
auxiliaryText,
|
|
75
|
-
labelId,
|
|
76
|
-
...props
|
|
77
|
-
}) => {
|
|
78
|
-
const {
|
|
79
|
-
variant: listVariant
|
|
80
|
-
} = _react.default.useContext(_List.ListContext);
|
|
81
|
-
|
|
82
|
-
const styles = {
|
|
83
|
-
paddingY: '6px',
|
|
84
|
-
paddingX: listVariant === 'full' ? 2 : 3,
|
|
85
|
-
fontSize: 0,
|
|
86
|
-
fontWeight: 'bold',
|
|
87
|
-
color: 'fg.muted',
|
|
88
|
-
...(variant === 'filled' && {
|
|
89
|
-
backgroundColor: 'canvas.subtle',
|
|
90
|
-
marginX: 0,
|
|
91
|
-
marginBottom: 2,
|
|
92
|
-
borderTop: '1px solid',
|
|
93
|
-
borderBottom: '1px solid',
|
|
94
|
-
borderColor: 'neutral.muted'
|
|
95
|
-
})
|
|
96
|
-
};
|
|
97
|
-
return /*#__PURE__*/_react.default.createElement(_Box.default, _extends({
|
|
98
|
-
sx: styles,
|
|
99
|
-
role: "presentation",
|
|
100
|
-
"aria-hidden": "true"
|
|
101
|
-
}, props), /*#__PURE__*/_react.default.createElement("span", {
|
|
102
|
-
id: labelId
|
|
103
|
-
}, title), auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null, auxiliaryText));
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
Header.displayName = "Header";
|
|
57
|
+
Group.displayName = "Group";
|
|
@@ -5,50 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Group = exports.GroupContext = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const ssr_1 = require("@react-aria/ssr");
|
|
9
8
|
const Box_1 = __importDefault(require("../Box"));
|
|
10
|
-
const
|
|
9
|
+
const Header_1 = require("./Header");
|
|
11
10
|
exports.GroupContext = react_1.default.createContext({});
|
|
12
|
-
const Group = ({ title, variant
|
|
13
|
-
const labelId = ssr_1.useSSRSafeId();
|
|
11
|
+
const Group = ({ title, variant, auxiliaryText, selectionVariant, sx = {}, ...props }) => {
|
|
14
12
|
return (<Box_1.default as="li" sx={{
|
|
15
13
|
'&:not(:first-child)': { marginTop: 2 },
|
|
16
14
|
listStyle: 'none',
|
|
17
15
|
...sx
|
|
18
16
|
}} {...props}>
|
|
19
|
-
{title && <Header title={title} variant={variant} auxiliaryText={auxiliaryText}
|
|
17
|
+
{title && <Header_1.Header title={title} variant={variant} auxiliaryText={auxiliaryText}/>}
|
|
20
18
|
<exports.GroupContext.Provider value={{ selectionVariant }}>
|
|
21
|
-
<Box_1.default as="ul" sx={{ paddingInlineStart: 0 }}
|
|
19
|
+
<Box_1.default as="ul" sx={{ paddingInlineStart: 0 }}>
|
|
22
20
|
{props.children}
|
|
23
21
|
</Box_1.default>
|
|
24
22
|
</exports.GroupContext.Provider>
|
|
25
23
|
</Box_1.default>);
|
|
26
24
|
};
|
|
27
25
|
exports.Group = Group;
|
|
28
|
-
/**
|
|
29
|
-
* Displays the name and description of a `Group`.
|
|
30
|
-
*
|
|
31
|
-
* For visual presentation only. It's hidden from screen readers.
|
|
32
|
-
*/
|
|
33
|
-
const Header = ({ variant, title, auxiliaryText, labelId, ...props }) => {
|
|
34
|
-
const { variant: listVariant } = react_1.default.useContext(List_1.ListContext);
|
|
35
|
-
const styles = {
|
|
36
|
-
paddingY: '6px',
|
|
37
|
-
paddingX: listVariant === 'full' ? 2 : 3,
|
|
38
|
-
fontSize: 0,
|
|
39
|
-
fontWeight: 'bold',
|
|
40
|
-
color: 'fg.muted',
|
|
41
|
-
...(variant === 'filled' && {
|
|
42
|
-
backgroundColor: 'canvas.subtle',
|
|
43
|
-
marginX: 0,
|
|
44
|
-
marginBottom: 2,
|
|
45
|
-
borderTop: '1px solid',
|
|
46
|
-
borderBottom: '1px solid',
|
|
47
|
-
borderColor: 'neutral.muted'
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
return (<Box_1.default sx={styles} role="presentation" aria-hidden="true" {...props}>
|
|
51
|
-
<span id={labelId}>{title}</span>
|
|
52
|
-
{auxiliaryText && <span>{auxiliaryText}</span>}
|
|
53
|
-
</Box_1.default>);
|
|
54
|
-
};
|
package/lib/ActionList2/Item.js
CHANGED
|
@@ -21,6 +21,8 @@ var _createSlots = _interopRequireDefault(require("../utils/create-slots"));
|
|
|
21
21
|
|
|
22
22
|
var _List = require("./List");
|
|
23
23
|
|
|
24
|
+
var _ActionMenu = require("../ActionMenu2");
|
|
25
|
+
|
|
24
26
|
var _Selection = require("./Selection");
|
|
25
27
|
|
|
26
28
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -82,6 +84,7 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
82
84
|
onSelect = () => null,
|
|
83
85
|
sx: sxProp = {},
|
|
84
86
|
id,
|
|
87
|
+
role,
|
|
85
88
|
_PrivateItemWrapper,
|
|
86
89
|
...props
|
|
87
90
|
}, forwardedRef) => {
|
|
@@ -90,6 +93,11 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
90
93
|
showDividers
|
|
91
94
|
} = _react.default.useContext(_List.ListContext);
|
|
92
95
|
|
|
96
|
+
const {
|
|
97
|
+
itemRole,
|
|
98
|
+
onClose: onMenuClose
|
|
99
|
+
} = _react.default.useContext(_ActionMenu.MenuContext);
|
|
100
|
+
|
|
93
101
|
const {
|
|
94
102
|
theme
|
|
95
103
|
} = (0, _ThemeProvider.useTheme)();
|
|
@@ -165,16 +173,23 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
165
173
|
|
|
166
174
|
const clickHandler = _react.default.useCallback(event => {
|
|
167
175
|
if (disabled) return;
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
|
|
177
|
+
if (!event.defaultPrevented) {
|
|
178
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
|
179
|
+
|
|
180
|
+
if (typeof onMenuClose === 'function') onMenuClose();
|
|
181
|
+
}
|
|
182
|
+
}, [onSelect, disabled, onMenuClose]);
|
|
170
183
|
|
|
171
184
|
const keyPressHandler = _react.default.useCallback(event => {
|
|
172
185
|
if (disabled) return;
|
|
173
186
|
|
|
174
187
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
|
175
|
-
onSelect(event);
|
|
188
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
|
189
|
+
|
|
190
|
+
if (typeof onMenuClose === 'function') onMenuClose();
|
|
176
191
|
}
|
|
177
|
-
}, [onSelect, disabled]); // use props.id if provided, otherwise generate one.
|
|
192
|
+
}, [onSelect, disabled, onMenuClose]); // use props.id if provided, otherwise generate one.
|
|
178
193
|
|
|
179
194
|
|
|
180
195
|
const labelId = (0, _ssr.useSSRSafeId)(id);
|
|
@@ -197,7 +212,8 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
197
212
|
"aria-disabled": disabled ? true : undefined,
|
|
198
213
|
tabIndex: disabled || _PrivateItemWrapper ? undefined : 0,
|
|
199
214
|
"aria-labelledby": `${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`,
|
|
200
|
-
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined
|
|
215
|
+
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined,
|
|
216
|
+
role: role || itemRole
|
|
201
217
|
}, props), /*#__PURE__*/_react.default.createElement(ItemWrapper, null, /*#__PURE__*/_react.default.createElement(_Selection.Selection, {
|
|
202
218
|
selected: selected,
|
|
203
219
|
disabled: disabled
|
package/lib/ActionList2/Item.jsx
CHANGED
|
@@ -31,6 +31,7 @@ const Box_1 = __importDefault(require("../Box"));
|
|
|
31
31
|
const sx_1 = __importStar(require("../sx"));
|
|
32
32
|
const create_slots_1 = __importDefault(require("../utils/create-slots"));
|
|
33
33
|
const List_1 = require("./List");
|
|
34
|
+
const ActionMenu2_1 = require("../ActionMenu2");
|
|
34
35
|
const Selection_1 = require("./Selection");
|
|
35
36
|
const getVariantStyles = (variant, disabled) => {
|
|
36
37
|
if (disabled) {
|
|
@@ -62,8 +63,9 @@ const { Slots, Slot } = create_slots_1.default(['LeadingVisual', 'InlineDescript
|
|
|
62
63
|
exports.Slot = Slot;
|
|
63
64
|
const LiBox = styled_components_1.default.li(sx_1.default);
|
|
64
65
|
exports.TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
|
65
|
-
exports.Item = react_1.default.forwardRef(({ variant = 'default', disabled = false, selected = undefined, onSelect = () => null, sx: sxProp = {}, id, _PrivateItemWrapper, ...props }, forwardedRef) => {
|
|
66
|
+
exports.Item = react_1.default.forwardRef(({ variant = 'default', disabled = false, selected = undefined, onSelect = () => null, sx: sxProp = {}, id, role, _PrivateItemWrapper, ...props }, forwardedRef) => {
|
|
66
67
|
const { variant: listVariant, showDividers } = react_1.default.useContext(List_1.ListContext);
|
|
68
|
+
const { itemRole, onClose: onMenuClose } = react_1.default.useContext(ActionMenu2_1.MenuContext);
|
|
67
69
|
const { theme } = ThemeProvider_1.useTheme();
|
|
68
70
|
const styles = {
|
|
69
71
|
display: 'flex',
|
|
@@ -128,23 +130,30 @@ exports.Item = react_1.default.forwardRef(({ variant = 'default', disabled = fal
|
|
|
128
130
|
const clickHandler = react_1.default.useCallback(event => {
|
|
129
131
|
if (disabled)
|
|
130
132
|
return;
|
|
131
|
-
if (!event.defaultPrevented)
|
|
133
|
+
if (!event.defaultPrevented) {
|
|
132
134
|
onSelect(event);
|
|
133
|
-
|
|
135
|
+
// if this Item is inside a Menu, close the Menu
|
|
136
|
+
if (typeof onMenuClose === 'function')
|
|
137
|
+
onMenuClose();
|
|
138
|
+
}
|
|
139
|
+
}, [onSelect, disabled, onMenuClose]);
|
|
134
140
|
const keyPressHandler = react_1.default.useCallback(event => {
|
|
135
141
|
if (disabled)
|
|
136
142
|
return;
|
|
137
143
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
|
138
144
|
onSelect(event);
|
|
145
|
+
// if this Item is inside a Menu, close the Menu
|
|
146
|
+
if (typeof onMenuClose === 'function')
|
|
147
|
+
onMenuClose();
|
|
139
148
|
}
|
|
140
|
-
}, [onSelect, disabled]);
|
|
149
|
+
}, [onSelect, disabled, onMenuClose]);
|
|
141
150
|
// use props.id if provided, otherwise generate one.
|
|
142
151
|
const labelId = ssr_1.useSSRSafeId(id);
|
|
143
152
|
const inlineDescriptionId = ssr_1.useSSRSafeId(id && `${id}--inline-description`);
|
|
144
153
|
const blockDescriptionId = ssr_1.useSSRSafeId(id && `${id}--block-description`);
|
|
145
154
|
const ItemWrapper = _PrivateItemWrapper || react_1.default.Fragment;
|
|
146
155
|
return (<Slots context={{ variant, disabled, inlineDescriptionId, blockDescriptionId }}>
|
|
147
|
-
{slots => (<LiBox ref={forwardedRef} sx={sx_1.merge(styles, sxProp)} onClick={clickHandler} onKeyPress={keyPressHandler} aria-selected={selected} aria-disabled={disabled ? true : undefined} tabIndex={disabled || _PrivateItemWrapper ? undefined : 0} aria-labelledby={`${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`} aria-describedby={slots.BlockDescription ? blockDescriptionId : undefined} {...props}>
|
|
156
|
+
{slots => (<LiBox ref={forwardedRef} sx={sx_1.merge(styles, sxProp)} onClick={clickHandler} onKeyPress={keyPressHandler} aria-selected={selected} aria-disabled={disabled ? true : undefined} tabIndex={disabled || _PrivateItemWrapper ? undefined : 0} aria-labelledby={`${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`} aria-describedby={slots.BlockDescription ? blockDescriptionId : undefined} role={role || itemRole} {...props}>
|
|
148
157
|
<ItemWrapper>
|
|
149
158
|
<Selection_1.Selection selected={selected} disabled={disabled}/>
|
|
150
159
|
{slots.LeadingVisual}
|
|
@@ -20,7 +20,7 @@ export declare type ListProps = {
|
|
|
20
20
|
*/
|
|
21
21
|
role?: AriaRole;
|
|
22
22
|
} & SxProp;
|
|
23
|
-
declare type ContextProps =
|
|
23
|
+
declare type ContextProps = Omit<ListProps, 'sx'>;
|
|
24
24
|
export declare const ListContext: React.Context<ContextProps>;
|
|
25
25
|
export declare const List: PolymorphicForwardRefComponent<"ul", ListProps>;
|
|
26
26
|
export {};
|
package/lib/ActionList2/List.js
CHANGED
|
@@ -11,6 +11,8 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
|
11
11
|
|
|
12
12
|
var _sx = _interopRequireWildcard(require("../sx"));
|
|
13
13
|
|
|
14
|
+
var _ActionMenu = require("../ActionMenu2");
|
|
15
|
+
|
|
14
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
17
|
|
|
16
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -32,6 +34,7 @@ const List = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
32
34
|
variant = 'inset',
|
|
33
35
|
selectionVariant,
|
|
34
36
|
showDividers = false,
|
|
37
|
+
role,
|
|
35
38
|
sx: sxProp = {},
|
|
36
39
|
...props
|
|
37
40
|
}, forwardedRef) => {
|
|
@@ -41,9 +44,16 @@ const List = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
41
44
|
// reset ul styles
|
|
42
45
|
paddingY: variant === 'inset' ? 2 : 0
|
|
43
46
|
};
|
|
47
|
+
/** if list is inside a Menu, it will get a role from the Menu */
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
listRole
|
|
51
|
+
} = _react.default.useContext(_ActionMenu.MenuContext);
|
|
52
|
+
|
|
44
53
|
return /*#__PURE__*/_react.default.createElement(ListBox, _extends({
|
|
45
54
|
sx: (0, _sx.merge)(styles, sxProp),
|
|
46
|
-
"aria-multiselectable": selectionVariant === 'multiple' ? true : undefined
|
|
55
|
+
"aria-multiselectable": selectionVariant === 'multiple' ? true : undefined,
|
|
56
|
+
role: role || listRole
|
|
47
57
|
}, props, {
|
|
48
58
|
ref: forwardedRef
|
|
49
59
|
}), /*#__PURE__*/_react.default.createElement(ListContext.Provider, {
|
package/lib/ActionList2/List.jsx
CHANGED
|
@@ -26,15 +26,18 @@ exports.List = exports.ListContext = void 0;
|
|
|
26
26
|
const react_1 = __importDefault(require("react"));
|
|
27
27
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
28
28
|
const sx_1 = __importStar(require("../sx"));
|
|
29
|
+
const ActionMenu2_1 = require("../ActionMenu2");
|
|
29
30
|
exports.ListContext = react_1.default.createContext({});
|
|
30
31
|
const ListBox = styled_components_1.default.ul(sx_1.default);
|
|
31
|
-
exports.List = react_1.default.forwardRef(({ variant = 'inset', selectionVariant, showDividers = false, sx: sxProp = {}, ...props }, forwardedRef) => {
|
|
32
|
+
exports.List = react_1.default.forwardRef(({ variant = 'inset', selectionVariant, showDividers = false, role, sx: sxProp = {}, ...props }, forwardedRef) => {
|
|
32
33
|
const styles = {
|
|
33
34
|
margin: 0,
|
|
34
35
|
paddingInlineStart: 0,
|
|
35
36
|
paddingY: variant === 'inset' ? 2 : 0
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
/** if list is inside a Menu, it will get a role from the Menu */
|
|
39
|
+
const { listRole } = react_1.default.useContext(ActionMenu2_1.MenuContext);
|
|
40
|
+
return (<ListBox sx={sx_1.merge(styles, sxProp)} aria-multiselectable={selectionVariant === 'multiple' ? true : undefined} role={role || listRole} {...props} ref={forwardedRef}>
|
|
38
41
|
<exports.ListContext.Provider value={{ variant, selectionVariant, showDividers }}>{props.children}</exports.ListContext.Provider>
|
|
39
42
|
</ListBox>);
|
|
40
43
|
});
|
|
@@ -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. */
|