@primer/components 0.0.0-202182821211 → 0.0.0-20218282148
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 +7 -1
- package/dist/browser.esm.js +242 -242
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +696 -696
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +1 -1
- package/lib/Dialog/ConfirmationDialog.js +3 -3
- package/lib/Dialog/Dialog.js +19 -13
- package/lib/theme-preval.d.ts +4 -58
- package/lib/theme-preval.js +3696 -1813
- package/lib/utils/testing.d.ts +889 -7381
- package/lib-esm/ActionList/Item.js +1 -1
- package/lib-esm/Dialog/ConfirmationDialog.js +3 -3
- package/lib-esm/Dialog/Dialog.js +20 -14
- package/lib-esm/theme-preval.d.ts +4 -58
- package/lib-esm/theme-preval.js +3696 -1813
- package/lib-esm/utils/testing.d.ts +889 -7381
- package/package.json +2 -2
@@ -97,13 +97,13 @@ export const ConfirmationDialog = props => {
|
|
97
97
|
}, [onClose]);
|
98
98
|
const cancelButton = {
|
99
99
|
content: cancelButtonContent,
|
100
|
-
onClick: onCancelButtonClick
|
100
|
+
onClick: onCancelButtonClick,
|
101
|
+
autoFocus: true
|
101
102
|
};
|
102
103
|
const confirmButton = {
|
103
104
|
content: confirmButtonContent,
|
104
105
|
buttonType: confirmButtonType,
|
105
|
-
onClick: onConfirmButtonClick
|
106
|
-
autoFocus: true
|
106
|
+
onClick: onConfirmButtonClick
|
107
107
|
};
|
108
108
|
const footerButtons = [cancelButton, confirmButton];
|
109
109
|
return /*#__PURE__*/React.createElement(Dialog, {
|
package/lib-esm/Dialog/Dialog.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
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
2
|
|
3
|
-
import React, { useCallback, useRef } from 'react';
|
3
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
4
4
|
import styled from 'styled-components';
|
5
5
|
import Button, { ButtonPrimary, ButtonDanger } from '../Button';
|
6
6
|
import Box from '../Box';
|
@@ -112,19 +112,10 @@ const _Dialog = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
112
112
|
onClose,
|
113
113
|
role = 'dialog',
|
114
114
|
width = 'xlarge',
|
115
|
-
height = 'auto'
|
116
|
-
footerButtons = []
|
115
|
+
height = 'auto'
|
117
116
|
} = props;
|
118
117
|
const dialogLabelId = useSSRSafeId();
|
119
118
|
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
|
-
|
128
119
|
const defaultedProps = { ...props,
|
129
120
|
title,
|
130
121
|
subtitle,
|
@@ -137,8 +128,7 @@ const _Dialog = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
137
128
|
const backdropRef = useRef(null);
|
138
129
|
useFocusTrap({
|
139
130
|
containerRef: dialogRef,
|
140
|
-
restoreFocusOnCleanUp: true
|
141
|
-
initialFocusRef: autoFocusedFooterButtonRef
|
131
|
+
restoreFocusOnCleanUp: true
|
142
132
|
});
|
143
133
|
useOnEscapePress(event => {
|
144
134
|
onClose('escape');
|
@@ -193,16 +183,32 @@ const buttonTypes = {
|
|
193
183
|
const Buttons = ({
|
194
184
|
buttons
|
195
185
|
}) => {
|
186
|
+
const autoFocusRef = useRef(null);
|
187
|
+
let autoFocusCount = 0;
|
188
|
+
const [hasRendered, setHasRendered] = useState(0);
|
189
|
+
useEffect(() => {
|
190
|
+
// hack to work around dialogs originating from other focus traps.
|
191
|
+
if (hasRendered === 1) {
|
192
|
+
var _autoFocusRef$current;
|
193
|
+
|
194
|
+
(_autoFocusRef$current = autoFocusRef.current) === null || _autoFocusRef$current === void 0 ? void 0 : _autoFocusRef$current.focus();
|
195
|
+
} else {
|
196
|
+
setHasRendered(hasRendered + 1);
|
197
|
+
}
|
198
|
+
}, [hasRendered]);
|
196
199
|
return /*#__PURE__*/React.createElement(React.Fragment, null, buttons.map((dialogButtonProps, index) => {
|
197
200
|
const {
|
198
201
|
content,
|
199
202
|
buttonType = 'normal',
|
203
|
+
autoFocus = false,
|
200
204
|
...buttonProps
|
201
205
|
} = dialogButtonProps;
|
202
206
|
const ButtonElement = buttonTypes[buttonType];
|
203
207
|
return /*#__PURE__*/React.createElement(ButtonElement, _extends({
|
204
208
|
key: index
|
205
|
-
}, buttonProps
|
209
|
+
}, buttonProps, {
|
210
|
+
ref: autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null
|
211
|
+
}), content);
|
206
212
|
}));
|
207
213
|
};
|
208
214
|
|
@@ -9,24 +9,7 @@ export namespace theme {
|
|
9
9
|
export { radii };
|
10
10
|
export { sizes };
|
11
11
|
export { space };
|
12
|
-
export
|
13
|
-
namespace light {
|
14
|
-
export { lightColors as colors };
|
15
|
-
export { lightShadows as shadows };
|
16
|
-
}
|
17
|
-
namespace dark {
|
18
|
-
export { darkColors as colors };
|
19
|
-
export { darkShadows as shadows };
|
20
|
-
}
|
21
|
-
namespace dark_dimmed {
|
22
|
-
export { darkDimmedColors as colors };
|
23
|
-
export { darkDimmedShadows as shadows };
|
24
|
-
}
|
25
|
-
namespace dark_high_contrast {
|
26
|
-
export { darkHighContrastColors as colors };
|
27
|
-
export { darkHighContrastShadows as shadows };
|
28
|
-
}
|
29
|
-
}
|
12
|
+
export { colorSchemes };
|
30
13
|
}
|
31
14
|
declare namespace animation {
|
32
15
|
const easeOutCubic: string;
|
@@ -39,8 +22,7 @@ declare namespace fonts {
|
|
39
22
|
}
|
40
23
|
declare const fontSizes: string[];
|
41
24
|
declare namespace fontWeights {
|
42
|
-
const
|
43
|
-
export { light_1 as light };
|
25
|
+
export const light: number;
|
44
26
|
const normal_1: number;
|
45
27
|
export { normal_1 as normal };
|
46
28
|
export const semibold: number;
|
@@ -60,44 +42,8 @@ declare namespace sizes {
|
|
60
42
|
}
|
61
43
|
declare const space: string[];
|
62
44
|
/**
|
63
|
-
* @type Partial<typeof primitives.colors.light
|
45
|
+
* @type Record<keyof typeof primitives.colors, Record<'colors' | 'shadows', Partial<typeof primitives.colors.light>>
|
64
46
|
*/
|
65
|
-
declare const
|
66
|
-
/**
|
67
|
-
* @type Partial<typeof primitives.colors.light>
|
68
|
-
*/
|
69
|
-
declare const lightShadows: Partial<typeof primitives.colors.light>;
|
70
|
-
/**
|
71
|
-
* @type Partial<typeof primitives.colors.dark>
|
72
|
-
*/
|
73
|
-
declare const darkColors: Partial<typeof primitives.colors.dark>;
|
74
|
-
/**
|
75
|
-
* @type Partial<typeof primitives.colors.dark>
|
76
|
-
*/
|
77
|
-
declare const darkShadows: Partial<typeof primitives.colors.dark>;
|
78
|
-
/**
|
79
|
-
* @type Partial<typeof primitives.colors.dark_dimmed>
|
80
|
-
*/
|
81
|
-
declare const darkDimmedColors: Partial<typeof primitives.colors.dark_dimmed>;
|
82
|
-
/**
|
83
|
-
* @type Partial<typeof primitives.colors.dark_dimmed>
|
84
|
-
*/
|
85
|
-
declare const darkDimmedShadows: Partial<typeof primitives.colors.dark_dimmed>;
|
86
|
-
/**
|
87
|
-
* @type Partial<typeof primitives.colors.dark_dimmed>
|
88
|
-
*/
|
89
|
-
declare const darkHighContrastColors: Partial<typeof primitives.colors.dark_dimmed>;
|
90
|
-
/**
|
91
|
-
* @type Partial<typeof primitives.colors.dark_high_contrast>
|
92
|
-
*/
|
93
|
-
declare const darkHighContrastShadows: Partial<typeof primitives.colors.dark_high_contrast>;
|
47
|
+
declare const colorSchemes: Record<keyof typeof primitives.colors, Record<'colors' | 'shadows', Partial<typeof primitives.colors.light>>>;
|
94
48
|
import { default as primitives } from "@primer/primitives";
|
95
|
-
declare const light_2: {
|
96
|
-
colors: {};
|
97
|
-
shadows: {};
|
98
|
-
};
|
99
|
-
declare const dark_1: {
|
100
|
-
colors: {};
|
101
|
-
shadows: {};
|
102
|
-
};
|
103
49
|
export {};
|