@primer/components 0.0.0-202111613539 → 0.0.0-202111613730
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/browser.esm.js +2 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +2 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList2/Item.js +6 -4
- package/lib/ActionList2/List.js +2 -2
- package/lib/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
- package/lib/ActionList2/{ActionListContainerContext.js → MenuContext.js} +3 -3
- package/lib/ActionList2/Selection.js +4 -4
- package/lib/ActionMenu2.d.ts +9 -13
- package/lib/ActionMenu2.js +29 -63
- package/lib/Checkbox.d.ts +1 -1
- package/lib/Radio.d.ts +38 -0
- package/lib/Radio.js +55 -0
- package/lib/hooks/index.d.ts +0 -1
- package/lib/hooks/index.js +1 -9
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib-esm/ActionList2/Item.js +6 -4
- package/lib-esm/ActionList2/List.js +2 -2
- package/lib-esm/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
- package/lib-esm/ActionList2/{ActionListContainerContext.js → MenuContext.js} +1 -1
- package/lib-esm/ActionList2/Selection.js +4 -4
- package/lib-esm/ActionMenu2.d.ts +9 -13
- package/lib-esm/ActionMenu2.js +27 -60
- package/lib-esm/Checkbox.d.ts +1 -1
- package/lib-esm/Radio.d.ts +38 -0
- package/lib-esm/Radio.js +40 -0
- package/lib-esm/hooks/index.d.ts +0 -1
- package/lib-esm/hooks/index.js +1 -2
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +1 -0
- package/package.json +1 -1
package/lib/ActionList2/Item.js
CHANGED
@@ -21,7 +21,7 @@ var _createSlots = _interopRequireDefault(require("../utils/create-slots"));
|
|
21
21
|
|
22
22
|
var _List = require("./List");
|
23
23
|
|
24
|
-
var
|
24
|
+
var _MenuContext = require("./MenuContext");
|
25
25
|
|
26
26
|
var _Selection = require("./Selection");
|
27
27
|
|
@@ -96,7 +96,7 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
96
96
|
const {
|
97
97
|
itemRole,
|
98
98
|
afterSelect
|
99
|
-
} = _react.default.useContext(
|
99
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
100
100
|
|
101
101
|
const {
|
102
102
|
theme
|
@@ -171,20 +171,22 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
171
171
|
};
|
172
172
|
|
173
173
|
const clickHandler = _react.default.useCallback(event => {
|
174
|
+
if (typeof onSelect !== 'function') return;
|
174
175
|
if (disabled) return;
|
175
176
|
|
176
177
|
if (!event.defaultPrevented) {
|
177
|
-
|
178
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
178
179
|
|
179
180
|
if (typeof afterSelect === 'function') afterSelect();
|
180
181
|
}
|
181
182
|
}, [onSelect, disabled, afterSelect]);
|
182
183
|
|
183
184
|
const keyPressHandler = _react.default.useCallback(event => {
|
185
|
+
if (typeof onSelect !== 'function') return;
|
184
186
|
if (disabled) return;
|
185
187
|
|
186
188
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
187
|
-
|
189
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
188
190
|
|
189
191
|
if (typeof afterSelect === 'function') afterSelect();
|
190
192
|
}
|
package/lib/ActionList2/List.js
CHANGED
@@ -11,7 +11,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
11
|
|
12
12
|
var _sx = _interopRequireWildcard(require("../sx"));
|
13
13
|
|
14
|
-
var
|
14
|
+
var _MenuContext = require("./MenuContext");
|
15
15
|
|
16
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); }
|
17
17
|
|
@@ -48,7 +48,7 @@ const List = /*#__PURE__*/_react.default.forwardRef(({
|
|
48
48
|
|
49
49
|
const {
|
50
50
|
listRole
|
51
|
-
} = _react.default.useContext(
|
51
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
52
52
|
|
53
53
|
return /*#__PURE__*/_react.default.createElement(ListBox, _extends({
|
54
54
|
sx: (0, _sx.merge)(styles, sxProp),
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/** This context can be used by components that compose ActionList inside a Menu */
|
2
2
|
import React from 'react';
|
3
3
|
declare type ContextProps = {
|
4
|
-
|
4
|
+
parent?: string;
|
5
5
|
listRole?: string;
|
6
6
|
itemRole?: string;
|
7
|
-
afterSelect?:
|
7
|
+
afterSelect?: () => void;
|
8
8
|
};
|
9
|
-
export declare const
|
9
|
+
export declare const MenuContext: React.Context<ContextProps>;
|
10
10
|
export {};
|
@@ -3,13 +3,13 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.MenuContext = void 0;
|
7
7
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
9
9
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
11
|
|
12
12
|
/** This context can be used by components that compose ActionList inside a Menu */
|
13
|
-
const
|
13
|
+
const MenuContext = /*#__PURE__*/_react.default.createContext({});
|
14
14
|
|
15
|
-
exports.
|
15
|
+
exports.MenuContext = MenuContext;
|
@@ -13,7 +13,7 @@ var _List = require("./List");
|
|
13
13
|
|
14
14
|
var _Group = require("./Group");
|
15
15
|
|
16
|
-
var
|
16
|
+
var _MenuContext = require("./MenuContext");
|
17
17
|
|
18
18
|
var _Visuals = require("./Visuals");
|
19
19
|
|
@@ -31,8 +31,8 @@ const Selection = ({
|
|
31
31
|
} = _react.default.useContext(_Group.GroupContext);
|
32
32
|
|
33
33
|
const {
|
34
|
-
|
35
|
-
} = _react.default.useContext(
|
34
|
+
parent
|
35
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
36
36
|
/** selectionVariant in Group can override the selectionVariant in List root */
|
37
37
|
|
38
38
|
|
@@ -44,7 +44,7 @@ const Selection = ({
|
|
44
44
|
return null;
|
45
45
|
}
|
46
46
|
|
47
|
-
if (
|
47
|
+
if (parent === 'ActionMenu') {
|
48
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
49
|
return null;
|
50
50
|
}
|
package/lib/ActionMenu2.d.ts
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import { ButtonProps } from './Button';
|
2
2
|
import React from 'react';
|
3
|
-
import { AnchoredOverlayProps } from './AnchoredOverlay';
|
4
3
|
import { OverlayProps } from './Overlay';
|
5
|
-
|
6
|
-
|
7
|
-
export declare type ActionMenuProps = {
|
4
|
+
import { AnchoredOverlayWrapperAnchorProps } from './AnchoredOverlay/AnchoredOverlay';
|
5
|
+
declare type ActionMenuBaseProps = {
|
8
6
|
/**
|
9
|
-
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with `
|
7
|
+
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with ActionList`
|
10
8
|
*/
|
11
9
|
children: React.ReactElement[] | React.ReactElement;
|
12
10
|
/**
|
@@ -17,18 +15,17 @@ export declare type ActionMenuProps = {
|
|
17
15
|
* If defined, will control the open/closed state of the overlay. Must be used in conjuction with `open`.
|
18
16
|
*/
|
19
17
|
onOpenChange?: (s: boolean) => void;
|
20
|
-
|
18
|
+
/**
|
19
|
+
* Props to be spread on the internal `Overlay` component.
|
20
|
+
*/
|
21
|
+
overlayProps?: Partial<OverlayProps>;
|
22
|
+
};
|
23
|
+
export declare type ActionMenuProps = ActionMenuBaseProps & AnchoredOverlayWrapperAnchorProps;
|
21
24
|
export declare type MenuAnchorProps = {
|
22
25
|
children: React.ReactElement;
|
23
26
|
};
|
24
27
|
/** this component is syntactical sugar 🍭 */
|
25
28
|
export declare type MenuButtonProps = ButtonProps;
|
26
|
-
declare type MenuOverlayProps = Partial<OverlayProps> & {
|
27
|
-
/**
|
28
|
-
* Recommended: `ActionList`
|
29
|
-
*/
|
30
|
-
children: React.ReactElement[] | React.ReactElement;
|
31
|
-
};
|
32
29
|
export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
33
30
|
Button: React.ForwardRefExoticComponent<Pick<{
|
34
31
|
color?: string | undefined;
|
@@ -311,7 +308,6 @@ export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
|
311
308
|
variant?: "small" | "medium" | "large" | undefined;
|
312
309
|
}> & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
313
310
|
Anchor: React.ForwardRefExoticComponent<MenuAnchorProps & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
314
|
-
Overlay: React.FC<MenuOverlayProps>;
|
315
311
|
Divider: React.FC<import("./sx").SxProp>;
|
316
312
|
};
|
317
313
|
export {};
|
package/lib/ActionMenu2.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.ActionMenu =
|
6
|
+
exports.ActionMenu = void 0;
|
7
7
|
|
8
8
|
var _Button = _interopRequireDefault(require("./Button"));
|
9
9
|
|
@@ -11,60 +11,59 @@ var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
12
12
|
var _AnchoredOverlay = require("./AnchoredOverlay");
|
13
13
|
|
14
|
+
var _useProvidedStateOrCreate = require("./hooks/useProvidedStateOrCreate");
|
15
|
+
|
14
16
|
var _hooks = require("./hooks");
|
15
17
|
|
16
18
|
var _Divider = require("./ActionList2/Divider");
|
17
19
|
|
18
|
-
var
|
20
|
+
var _MenuContext = require("./ActionList2/MenuContext");
|
19
21
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
23
|
|
22
|
-
const
|
23
|
-
renderAnchor: null,
|
24
|
-
open: false
|
25
|
-
});
|
26
|
-
|
27
|
-
exports.MenuContext = MenuContext;
|
28
|
-
|
29
|
-
const Menu = ({
|
24
|
+
const ActionMenuBase = ({
|
30
25
|
anchorRef: externalAnchorRef,
|
31
26
|
open,
|
32
27
|
onOpenChange,
|
28
|
+
overlayProps,
|
33
29
|
children
|
34
30
|
}) => {
|
35
|
-
const [combinedOpenState, setCombinedOpenState] = (0,
|
31
|
+
const [combinedOpenState, setCombinedOpenState] = (0, _useProvidedStateOrCreate.useProvidedStateOrCreate)(open, onOpenChange, false);
|
32
|
+
const anchorRef = (0, _hooks.useProvidedRefOrCreate)(externalAnchorRef);
|
36
33
|
|
37
34
|
const onOpen = _react.default.useCallback(() => setCombinedOpenState(true), [setCombinedOpenState]);
|
38
35
|
|
39
36
|
const onClose = _react.default.useCallback(() => setCombinedOpenState(false), [setCombinedOpenState]);
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
// we strip out Anchor from children and pass it to AnchoredOverlay to render
|
44
|
-
// with additional props for accessibility
|
38
|
+
let renderAnchor = null;
|
39
|
+
const contents = [];
|
45
40
|
|
46
|
-
|
41
|
+
_react.default.Children.map(children, child => {
|
47
42
|
if (child.type === MenuButton || child.type === Anchor) {
|
48
43
|
renderAnchor = anchorProps => /*#__PURE__*/_react.default.cloneElement(child, anchorProps);
|
49
|
-
|
50
|
-
|
44
|
+
} else {
|
45
|
+
contents.push(child);
|
51
46
|
}
|
52
|
-
|
53
|
-
return child;
|
54
47
|
});
|
55
48
|
|
56
|
-
return /*#__PURE__*/_react.default.createElement(
|
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
57
|
value: {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
onClose
|
58
|
+
parent: 'ActionMenu',
|
59
|
+
listRole: 'menu',
|
60
|
+
itemRole: 'menuitem',
|
61
|
+
afterSelect: onClose
|
63
62
|
}
|
64
|
-
}, contents);
|
63
|
+
}, contents));
|
65
64
|
};
|
66
65
|
|
67
|
-
|
66
|
+
ActionMenuBase.displayName = "ActionMenuBase";
|
68
67
|
|
69
68
|
const Anchor = /*#__PURE__*/_react.default.forwardRef(({
|
70
69
|
children,
|
@@ -83,43 +82,10 @@ const MenuButton = /*#__PURE__*/_react.default.forwardRef((props, anchorRef) =>
|
|
83
82
|
}, /*#__PURE__*/_react.default.createElement(_Button.default, props));
|
84
83
|
});
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
...overlayProps
|
89
|
-
}) => {
|
90
|
-
// we typecast anchorRef as required instead of optional
|
91
|
-
// because we know that we're setting it in context in Menu
|
92
|
-
const {
|
93
|
-
anchorRef,
|
94
|
-
renderAnchor,
|
95
|
-
open,
|
96
|
-
onOpen,
|
97
|
-
onClose
|
98
|
-
} = _react.default.useContext(MenuContext);
|
99
|
-
|
100
|
-
return /*#__PURE__*/_react.default.createElement(_AnchoredOverlay.AnchoredOverlay, {
|
101
|
-
anchorRef: anchorRef,
|
102
|
-
renderAnchor: renderAnchor,
|
103
|
-
open: open,
|
104
|
-
onOpen: onOpen,
|
105
|
-
onClose: onClose,
|
106
|
-
overlayProps: overlayProps
|
107
|
-
}, /*#__PURE__*/_react.default.createElement(_ActionListContainerContext.ActionListContainerContext.Provider, {
|
108
|
-
value: {
|
109
|
-
container: 'ActionMenu',
|
110
|
-
listRole: 'menu',
|
111
|
-
itemRole: 'menuitem',
|
112
|
-
afterSelect: onClose
|
113
|
-
}
|
114
|
-
}, children));
|
115
|
-
};
|
116
|
-
|
117
|
-
Overlay.displayName = "Overlay";
|
118
|
-
Menu.displayName = 'ActionMenu';
|
119
|
-
const ActionMenu = Object.assign(Menu, {
|
85
|
+
ActionMenuBase.displayName = 'ActionMenu';
|
86
|
+
const ActionMenu = Object.assign(ActionMenuBase, {
|
120
87
|
Button: MenuButton,
|
121
88
|
Anchor,
|
122
|
-
Overlay,
|
123
89
|
Divider: _Divider.Divider
|
124
90
|
});
|
125
91
|
exports.ActionMenu = ActionMenu;
|
package/lib/Checkbox.d.ts
CHANGED
@@ -25,5 +25,5 @@ export declare type CheckboxProps = {
|
|
25
25
|
/**
|
26
26
|
* An accessible, native checkbox component
|
27
27
|
*/
|
28
|
-
declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "
|
28
|
+
declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "validationStatus" | "indeterminate"> & React.RefAttributes<HTMLInputElement>>;
|
29
29
|
export default Checkbox;
|
package/lib/Radio.d.ts
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import React, { InputHTMLAttributes } from 'react';
|
2
|
+
import { SxProp } from './sx';
|
3
|
+
export declare type RadioProps = {
|
4
|
+
/**
|
5
|
+
* A unique value that is never shown to the user.
|
6
|
+
* Used during form submission and to identify which radio button in a group is selected
|
7
|
+
*/
|
8
|
+
value: string;
|
9
|
+
/**
|
10
|
+
* Name attribute of the input element. Required for grouping radio inputs
|
11
|
+
*/
|
12
|
+
name: string;
|
13
|
+
/**
|
14
|
+
* Apply inactive visual appearance to the radio button
|
15
|
+
*/
|
16
|
+
disabled?: boolean;
|
17
|
+
/**
|
18
|
+
* Indicates whether the radio button is selected
|
19
|
+
*/
|
20
|
+
checked?: boolean;
|
21
|
+
/**
|
22
|
+
* Forward a ref to the underlying input element
|
23
|
+
*/
|
24
|
+
ref?: React.RefObject<HTMLInputElement>;
|
25
|
+
/**
|
26
|
+
* Indicates whether the radio button must be checked before the form can be submitted
|
27
|
+
*/
|
28
|
+
required?: boolean;
|
29
|
+
/**
|
30
|
+
* Indicates whether the radio button validation state is non-standard
|
31
|
+
*/
|
32
|
+
validationStatus?: 'error' | 'success';
|
33
|
+
} & InputHTMLAttributes<HTMLInputElement> & SxProp;
|
34
|
+
/**
|
35
|
+
* An accessible, native radio component for selecting one option from a list.
|
36
|
+
*/
|
37
|
+
declare const Radio: React.ForwardRefExoticComponent<Pick<RadioProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "validationStatus"> & React.RefAttributes<HTMLInputElement>>;
|
38
|
+
export default Radio;
|
package/lib/Radio.js
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
9
|
+
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
11
|
+
|
12
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
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
|
+
const StyledRadio = _styledComponents.default.input.withConfig({
|
19
|
+
displayName: "Radio__StyledRadio",
|
20
|
+
componentId: "sc-1ak1fjg-0"
|
21
|
+
})(["cursor:pointer;", " ", ""], props => props.disabled && `cursor: not-allowed;`, _sx.default);
|
22
|
+
/**
|
23
|
+
* An accessible, native radio component for selecting one option from a list.
|
24
|
+
*/
|
25
|
+
|
26
|
+
|
27
|
+
const Radio = /*#__PURE__*/_react.default.forwardRef(({
|
28
|
+
checked,
|
29
|
+
disabled,
|
30
|
+
sx: sxProp,
|
31
|
+
required,
|
32
|
+
validationStatus,
|
33
|
+
value,
|
34
|
+
name,
|
35
|
+
...rest
|
36
|
+
}, ref) => {
|
37
|
+
return /*#__PURE__*/_react.default.createElement(StyledRadio, _extends({
|
38
|
+
type: "radio",
|
39
|
+
value: value,
|
40
|
+
name: name,
|
41
|
+
ref: ref,
|
42
|
+
disabled: disabled,
|
43
|
+
"aria-disabled": disabled ? 'true' : 'false',
|
44
|
+
checked: checked,
|
45
|
+
"aria-checked": checked ? 'true' : 'false',
|
46
|
+
required: required,
|
47
|
+
"aria-required": required ? 'true' : 'false',
|
48
|
+
"aria-invalid": validationStatus === 'error' ? 'true' : 'false',
|
49
|
+
sx: sxProp
|
50
|
+
}, rest));
|
51
|
+
});
|
52
|
+
|
53
|
+
Radio.displayName = 'Radio';
|
54
|
+
var _default = Radio;
|
55
|
+
exports.default = _default;
|
package/lib/hooks/index.d.ts
CHANGED
@@ -9,4 +9,3 @@ export { useAnchoredPosition } from './useAnchoredPosition';
|
|
9
9
|
export { useOverlay } from './useOverlay';
|
10
10
|
export type { UseOverlaySettings } from './useOverlay';
|
11
11
|
export { useRenderForcingRef } from './useRenderForcingRef';
|
12
|
-
export { useProvidedStateOrCreate } from './useProvidedStateOrCreate';
|
package/lib/hooks/index.js
CHANGED
@@ -45,12 +45,6 @@ Object.defineProperty(exports, "useRenderForcingRef", {
|
|
45
45
|
return _useRenderForcingRef.useRenderForcingRef;
|
46
46
|
}
|
47
47
|
});
|
48
|
-
Object.defineProperty(exports, "useProvidedStateOrCreate", {
|
49
|
-
enumerable: true,
|
50
|
-
get: function () {
|
51
|
-
return _useProvidedStateOrCreate.useProvidedStateOrCreate;
|
52
|
-
}
|
53
|
-
});
|
54
48
|
|
55
49
|
var _useOnOutsideClick = require("./useOnOutsideClick");
|
56
50
|
|
@@ -64,6 +58,4 @@ var _useAnchoredPosition = require("./useAnchoredPosition");
|
|
64
58
|
|
65
59
|
var _useOverlay = require("./useOverlay");
|
66
60
|
|
67
|
-
var _useRenderForcingRef = require("./useRenderForcingRef");
|
68
|
-
|
69
|
-
var _useProvidedStateOrCreate = require("./useProvidedStateOrCreate");
|
61
|
+
var _useRenderForcingRef = require("./useRenderForcingRef");
|
package/lib/index.d.ts
CHANGED
@@ -21,6 +21,8 @@ export { useOpenAndCloseFocus } from './hooks/useOpenAndCloseFocus';
|
|
21
21
|
export { useOnEscapePress } from './hooks/useOnEscapePress';
|
22
22
|
export { useOverlay } from './hooks/useOverlay';
|
23
23
|
export { useConfirm } from './Dialog/ConfirmationDialog';
|
24
|
+
export { default as Radio } from './Radio';
|
25
|
+
export type { RadioProps } from './Radio';
|
24
26
|
export { ActionList } from './ActionList';
|
25
27
|
export { ActionMenu } from './ActionMenu';
|
26
28
|
export type { ActionMenuProps } from './ActionMenu';
|
package/lib/index.js
CHANGED
@@ -141,6 +141,12 @@ Object.defineProperty(exports, "ConfirmationDialog", {
|
|
141
141
|
return _ConfirmationDialog.ConfirmationDialog;
|
142
142
|
}
|
143
143
|
});
|
144
|
+
Object.defineProperty(exports, "Radio", {
|
145
|
+
enumerable: true,
|
146
|
+
get: function () {
|
147
|
+
return _Radio.default;
|
148
|
+
}
|
149
|
+
});
|
144
150
|
Object.defineProperty(exports, "ActionList", {
|
145
151
|
enumerable: true,
|
146
152
|
get: function () {
|
@@ -546,6 +552,8 @@ var _useOverlay = require("./hooks/useOverlay");
|
|
546
552
|
|
547
553
|
var _ConfirmationDialog = require("./Dialog/ConfirmationDialog");
|
548
554
|
|
555
|
+
var _Radio = _interopRequireDefault(require("./Radio"));
|
556
|
+
|
549
557
|
var _ActionList = require("./ActionList");
|
550
558
|
|
551
559
|
var _ActionMenu = require("./ActionMenu");
|
@@ -8,7 +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 {
|
11
|
+
import { MenuContext } from './MenuContext';
|
12
12
|
import { Selection } from './Selection';
|
13
13
|
export const getVariantStyles = (variant, disabled) => {
|
14
14
|
if (disabled) {
|
@@ -66,7 +66,7 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
66
66
|
const {
|
67
67
|
itemRole,
|
68
68
|
afterSelect
|
69
|
-
} = React.useContext(
|
69
|
+
} = React.useContext(MenuContext);
|
70
70
|
const {
|
71
71
|
theme
|
72
72
|
} = useTheme();
|
@@ -139,19 +139,21 @@ export const Item = /*#__PURE__*/React.forwardRef(({
|
|
139
139
|
}
|
140
140
|
};
|
141
141
|
const clickHandler = React.useCallback(event => {
|
142
|
+
if (typeof onSelect !== 'function') return;
|
142
143
|
if (disabled) return;
|
143
144
|
|
144
145
|
if (!event.defaultPrevented) {
|
145
|
-
|
146
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
146
147
|
|
147
148
|
if (typeof afterSelect === 'function') afterSelect();
|
148
149
|
}
|
149
150
|
}, [onSelect, disabled, afterSelect]);
|
150
151
|
const keyPressHandler = React.useCallback(event => {
|
152
|
+
if (typeof onSelect !== 'function') return;
|
151
153
|
if (disabled) return;
|
152
154
|
|
153
155
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
154
|
-
|
156
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
155
157
|
|
156
158
|
if (typeof afterSelect === 'function') afterSelect();
|
157
159
|
}
|
@@ -3,7 +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 {
|
6
|
+
import { MenuContext } from './MenuContext';
|
7
7
|
export const ListContext = /*#__PURE__*/React.createContext({});
|
8
8
|
const ListBox = styled.ul.withConfig({
|
9
9
|
displayName: "List__ListBox",
|
@@ -27,7 +27,7 @@ export const List = /*#__PURE__*/React.forwardRef(({
|
|
27
27
|
|
28
28
|
const {
|
29
29
|
listRole
|
30
|
-
} = React.useContext(
|
30
|
+
} = React.useContext(MenuContext);
|
31
31
|
return /*#__PURE__*/React.createElement(ListBox, _extends({
|
32
32
|
sx: merge(styles, sxProp),
|
33
33
|
role: role || listRole
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/** This context can be used by components that compose ActionList inside a Menu */
|
2
2
|
import React from 'react';
|
3
3
|
declare type ContextProps = {
|
4
|
-
|
4
|
+
parent?: string;
|
5
5
|
listRole?: string;
|
6
6
|
itemRole?: string;
|
7
|
-
afterSelect?:
|
7
|
+
afterSelect?: () => void;
|
8
8
|
};
|
9
|
-
export declare const
|
9
|
+
export declare const MenuContext: React.Context<ContextProps>;
|
10
10
|
export {};
|
@@ -2,7 +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 {
|
5
|
+
import { MenuContext } from './MenuContext';
|
6
6
|
import { LeadingVisualContainer } from './Visuals';
|
7
7
|
export const Selection = ({
|
8
8
|
selected
|
@@ -14,8 +14,8 @@ export const Selection = ({
|
|
14
14
|
selectionVariant: groupSelectionVariant
|
15
15
|
} = React.useContext(GroupContext);
|
16
16
|
const {
|
17
|
-
|
18
|
-
} = React.useContext(
|
17
|
+
parent
|
18
|
+
} = React.useContext(MenuContext);
|
19
19
|
/** selectionVariant in Group can override the selectionVariant in List root */
|
20
20
|
|
21
21
|
const selectionVariant = typeof groupSelectionVariant !== 'undefined' ? groupSelectionVariant : listSelectionVariant; // if selectionVariant is not set on List, don't show selection
|
@@ -26,7 +26,7 @@ export const Selection = ({
|
|
26
26
|
return null;
|
27
27
|
}
|
28
28
|
|
29
|
-
if (
|
29
|
+
if (parent === 'ActionMenu') {
|
30
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
31
|
return null;
|
32
32
|
}
|
package/lib-esm/ActionMenu2.d.ts
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import { ButtonProps } from './Button';
|
2
2
|
import React from 'react';
|
3
|
-
import { AnchoredOverlayProps } from './AnchoredOverlay';
|
4
3
|
import { OverlayProps } from './Overlay';
|
5
|
-
|
6
|
-
|
7
|
-
export declare type ActionMenuProps = {
|
4
|
+
import { AnchoredOverlayWrapperAnchorProps } from './AnchoredOverlay/AnchoredOverlay';
|
5
|
+
declare type ActionMenuBaseProps = {
|
8
6
|
/**
|
9
|
-
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with `
|
7
|
+
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with ActionList`
|
10
8
|
*/
|
11
9
|
children: React.ReactElement[] | React.ReactElement;
|
12
10
|
/**
|
@@ -17,18 +15,17 @@ export declare type ActionMenuProps = {
|
|
17
15
|
* If defined, will control the open/closed state of the overlay. Must be used in conjuction with `open`.
|
18
16
|
*/
|
19
17
|
onOpenChange?: (s: boolean) => void;
|
20
|
-
|
18
|
+
/**
|
19
|
+
* Props to be spread on the internal `Overlay` component.
|
20
|
+
*/
|
21
|
+
overlayProps?: Partial<OverlayProps>;
|
22
|
+
};
|
23
|
+
export declare type ActionMenuProps = ActionMenuBaseProps & AnchoredOverlayWrapperAnchorProps;
|
21
24
|
export declare type MenuAnchorProps = {
|
22
25
|
children: React.ReactElement;
|
23
26
|
};
|
24
27
|
/** this component is syntactical sugar 🍭 */
|
25
28
|
export declare type MenuButtonProps = ButtonProps;
|
26
|
-
declare type MenuOverlayProps = Partial<OverlayProps> & {
|
27
|
-
/**
|
28
|
-
* Recommended: `ActionList`
|
29
|
-
*/
|
30
|
-
children: React.ReactElement[] | React.ReactElement;
|
31
|
-
};
|
32
29
|
export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
33
30
|
Button: React.ForwardRefExoticComponent<Pick<{
|
34
31
|
color?: string | undefined;
|
@@ -311,7 +308,6 @@ export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
|
311
308
|
variant?: "small" | "medium" | "large" | undefined;
|
312
309
|
}> & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
313
310
|
Anchor: React.ForwardRefExoticComponent<MenuAnchorProps & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
314
|
-
Overlay: React.FC<MenuOverlayProps>;
|
315
311
|
Divider: React.FC<import("./sx").SxProp>;
|
316
312
|
};
|
317
313
|
export {};
|