@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.
@@ -90,7 +90,7 @@ const getItemVariant = (variant = 'default', disabled) => {
90
90
 
91
91
  default:
92
92
  return {
93
- color: 'inherit',
93
+ color: (0, _constants.get)('colors.fg.default'),
94
94
  iconColor: (0, _constants.get)('colors.fg.muted'),
95
95
  annotationColor: (0, _constants.get)('colors.fg.muted'),
96
96
  hoverCursor: 'pointer'
@@ -117,13 +117,13 @@ const ConfirmationDialog = props => {
117
117
  }, [onClose]);
118
118
  const cancelButton = {
119
119
  content: cancelButtonContent,
120
- onClick: onCancelButtonClick
120
+ onClick: onCancelButtonClick,
121
+ autoFocus: true
121
122
  };
122
123
  const confirmButton = {
123
124
  content: confirmButtonContent,
124
125
  buttonType: confirmButtonType,
125
- onClick: onConfirmButtonClick,
126
- autoFocus: true
126
+ onClick: onConfirmButtonClick
127
127
  };
128
128
  const footerButtons = [cancelButton, confirmButton];
129
129
  return /*#__PURE__*/_react.default.createElement(_Dialog.Dialog, {
@@ -141,19 +141,10 @@ const _Dialog = /*#__PURE__*/_react.default.forwardRef((props, forwardedRef) =>
141
141
  onClose,
142
142
  role = 'dialog',
143
143
  width = 'xlarge',
144
- height = 'auto',
145
- footerButtons = []
144
+ height = 'auto'
146
145
  } = props;
147
146
  const dialogLabelId = (0, _ssr.useSSRSafeId)();
148
147
  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
-
157
148
  const defaultedProps = { ...props,
158
149
  title,
159
150
  subtitle,
@@ -166,8 +157,7 @@ const _Dialog = /*#__PURE__*/_react.default.forwardRef((props, forwardedRef) =>
166
157
  const backdropRef = (0, _react.useRef)(null);
167
158
  (0, _useFocusTrap.useFocusTrap)({
168
159
  containerRef: dialogRef,
169
- restoreFocusOnCleanUp: true,
170
- initialFocusRef: autoFocusedFooterButtonRef
160
+ restoreFocusOnCleanUp: true
171
161
  });
172
162
  (0, _hooks.useOnEscapePress)(event => {
173
163
  onClose('escape');
@@ -222,16 +212,32 @@ const buttonTypes = {
222
212
  const Buttons = ({
223
213
  buttons
224
214
  }) => {
215
+ const autoFocusRef = (0, _react.useRef)(null);
216
+ let autoFocusCount = 0;
217
+ const [hasRendered, setHasRendered] = (0, _react.useState)(0);
218
+ (0, _react.useEffect)(() => {
219
+ // hack to work around dialogs originating from other focus traps.
220
+ if (hasRendered === 1) {
221
+ var _autoFocusRef$current;
222
+
223
+ (_autoFocusRef$current = autoFocusRef.current) === null || _autoFocusRef$current === void 0 ? void 0 : _autoFocusRef$current.focus();
224
+ } else {
225
+ setHasRendered(hasRendered + 1);
226
+ }
227
+ }, [hasRendered]);
225
228
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, buttons.map((dialogButtonProps, index) => {
226
229
  const {
227
230
  content,
228
231
  buttonType = 'normal',
232
+ autoFocus = false,
229
233
  ...buttonProps
230
234
  } = dialogButtonProps;
231
235
  const ButtonElement = buttonTypes[buttonType];
232
236
  return /*#__PURE__*/_react.default.createElement(ButtonElement, _extends({
233
237
  key: index
234
- }, buttonProps), content);
238
+ }, buttonProps, {
239
+ ref: autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null
240
+ }), content);
235
241
  }));
236
242
  };
237
243
 
@@ -9,24 +9,7 @@ export namespace theme {
9
9
  export { radii };
10
10
  export { sizes };
11
11
  export { space };
12
- export namespace colorSchemes {
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 light_1: number;
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 lightColors: Partial<typeof primitives.colors.light>;
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 {};