@primer/components 0.0.0-202182923742 → 0.0.0-202183053931
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 +3 -1
- package/dist/browser.esm.js +5 -5
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +259 -259
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +6 -25
- package/lib/Dialog/ConfirmationDialog.js +3 -3
- package/lib/Dialog/Dialog.d.ts +5 -0
- package/lib/Dialog/Dialog.js +16 -4
- package/lib-esm/ActionList/Item.js +7 -27
- package/lib-esm/Dialog/ConfirmationDialog.js +3 -3
- package/lib-esm/Dialog/Dialog.d.ts +5 -0
- package/lib-esm/Dialog/Dialog.js +17 -5
- package/package.json +4 -4
package/lib/ActionList/Item.js
CHANGED
@@ -36,33 +36,14 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
36
36
|
|
37
37
|
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); }
|
38
38
|
|
39
|
-
/**
|
40
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
41
|
-
*/
|
42
39
|
const customItemThemes = {
|
43
40
|
default: {
|
44
|
-
hover:
|
45
|
-
|
46
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
47
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
48
|
-
},
|
49
|
-
focus: {
|
50
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
51
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
52
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
53
|
-
}
|
41
|
+
hover: (0, _constants.get)('colors.neutral.subtle'),
|
42
|
+
focus: (0, _constants.get)('colors.neutral.muted')
|
54
43
|
},
|
55
44
|
danger: {
|
56
|
-
hover:
|
57
|
-
|
58
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
59
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
60
|
-
},
|
61
|
-
focus: {
|
62
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
63
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
64
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
65
|
-
}
|
45
|
+
hover: (0, _constants.get)('colors.danger.subtle'),
|
46
|
+
focus: (0, _constants.get)('colors.danger.muted')
|
66
47
|
}
|
67
48
|
};
|
68
49
|
/**
|
@@ -229,8 +210,8 @@ function Item(itemProps) {
|
|
229
210
|
}
|
230
211
|
}, [onAction, disabled, itemProps, onClick]);
|
231
212
|
const customItemTheme = customItemThemes[variant];
|
232
|
-
const hoverBackground =
|
233
|
-
const focusBackground =
|
213
|
+
const hoverBackground = customItemTheme.hover;
|
214
|
+
const focusBackground = customItemTheme.focus;
|
234
215
|
const {
|
235
216
|
theme
|
236
217
|
} = (0, _ThemeProvider.useTheme)();
|
@@ -117,13 +117,13 @@ const ConfirmationDialog = props => {
|
|
117
117
|
}, [onClose]);
|
118
118
|
const cancelButton = {
|
119
119
|
content: cancelButtonContent,
|
120
|
-
onClick: onCancelButtonClick
|
121
|
-
autoFocus: true
|
120
|
+
onClick: onCancelButtonClick
|
122
121
|
};
|
123
122
|
const confirmButton = {
|
124
123
|
content: confirmButtonContent,
|
125
124
|
buttonType: confirmButtonType,
|
126
|
-
onClick: onConfirmButtonClick
|
125
|
+
onClick: onConfirmButtonClick,
|
126
|
+
autoFocus: true
|
127
127
|
};
|
128
128
|
const footerButtons = [cancelButton, confirmButton];
|
129
129
|
return /*#__PURE__*/_react.default.createElement(_Dialog.Dialog, {
|
package/lib/Dialog/Dialog.d.ts
CHANGED
@@ -19,6 +19,11 @@ export declare type DialogButtonProps = ButtonProps & {
|
|
19
19
|
* focus this button automatically when the dialog appears.
|
20
20
|
*/
|
21
21
|
autoFocus?: boolean;
|
22
|
+
/**
|
23
|
+
* A reference to the rendered Button’s DOM node, used together with
|
24
|
+
* `autoFocus` for `focusTrap`’s `initialFocus`.
|
25
|
+
*/
|
26
|
+
ref?: React.RefObject<HTMLButtonElement>;
|
22
27
|
};
|
23
28
|
/**
|
24
29
|
* Props to customize the rendering of the Dialog.
|
package/lib/Dialog/Dialog.js
CHANGED
@@ -141,10 +141,19 @@ const _Dialog = /*#__PURE__*/_react.default.forwardRef((props, forwardedRef) =>
|
|
141
141
|
onClose,
|
142
142
|
role = 'dialog',
|
143
143
|
width = 'xlarge',
|
144
|
-
height = 'auto'
|
144
|
+
height = 'auto',
|
145
|
+
footerButtons = []
|
145
146
|
} = props;
|
146
147
|
const dialogLabelId = (0, _ssr.useSSRSafeId)();
|
147
148
|
const dialogDescriptionId = (0, _ssr.useSSRSafeId)();
|
149
|
+
const autoFocusedFooterButtonRef = (0, _react.useRef)(null);
|
150
|
+
|
151
|
+
for (const footerButton of footerButtons) {
|
152
|
+
if (footerButton.autoFocus) {
|
153
|
+
footerButton.ref = autoFocusedFooterButtonRef;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
148
157
|
const defaultedProps = { ...props,
|
149
158
|
title,
|
150
159
|
subtitle,
|
@@ -157,7 +166,8 @@ const _Dialog = /*#__PURE__*/_react.default.forwardRef((props, forwardedRef) =>
|
|
157
166
|
const backdropRef = (0, _react.useRef)(null);
|
158
167
|
(0, _useFocusTrap.useFocusTrap)({
|
159
168
|
containerRef: dialogRef,
|
160
|
-
restoreFocusOnCleanUp: true
|
169
|
+
restoreFocusOnCleanUp: true,
|
170
|
+
initialFocusRef: autoFocusedFooterButtonRef
|
161
171
|
});
|
162
172
|
(0, _hooks.useOnEscapePress)(event => {
|
163
173
|
onClose('escape');
|
@@ -212,7 +222,9 @@ const buttonTypes = {
|
|
212
222
|
const Buttons = ({
|
213
223
|
buttons
|
214
224
|
}) => {
|
215
|
-
|
225
|
+
var _buttons$find;
|
226
|
+
|
227
|
+
const autoFocusRef = (0, _hooks.useProvidedRefOrCreate)((_buttons$find = buttons.find(button => button.autoFocus)) === null || _buttons$find === void 0 ? void 0 : _buttons$find.ref);
|
216
228
|
let autoFocusCount = 0;
|
217
229
|
const [hasRendered, setHasRendered] = (0, _react.useState)(0);
|
218
230
|
(0, _react.useEffect)(() => {
|
@@ -224,7 +236,7 @@ const Buttons = ({
|
|
224
236
|
} else {
|
225
237
|
setHasRendered(hasRendered + 1);
|
226
238
|
}
|
227
|
-
}, [hasRendered]);
|
239
|
+
}, [autoFocusRef, hasRendered]);
|
228
240
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, buttons.map((dialogButtonProps, index) => {
|
229
241
|
const {
|
230
242
|
content,
|
@@ -8,37 +8,17 @@ import Truncate from '../Truncate';
|
|
8
8
|
import styled from 'styled-components';
|
9
9
|
import { StyledHeader } from './Header';
|
10
10
|
import { StyledDivider } from './Divider';
|
11
|
-
import {
|
11
|
+
import { useTheme } from '../ThemeProvider';
|
12
12
|
import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
|
13
13
|
import { useSSRSafeId } from '@react-aria/ssr';
|
14
|
-
/**
|
15
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
16
|
-
*/
|
17
|
-
|
18
14
|
const customItemThemes = {
|
19
15
|
default: {
|
20
|
-
hover:
|
21
|
-
|
22
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
23
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
24
|
-
},
|
25
|
-
focus: {
|
26
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
27
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
28
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
29
|
-
}
|
16
|
+
hover: get('colors.neutral.subtle'),
|
17
|
+
focus: get('colors.neutral.muted')
|
30
18
|
},
|
31
19
|
danger: {
|
32
|
-
hover:
|
33
|
-
|
34
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
35
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
36
|
-
},
|
37
|
-
focus: {
|
38
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
39
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
40
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
41
|
-
}
|
20
|
+
hover: get('colors.danger.subtle'),
|
21
|
+
focus: get('colors.danger.muted')
|
42
22
|
}
|
43
23
|
};
|
44
24
|
/**
|
@@ -195,8 +175,8 @@ export function Item(itemProps) {
|
|
195
175
|
}
|
196
176
|
}, [onAction, disabled, itemProps, onClick]);
|
197
177
|
const customItemTheme = customItemThemes[variant];
|
198
|
-
const hoverBackground =
|
199
|
-
const focusBackground =
|
178
|
+
const hoverBackground = customItemTheme.hover;
|
179
|
+
const focusBackground = customItemTheme.focus;
|
200
180
|
const {
|
201
181
|
theme
|
202
182
|
} = useTheme();
|
@@ -97,13 +97,13 @@ export const ConfirmationDialog = props => {
|
|
97
97
|
}, [onClose]);
|
98
98
|
const cancelButton = {
|
99
99
|
content: cancelButtonContent,
|
100
|
-
onClick: onCancelButtonClick
|
101
|
-
autoFocus: true
|
100
|
+
onClick: onCancelButtonClick
|
102
101
|
};
|
103
102
|
const confirmButton = {
|
104
103
|
content: confirmButtonContent,
|
105
104
|
buttonType: confirmButtonType,
|
106
|
-
onClick: onConfirmButtonClick
|
105
|
+
onClick: onConfirmButtonClick,
|
106
|
+
autoFocus: true
|
107
107
|
};
|
108
108
|
const footerButtons = [cancelButton, confirmButton];
|
109
109
|
return /*#__PURE__*/React.createElement(Dialog, {
|
@@ -19,6 +19,11 @@ export declare type DialogButtonProps = ButtonProps & {
|
|
19
19
|
* focus this button automatically when the dialog appears.
|
20
20
|
*/
|
21
21
|
autoFocus?: boolean;
|
22
|
+
/**
|
23
|
+
* A reference to the rendered Button’s DOM node, used together with
|
24
|
+
* `autoFocus` for `focusTrap`’s `initialFocus`.
|
25
|
+
*/
|
26
|
+
ref?: React.RefObject<HTMLButtonElement>;
|
22
27
|
};
|
23
28
|
/**
|
24
29
|
* Props to customize the rendering of the Dialog.
|
package/lib-esm/Dialog/Dialog.js
CHANGED
@@ -5,7 +5,7 @@ import styled from 'styled-components';
|
|
5
5
|
import Button, { ButtonPrimary, ButtonDanger } from '../Button';
|
6
6
|
import Box from '../Box';
|
7
7
|
import { get, COMMON, POSITION } from '../constants';
|
8
|
-
import { useOnEscapePress } from '../hooks';
|
8
|
+
import { useOnEscapePress, useProvidedRefOrCreate } from '../hooks';
|
9
9
|
import { useFocusTrap } from '../hooks/useFocusTrap';
|
10
10
|
import sx from '../sx';
|
11
11
|
import StyledOcticon from '../StyledOcticon';
|
@@ -112,10 +112,19 @@ const _Dialog = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
112
112
|
onClose,
|
113
113
|
role = 'dialog',
|
114
114
|
width = 'xlarge',
|
115
|
-
height = 'auto'
|
115
|
+
height = 'auto',
|
116
|
+
footerButtons = []
|
116
117
|
} = props;
|
117
118
|
const dialogLabelId = useSSRSafeId();
|
118
119
|
const dialogDescriptionId = useSSRSafeId();
|
120
|
+
const autoFocusedFooterButtonRef = useRef(null);
|
121
|
+
|
122
|
+
for (const footerButton of footerButtons) {
|
123
|
+
if (footerButton.autoFocus) {
|
124
|
+
footerButton.ref = autoFocusedFooterButtonRef;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
119
128
|
const defaultedProps = { ...props,
|
120
129
|
title,
|
121
130
|
subtitle,
|
@@ -128,7 +137,8 @@ const _Dialog = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
128
137
|
const backdropRef = useRef(null);
|
129
138
|
useFocusTrap({
|
130
139
|
containerRef: dialogRef,
|
131
|
-
restoreFocusOnCleanUp: true
|
140
|
+
restoreFocusOnCleanUp: true,
|
141
|
+
initialFocusRef: autoFocusedFooterButtonRef
|
132
142
|
});
|
133
143
|
useOnEscapePress(event => {
|
134
144
|
onClose('escape');
|
@@ -183,7 +193,9 @@ const buttonTypes = {
|
|
183
193
|
const Buttons = ({
|
184
194
|
buttons
|
185
195
|
}) => {
|
186
|
-
|
196
|
+
var _buttons$find;
|
197
|
+
|
198
|
+
const autoFocusRef = useProvidedRefOrCreate((_buttons$find = buttons.find(button => button.autoFocus)) === null || _buttons$find === void 0 ? void 0 : _buttons$find.ref);
|
187
199
|
let autoFocusCount = 0;
|
188
200
|
const [hasRendered, setHasRendered] = useState(0);
|
189
201
|
useEffect(() => {
|
@@ -195,7 +207,7 @@ const Buttons = ({
|
|
195
207
|
} else {
|
196
208
|
setHasRendered(hasRendered + 1);
|
197
209
|
}
|
198
|
-
}, [hasRendered]);
|
210
|
+
}, [autoFocusRef, hasRendered]);
|
199
211
|
return /*#__PURE__*/React.createElement(React.Fragment, null, buttons.map((dialogButtonProps, index) => {
|
200
212
|
const {
|
201
213
|
content,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/components",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-202183053931",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -72,7 +72,7 @@
|
|
72
72
|
"@changesets/cli": "2.17.0",
|
73
73
|
"@github/prettier-config": "0.0.4",
|
74
74
|
"@rollup/plugin-commonjs": "19.0.2",
|
75
|
-
"@rollup/plugin-node-resolve": "13.0.
|
75
|
+
"@rollup/plugin-node-resolve": "13.0.5",
|
76
76
|
"@size-limit/preset-big-lib": "5.0.2",
|
77
77
|
"@storybook/addon-a11y": "6.3.4",
|
78
78
|
"@storybook/addon-actions": "^6.2.9",
|
@@ -81,7 +81,7 @@
|
|
81
81
|
"@storybook/react": "6.3.8",
|
82
82
|
"@testing-library/dom": "7.31.2",
|
83
83
|
"@testing-library/react": "11.2.7",
|
84
|
-
"@testing-library/react-hooks": "7.0.
|
84
|
+
"@testing-library/react-hooks": "7.0.2",
|
85
85
|
"@testing-library/user-event": "13.1.9",
|
86
86
|
"@types/chroma-js": "2.1.3",
|
87
87
|
"@types/enzyme": "3.10.9",
|
@@ -111,7 +111,7 @@
|
|
111
111
|
"eslint-plugin-jsx-a11y": "6.4.1",
|
112
112
|
"eslint-plugin-mdx": "1.15.1",
|
113
113
|
"eslint-plugin-prettier": "3.4.0",
|
114
|
-
"eslint-plugin-primer-react": "0.
|
114
|
+
"eslint-plugin-primer-react": "0.5.0",
|
115
115
|
"eslint-plugin-react": "7.24.0",
|
116
116
|
"eslint-plugin-react-hooks": "4.2.0",
|
117
117
|
"jest": "27.0.4",
|