@primer/components 0.0.0-202111405048 → 0.0.0-2021116132249
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/{MenuContext.d.ts → ActionListContainerContext.d.ts} +3 -3
- package/lib/ActionList2/{MenuContext.js → ActionListContainerContext.js} +3 -3
- package/lib/ActionList2/Item.js +4 -6
- package/lib/ActionList2/List.js +2 -2
- package/lib/ActionList2/Selection.js +4 -4
- package/lib/ActionMenu2.d.ts +13 -9
- package/lib/ActionMenu2.js +63 -29
- 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 +1 -0
- package/lib/hooks/index.js +9 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib-esm/ActionList2/{MenuContext.d.ts → ActionListContainerContext.d.ts} +3 -3
- package/lib-esm/ActionList2/{MenuContext.js → ActionListContainerContext.js} +1 -1
- package/lib-esm/ActionList2/Item.js +4 -6
- package/lib-esm/ActionList2/List.js +2 -2
- package/lib-esm/ActionList2/Selection.js +4 -4
- package/lib-esm/ActionMenu2.d.ts +13 -9
- package/lib-esm/ActionMenu2.js +60 -27
- 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 +1 -0
- package/lib-esm/hooks/index.js +2 -1
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +1 -0
- package/package.json +1 -1
package/lib-esm/ActionMenu2.js
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
import Button from './Button';
|
2
2
|
import React from 'react';
|
3
3
|
import { AnchoredOverlay } from './AnchoredOverlay';
|
4
|
-
import { useProvidedStateOrCreate } from './hooks
|
5
|
-
import { useProvidedRefOrCreate } from './hooks';
|
4
|
+
import { useProvidedRefOrCreate, useProvidedStateOrCreate } from './hooks';
|
6
5
|
import { Divider } from './ActionList2/Divider';
|
7
|
-
import {
|
6
|
+
import { ActionListContainerContext } from './ActionList2/ActionListContainerContext';
|
7
|
+
export const MenuContext = /*#__PURE__*/React.createContext({
|
8
|
+
renderAnchor: null,
|
9
|
+
open: false
|
10
|
+
});
|
8
11
|
|
9
|
-
const
|
12
|
+
const Menu = ({
|
10
13
|
anchorRef: externalAnchorRef,
|
11
14
|
open,
|
12
15
|
onOpenChange,
|
13
|
-
overlayProps,
|
14
16
|
children
|
15
17
|
}) => {
|
16
18
|
const [combinedOpenState, setCombinedOpenState] = useProvidedStateOrCreate(open, onOpenChange, false);
|
17
|
-
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
18
19
|
const onOpen = React.useCallback(() => setCombinedOpenState(true), [setCombinedOpenState]);
|
19
20
|
const onClose = React.useCallback(() => setCombinedOpenState(false), [setCombinedOpenState]);
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
22
|
+
let renderAnchor = null; // 🚨 Hack for good API!
|
23
|
+
// we strip out Anchor from children and pass it to AnchoredOverlay to render
|
24
|
+
// with additional props for accessibility
|
25
|
+
|
26
|
+
const contents = React.Children.map(children, child => {
|
23
27
|
if (child.type === MenuButton || child.type === Anchor) {
|
24
28
|
renderAnchor = anchorProps => /*#__PURE__*/React.cloneElement(child, anchorProps);
|
25
|
-
|
26
|
-
|
29
|
+
|
30
|
+
return null;
|
27
31
|
}
|
32
|
+
|
33
|
+
return child;
|
28
34
|
});
|
29
|
-
return /*#__PURE__*/React.createElement(
|
30
|
-
renderAnchor: renderAnchor,
|
31
|
-
anchorRef: anchorRef,
|
32
|
-
open: combinedOpenState,
|
33
|
-
onOpen: onOpen,
|
34
|
-
onClose: onClose,
|
35
|
-
overlayProps: overlayProps
|
36
|
-
}, /*#__PURE__*/React.createElement(ActionListMenuContext.Provider, {
|
35
|
+
return /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
37
36
|
value: {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
anchorRef,
|
38
|
+
renderAnchor,
|
39
|
+
open: combinedOpenState,
|
40
|
+
onOpen,
|
41
|
+
onClose
|
42
42
|
}
|
43
|
-
}, contents)
|
43
|
+
}, contents);
|
44
44
|
};
|
45
45
|
|
46
|
-
|
46
|
+
Menu.displayName = "Menu";
|
47
47
|
const Anchor = /*#__PURE__*/React.forwardRef(({
|
48
48
|
children,
|
49
49
|
...anchorProps
|
@@ -59,9 +59,42 @@ const MenuButton = /*#__PURE__*/React.forwardRef((props, anchorRef) => {
|
|
59
59
|
ref: anchorRef
|
60
60
|
}, /*#__PURE__*/React.createElement(Button, props));
|
61
61
|
});
|
62
|
-
|
63
|
-
|
62
|
+
|
63
|
+
const Overlay = ({
|
64
|
+
children,
|
65
|
+
...overlayProps
|
66
|
+
}) => {
|
67
|
+
// we typecast anchorRef as required instead of optional
|
68
|
+
// because we know that we're setting it in context in Menu
|
69
|
+
const {
|
70
|
+
anchorRef,
|
71
|
+
renderAnchor,
|
72
|
+
open,
|
73
|
+
onOpen,
|
74
|
+
onClose
|
75
|
+
} = React.useContext(MenuContext);
|
76
|
+
return /*#__PURE__*/React.createElement(AnchoredOverlay, {
|
77
|
+
anchorRef: anchorRef,
|
78
|
+
renderAnchor: renderAnchor,
|
79
|
+
open: open,
|
80
|
+
onOpen: onOpen,
|
81
|
+
onClose: onClose,
|
82
|
+
overlayProps: overlayProps
|
83
|
+
}, /*#__PURE__*/React.createElement(ActionListContainerContext.Provider, {
|
84
|
+
value: {
|
85
|
+
container: 'ActionMenu',
|
86
|
+
listRole: 'menu',
|
87
|
+
itemRole: 'menuitem',
|
88
|
+
afterSelect: onClose
|
89
|
+
}
|
90
|
+
}, children));
|
91
|
+
};
|
92
|
+
|
93
|
+
Overlay.displayName = "Overlay";
|
94
|
+
Menu.displayName = 'ActionMenu';
|
95
|
+
export const ActionMenu = Object.assign(Menu, {
|
64
96
|
Button: MenuButton,
|
65
97
|
Anchor,
|
98
|
+
Overlay,
|
66
99
|
Divider
|
67
100
|
});
|
package/lib-esm/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;
|
@@ -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-esm/Radio.js
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
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); }
|
2
|
+
|
3
|
+
import styled from 'styled-components';
|
4
|
+
import React from 'react';
|
5
|
+
import sx from './sx';
|
6
|
+
const StyledRadio = styled.input.withConfig({
|
7
|
+
displayName: "Radio__StyledRadio",
|
8
|
+
componentId: "sc-1ak1fjg-0"
|
9
|
+
})(["cursor:pointer;", " ", ""], props => props.disabled && `cursor: not-allowed;`, sx);
|
10
|
+
/**
|
11
|
+
* An accessible, native radio component for selecting one option from a list.
|
12
|
+
*/
|
13
|
+
|
14
|
+
const Radio = /*#__PURE__*/React.forwardRef(({
|
15
|
+
checked,
|
16
|
+
disabled,
|
17
|
+
sx: sxProp,
|
18
|
+
required,
|
19
|
+
validationStatus,
|
20
|
+
value,
|
21
|
+
name,
|
22
|
+
...rest
|
23
|
+
}, ref) => {
|
24
|
+
return /*#__PURE__*/React.createElement(StyledRadio, _extends({
|
25
|
+
type: "radio",
|
26
|
+
value: value,
|
27
|
+
name: name,
|
28
|
+
ref: ref,
|
29
|
+
disabled: disabled,
|
30
|
+
"aria-disabled": disabled ? 'true' : 'false',
|
31
|
+
checked: checked,
|
32
|
+
"aria-checked": checked ? 'true' : 'false',
|
33
|
+
required: required,
|
34
|
+
"aria-required": required ? 'true' : 'false',
|
35
|
+
"aria-invalid": validationStatus === 'error' ? 'true' : 'false',
|
36
|
+
sx: sxProp
|
37
|
+
}, rest));
|
38
|
+
});
|
39
|
+
Radio.displayName = 'Radio';
|
40
|
+
export default Radio;
|
package/lib-esm/hooks/index.d.ts
CHANGED
@@ -9,3 +9,4 @@ 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-esm/hooks/index.js
CHANGED
@@ -4,4 +4,5 @@ export { useOnEscapePress } from './useOnEscapePress';
|
|
4
4
|
export { useOpenAndCloseFocus } from './useOpenAndCloseFocus';
|
5
5
|
export { useAnchoredPosition } from './useAnchoredPosition';
|
6
6
|
export { useOverlay } from './useOverlay';
|
7
|
-
export { useRenderForcingRef } from './useRenderForcingRef';
|
7
|
+
export { useRenderForcingRef } from './useRenderForcingRef';
|
8
|
+
export { useProvidedStateOrCreate } from './useProvidedStateOrCreate';
|
package/lib-esm/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-esm/index.js
CHANGED
@@ -17,6 +17,7 @@ export { useOnEscapePress } from './hooks/useOnEscapePress';
|
|
17
17
|
export { useOverlay } from './hooks/useOverlay';
|
18
18
|
export { useConfirm } from './Dialog/ConfirmationDialog'; // Components
|
19
19
|
|
20
|
+
export { default as Radio } from './Radio';
|
20
21
|
export { ActionList } from './ActionList';
|
21
22
|
export { ActionMenu } from './ActionMenu';
|
22
23
|
export { default as Autocomplete } from './Autocomplete';
|