@primer/components 0.0.0-20211030113431 → 0.0.0-2021103011479
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/Header.d.ts +26 -0
- package/lib/ActionList2/Header.js +55 -0
- package/lib/ActionList2/Item.js +22 -8
- 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 +309 -0
- package/lib/ActionMenu2.js +91 -0
- package/lib/Autocomplete/Autocomplete.d.ts +0 -1
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -1
- package/lib/Button/Button.d.ts +0 -1
- package/lib/Button/ButtonClose.d.ts +1 -2
- package/lib/Button/ButtonDanger.d.ts +0 -1
- package/lib/Button/ButtonInvisible.d.ts +0 -1
- package/lib/Button/ButtonOutline.d.ts +0 -1
- package/lib/Button/ButtonPrimary.d.ts +0 -1
- package/lib/CircleOcticon.d.ts +0 -1
- package/lib/Dialog.d.ts +2 -3
- package/lib/Dropdown.d.ts +0 -4
- package/lib/DropdownMenu/DropdownButton.d.ts +1 -2
- package/lib/FilterList.d.ts +0 -1
- package/lib/Position.d.ts +4 -4
- package/lib/SelectMenu/SelectMenu.d.ts +4 -10
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +0 -1
- 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 +13 -0
- package/lib/utils/testing.d.ts +20 -0
- package/lib/utils/testing.js +1 -1
- package/lib-esm/ActionList2/Divider.d.ts +3 -2
- package/lib-esm/ActionList2/Divider.js +8 -5
- package/lib-esm/ActionList2/Header.d.ts +26 -0
- package/lib-esm/ActionList2/Header.js +44 -0
- package/lib-esm/ActionList2/Item.js +20 -8
- 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 +309 -0
- package/lib-esm/ActionMenu2.js +67 -0
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -1
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -1
- package/lib-esm/Button/Button.d.ts +0 -1
- package/lib-esm/Button/ButtonClose.d.ts +1 -2
- package/lib-esm/Button/ButtonDanger.d.ts +0 -1
- package/lib-esm/Button/ButtonInvisible.d.ts +0 -1
- package/lib-esm/Button/ButtonOutline.d.ts +0 -1
- package/lib-esm/Button/ButtonPrimary.d.ts +0 -1
- package/lib-esm/CircleOcticon.d.ts +0 -1
- package/lib-esm/Dialog.d.ts +2 -3
- package/lib-esm/Dropdown.d.ts +0 -4
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +1 -2
- package/lib-esm/FilterList.d.ts +0 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -10
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +0 -1
- 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/lib-esm/utils/testing.d.ts +20 -0
- package/lib-esm/utils/testing.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# @primer/components
|
2
2
|
|
3
|
-
## 0.0.0-
|
3
|
+
## 0.0.0-2021103011479
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
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`
|
4
8
|
|
5
9
|
### Patch Changes
|
6
10
|
|
@@ -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";
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { SxProp } from '../sx';
|
3
|
+
/**
|
4
|
+
* Contract for props passed to the `Header` component.
|
5
|
+
*/
|
6
|
+
export declare type HeaderProps = {
|
7
|
+
/**
|
8
|
+
* Style variations. Usage is discretionary.
|
9
|
+
*
|
10
|
+
* - `"filled"` - Superimposed on a background, offset from nearby content
|
11
|
+
* - `"subtle"` - Relatively less offset from nearby content
|
12
|
+
*/
|
13
|
+
variant?: 'subtle' | 'filled';
|
14
|
+
/**
|
15
|
+
* Primary text which names a `Group`.
|
16
|
+
*/
|
17
|
+
title?: string;
|
18
|
+
/**
|
19
|
+
* Secondary text which provides additional information about a `Group`.
|
20
|
+
*/
|
21
|
+
auxiliaryText?: string;
|
22
|
+
} & SxProp;
|
23
|
+
/**
|
24
|
+
* Displays the name and description of a `Group`.
|
25
|
+
*/
|
26
|
+
export declare const Header: ({ variant, title, auxiliaryText, sx, ...props }: HeaderProps) => JSX.Element;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Header = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
|
10
|
+
var _Box = _interopRequireDefault(require("../Box"));
|
11
|
+
|
12
|
+
var _List = require("./List");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Displays the name and description of a `Group`.
|
20
|
+
*/
|
21
|
+
const Header = ({
|
22
|
+
variant = 'subtle',
|
23
|
+
title,
|
24
|
+
auxiliaryText,
|
25
|
+
sx = {},
|
26
|
+
...props
|
27
|
+
}) => {
|
28
|
+
const {
|
29
|
+
variant: listVariant
|
30
|
+
} = _react.default.useContext(_List.ListContext);
|
31
|
+
|
32
|
+
const styles = {
|
33
|
+
paddingY: '6px',
|
34
|
+
paddingX: listVariant === 'full' ? 2 : 3,
|
35
|
+
fontSize: 0,
|
36
|
+
fontWeight: 'bold',
|
37
|
+
color: 'fg.muted',
|
38
|
+
...(variant === 'filled' && {
|
39
|
+
backgroundColor: 'canvas.subtle',
|
40
|
+
marginX: 0,
|
41
|
+
marginBottom: 2,
|
42
|
+
borderTop: '1px solid',
|
43
|
+
borderBottom: '1px solid',
|
44
|
+
borderColor: 'neutral.muted'
|
45
|
+
}),
|
46
|
+
...sx
|
47
|
+
};
|
48
|
+
return /*#__PURE__*/_react.default.createElement(_Box.default, _extends({
|
49
|
+
sx: styles,
|
50
|
+
role: "heading"
|
51
|
+
}, props), title, auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null, auxiliaryText));
|
52
|
+
};
|
53
|
+
|
54
|
+
exports.Header = Header;
|
55
|
+
Header.displayName = "Header";
|
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 _MenuContext = require("./MenuContext");
|
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); }
|
@@ -79,9 +81,10 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
79
81
|
variant = 'default',
|
80
82
|
disabled = false,
|
81
83
|
selected = undefined,
|
82
|
-
onSelect,
|
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
|
+
afterSelect
|
99
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
100
|
+
|
93
101
|
const {
|
94
102
|
theme
|
95
103
|
} = (0, _ThemeProvider.useTheme)();
|
@@ -163,19 +171,24 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
163
171
|
};
|
164
172
|
|
165
173
|
const clickHandler = _react.default.useCallback(event => {
|
166
|
-
if (typeof onSelect !== 'function') return;
|
167
174
|
if (disabled) return;
|
168
|
-
|
169
|
-
|
175
|
+
|
176
|
+
if (!event.defaultPrevented) {
|
177
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
178
|
+
|
179
|
+
if (typeof afterSelect === 'function') afterSelect();
|
180
|
+
}
|
181
|
+
}, [onSelect, disabled, afterSelect]);
|
170
182
|
|
171
183
|
const keyPressHandler = _react.default.useCallback(event => {
|
172
|
-
if (typeof onSelect !== 'function') return;
|
173
184
|
if (disabled) return;
|
174
185
|
|
175
186
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
176
|
-
onSelect(event);
|
187
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
188
|
+
|
189
|
+
if (typeof afterSelect === 'function') afterSelect();
|
177
190
|
}
|
178
|
-
}, [onSelect, disabled]); // use props.id if provided, otherwise generate one.
|
191
|
+
}, [onSelect, disabled, afterSelect]); // use props.id if provided, otherwise generate one.
|
179
192
|
|
180
193
|
|
181
194
|
const labelId = (0, _ssr.useSSRSafeId)(id);
|
@@ -198,7 +211,8 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
198
211
|
"aria-disabled": disabled ? true : undefined,
|
199
212
|
tabIndex: disabled || _PrivateItemWrapper ? undefined : 0,
|
200
213
|
"aria-labelledby": `${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`,
|
201
|
-
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined
|
214
|
+
"aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined,
|
215
|
+
role: role || itemRole
|
202
216
|
}, props), /*#__PURE__*/_react.default.createElement(ItemWrapper, null, /*#__PURE__*/_react.default.createElement(_Selection.Selection, {
|
203
217
|
selected: selected
|
204
218
|
}), slots.LeadingVisual, /*#__PURE__*/_react.default.createElement(_Box.default, {
|
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 _MenuContext = require("./MenuContext");
|
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,8 +44,15 @@ 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(_MenuContext.MenuContext);
|
52
|
+
|
44
53
|
return /*#__PURE__*/_react.default.createElement(ListBox, _extends({
|
45
|
-
sx: (0, _sx.merge)(styles, sxProp)
|
54
|
+
sx: (0, _sx.merge)(styles, sxProp),
|
55
|
+
role: role || listRole
|
46
56
|
}, props, {
|
47
57
|
ref: forwardedRef
|
48
58
|
}), /*#__PURE__*/_react.default.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 {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.MenuContext = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
/** This context can be used by components that compose ActionList inside a Menu */
|
13
|
+
const MenuContext = /*#__PURE__*/_react.default.createContext({});
|
14
|
+
|
15
|
+
exports.MenuContext = MenuContext;
|
@@ -13,6 +13,8 @@ var _List = require("./List");
|
|
13
13
|
|
14
14
|
var _Group = require("./Group");
|
15
15
|
|
16
|
+
var _MenuContext = require("./MenuContext");
|
17
|
+
|
16
18
|
var _Visuals = require("./Visuals");
|
17
19
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -27,6 +29,10 @@ const Selection = ({
|
|
27
29
|
const {
|
28
30
|
selectionVariant: groupSelectionVariant
|
29
31
|
} = _react.default.useContext(_Group.GroupContext);
|
32
|
+
|
33
|
+
const {
|
34
|
+
parent
|
35
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
30
36
|
/** selectionVariant in Group can override the selectionVariant in List root */
|
31
37
|
|
32
38
|
|
@@ -38,6 +44,11 @@ const Selection = ({
|
|
38
44
|
return null;
|
39
45
|
}
|
40
46
|
|
47
|
+
if (parent === 'ActionMenu') {
|
48
|
+
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');
|
49
|
+
return null;
|
50
|
+
}
|
51
|
+
|
41
52
|
if (selectionVariant === 'single') {
|
42
53
|
return /*#__PURE__*/_react.default.createElement(_Visuals.LeadingVisualContainer, null, selected && /*#__PURE__*/_react.default.createElement(_octiconsReact.CheckIcon, null));
|
43
54
|
}
|
@@ -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. */
|