@primer/components 0.0.0-2021828202352 → 0.0.0-202182821115

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.
@@ -1,12 +1,8 @@
1
- /// <reference types="react" />
2
- import { SystemCommonProps } from './constants';
1
+ import React from 'react';
3
2
  import { SxProp } from './sx';
4
- import { ComponentProps } from './utils/types';
5
- declare const AvatarStackWrapper: import("styled-components").StyledComponent<"span", any, {
6
- count?: number | undefined;
7
- } & SystemCommonProps & SxProp, never>;
8
3
  export declare type AvatarStackProps = {
9
4
  alignRight?: boolean;
10
- } & ComponentProps<typeof AvatarStackWrapper>;
11
- declare const AvatarStack: ({ children, alignRight, ...rest }: AvatarStackProps) => JSX.Element;
5
+ children: React.ReactNode;
6
+ } & SxProp;
7
+ declare const AvatarStack: ({ children, alignRight, sx: sxProp }: AvatarStackProps) => JSX.Element;
12
8
  export default AvatarStack;
@@ -1,15 +1,13 @@
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
1
  import classnames from 'classnames';
4
2
  import React from 'react';
5
3
  import styled from 'styled-components';
6
- import { COMMON, get } from './constants';
4
+ import { get } from './constants';
7
5
  import { Box } from '.';
8
6
  import sx from './sx';
9
7
  const AvatarStackWrapper = styled.span.withConfig({
10
8
  displayName: "AvatarStack__AvatarStackWrapper",
11
9
  componentId: "sc-1qgzd2v-0"
12
- })(["display:flex;position:relative;height:20px;min-width:", ";.pc-AvatarItem{flex-shrink:0;height:20px;width:20px;box-shadow:0 0 0 1px ", ";margin-left:-11px;position:relative;overflow:hidden;transition:margin 0.2s ease-in-out,opacity 0.2s ease-in-out,visibility 0.2s ease-in-out,box-shadow 0.1s ease-in-out;&:first-child{margin-left:0;}&:nth-child(n + 4){display:none;}}&.pc-AvatarStack--two{min-width:30px;.pc-AvatarItem{&:nth-child(n + 3){display:none;}}}&.pc-AvatarStack--three-plus{min-width:38px;.pc-AvatarItem{&:nth-child(3){opacity:", "%;margin-left:-17px;}&:nth-child(4){opacity:", "%;margin-left:-17px;}&:nth-child(5){opacity:", "%;margin-left:-17px;}&:nth-child(n + 4){display:block;}&:nth-child(n + 6){opacity:0;visibility:hidden;}}}&.pc-AvatarStack--right{justify-content:flex-end;.pc-AvatarItem{margin-left:0 !important;margin-right:-11px;&:first-child{margin-right:0;}}.pc-AvatarStackBody{flex-direction:row-reverse;&:hover{.pc-AvatarItem{margin-right:", "!important;margin-left:0 !important;&:first-child{margin-right:0 !important;}}}}}&.pc-AvatarStack--three-plus.pc-AvatarStack--right{.pc-AvatarItem{&:nth-child(3){margin-right:-17px;}&:nth-child(4){margin-right:-17px;}&:nth-child(5){margin-right:-17px;}}}.pc-AvatarStackBody:hover{width:auto;.pc-AvatarItem{margin-left:", ";opacity:100%;visibility:visible;box-shadow:0 0 0 4px ", ";&:first-child{margin-left:0;}}}", " ", ";"], props => props.count === 1 ? '20px' : props.count === 2 ? '30px' : '38px', get('colors.canvas.default'), 100 - 3 * 15, 100 - 4 * 15, 100 - 5 * 15, get('space.1'), get('space.1'), get('colors.canvas.default'), COMMON, sx);
10
+ })(["display:flex;position:relative;height:20px;min-width:", ";.pc-AvatarItem{flex-shrink:0;height:20px;width:20px;box-shadow:0 0 0 1px ", ";margin-left:-11px;position:relative;overflow:hidden;transition:margin 0.2s ease-in-out,opacity 0.2s ease-in-out,visibility 0.2s ease-in-out,box-shadow 0.1s ease-in-out;&:first-child{margin-left:0;}&:nth-child(n + 4){display:none;}}&.pc-AvatarStack--two{min-width:30px;.pc-AvatarItem{&:nth-child(n + 3){display:none;}}}&.pc-AvatarStack--three-plus{min-width:38px;.pc-AvatarItem{&:nth-child(3){opacity:", "%;margin-left:-17px;}&:nth-child(4){opacity:", "%;margin-left:-17px;}&:nth-child(5){opacity:", "%;margin-left:-17px;}&:nth-child(n + 4){display:block;}&:nth-child(n + 6){opacity:0;visibility:hidden;}}}&.pc-AvatarStack--right{justify-content:flex-end;.pc-AvatarItem{margin-left:0 !important;margin-right:-11px;&:first-child{margin-right:0;}}.pc-AvatarStackBody{flex-direction:row-reverse;&:hover{.pc-AvatarItem{margin-right:", "!important;margin-left:0 !important;&:first-child{margin-right:0 !important;}}}}}&.pc-AvatarStack--three-plus.pc-AvatarStack--right{.pc-AvatarItem{&:nth-child(3){margin-right:-17px;}&:nth-child(4){margin-right:-17px;}&:nth-child(5){margin-right:-17px;}}}.pc-AvatarStackBody:hover{width:auto;.pc-AvatarItem{margin-left:", ";opacity:100%;visibility:visible;box-shadow:0 0 0 4px ", ";&:first-child{margin-left:0;}}}", ";"], props => props.count === 1 ? '20px' : props.count === 2 ? '30px' : '38px', get('colors.canvas.default'), 100 - 3 * 15, 100 - 4 * 15, 100 - 5 * 15, get('space.1'), get('space.1'), get('colors.canvas.default'), sx);
13
11
 
14
12
  const transformChildren = children => {
15
13
  return React.Children.map(children, (child, index) => {
@@ -27,7 +25,7 @@ const transformChildren = children => {
27
25
  const AvatarStack = ({
28
26
  children,
29
27
  alignRight,
30
- ...rest
28
+ sx: sxProp
31
29
  }) => {
32
30
  const count = React.Children.count(children);
33
31
  const wrapperClassNames = classnames({
@@ -35,10 +33,11 @@ const AvatarStack = ({
35
33
  'pc-AvatarStack--three-plus': count > 2,
36
34
  'pc-AvatarStack--right': alignRight
37
35
  });
38
- return /*#__PURE__*/React.createElement(AvatarStackWrapper, _extends({
36
+ return /*#__PURE__*/React.createElement(AvatarStackWrapper, {
39
37
  count: count,
40
- className: wrapperClassNames
41
- }, rest), /*#__PURE__*/React.createElement(Box, {
38
+ className: wrapperClassNames,
39
+ sx: sxProp
40
+ }, /*#__PURE__*/React.createElement(Box, {
42
41
  position: "absolute",
43
42
  display: "flex",
44
43
  width: "38px",
@@ -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.
@@ -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
- const autoFocusRef = useRef(null);
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,
@@ -9,7 +9,24 @@ export namespace theme {
9
9
  export { radii };
10
10
  export { sizes };
11
11
  export { space };
12
- export { colorSchemes };
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
+ }
13
30
  }
14
31
  declare namespace animation {
15
32
  const easeOutCubic: string;
@@ -22,7 +39,8 @@ declare namespace fonts {
22
39
  }
23
40
  declare const fontSizes: string[];
24
41
  declare namespace fontWeights {
25
- export const light: number;
42
+ const light_1: number;
43
+ export { light_1 as light };
26
44
  const normal_1: number;
27
45
  export { normal_1 as normal };
28
46
  export const semibold: number;
@@ -42,8 +60,44 @@ declare namespace sizes {
42
60
  }
43
61
  declare const space: string[];
44
62
  /**
45
- * @type Record<keyof typeof primitives.colors, Record<'colors' | 'shadows', Partial<typeof primitives.colors.light>>
63
+ * @type Partial<typeof primitives.colors.light>
46
64
  */
47
- declare const colorSchemes: Record<keyof typeof primitives.colors, Record<'colors' | 'shadows', Partial<typeof primitives.colors.light>>>;
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>;
48
94
  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
+ };
49
103
  export {};