@primer/components 0.0.0-2021830153742 → 0.0.0-202183017829

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.
@@ -2,12 +2,10 @@ import { IconProps } from '@primer/octicons-react';
2
2
  import React from 'react';
3
3
  import { SxProp } from '../sx';
4
4
  import { ItemInput } from './List';
5
- import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
6
- import { AriaRole } from '../utils/types';
7
5
  /**
8
6
  * Contract for props passed to the `Item` component.
9
7
  */
10
- export interface ItemProps extends SxProp {
8
+ export interface ItemProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'id'>, SxProp {
11
9
  /**
12
10
  * Primary text which names an `Item`.
13
11
  */
@@ -70,18 +68,6 @@ export interface ItemProps extends SxProp {
70
68
  * An id associated with this item. Should be unique between items
71
69
  */
72
70
  id?: number | string;
73
- /**
74
- * Node to be included inside the item before the text.
75
- */
76
- children?: React.ReactNode;
77
- /**
78
- * The ARIA role describing the function of `List` component. `option` is a common value.
79
- */
80
- role?: AriaRole;
81
- /**
82
- * An item to pass back in the `onAction` callback, meant as
83
- */
84
- item?: ItemInput;
85
71
  }
86
72
  export declare const TextContainer: import("styled-components").StyledComponent<"span", any, {
87
73
  dangerouslySetInnerHtml?: React.DOMAttributes<HTMLDivElement>['dangerouslySetInnerHTML'];
@@ -89,4 +75,6 @@ export declare const TextContainer: import("styled-components").StyledComponent<
89
75
  /**
90
76
  * An actionable or selectable `Item` with an optional icon and description.
91
77
  */
92
- export declare const Item: PolymorphicForwardRefComponent<"div", ItemProps>;
78
+ export declare function Item(itemProps: Partial<ItemProps> & {
79
+ item?: ItemInput;
80
+ }): JSX.Element;
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Item = exports.TextContainer = void 0;
6
+ exports.Item = Item;
7
+ exports.TextContainer = void 0;
7
8
 
8
9
  var _octiconsReact = require("@primer/octicons-react");
9
10
 
@@ -110,7 +111,7 @@ const MainContent = _styledComponents.default.div.withConfig({
110
111
  const StyledItem = _styledComponents.default.div.withConfig({
111
112
  displayName: "Item__StyledItem",
112
113
  componentId: "jqpvy8-2"
113
- })(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], (0, _constants.get)('space.2'), (0, _constants.get)('radii.2'), ({
114
+ })(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], (0, _constants.get)('space.2'), (0, _constants.get)('radii.2'), ({
114
115
  variant,
115
116
  item
116
117
  }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).color, ({
@@ -177,9 +178,8 @@ const MultiSelectInput = _styledComponents.default.input.withConfig({
177
178
  */
178
179
 
179
180
 
180
- const Item = /*#__PURE__*/_react.default.forwardRef((itemProps, ref) => {
181
+ function Item(itemProps) {
181
182
  const {
182
- as: Component,
183
183
  text,
184
184
  description,
185
185
  descriptionVariant = 'inline',
@@ -235,8 +235,6 @@ const Item = /*#__PURE__*/_react.default.forwardRef((itemProps, ref) => {
235
235
  theme
236
236
  } = (0, _ThemeProvider.useTheme)();
237
237
  return /*#__PURE__*/_react.default.createElement(StyledItem, _extends({
238
- ref: ref,
239
- as: Component,
240
238
  tabIndex: disabled ? undefined : -1,
241
239
  variant: variant,
242
240
  showDivider: showDivider,
@@ -282,7 +280,6 @@ const Item = /*#__PURE__*/_react.default.forwardRef((itemProps, ref) => {
282
280
  variant: variant,
283
281
  disabled: disabled
284
282
  }, trailingText, TrailingIcon && /*#__PURE__*/_react.default.createElement(TrailingIcon, null)) : null));
285
- });
283
+ }
286
284
 
287
- exports.Item = Item;
288
- Item.displayName = 'ActionList.Item';
285
+ Item.displayName = "Item";
@@ -1,12 +1,9 @@
1
- import React, { Key } from 'react';
1
+ import React from 'react';
2
2
  import type { AriaRole } from '../utils/types';
3
3
  import { Group, GroupProps } from './Group';
4
- import { ItemProps } from './Item';
5
- declare type RenderItemFn = (props: ItemProps) => React.ReactElement;
6
- export declare type ItemInput = ItemProps | ((Partial<ItemProps> & {
7
- renderItem: RenderItemFn;
8
- }) & {
9
- key?: Key;
4
+ import { Item, ItemProps } from './Item';
5
+ export declare type ItemInput = ItemProps | (Partial<ItemProps> & {
6
+ renderItem: typeof Item;
10
7
  });
11
8
  /**
12
9
  * Contract for props passed to the `List` component.
@@ -29,7 +26,7 @@ export interface ListPropsBase {
29
26
  * without a `Group`-level or `Item`-level custom `Item` renderer will be
30
27
  * rendered using this function component.
31
28
  */
32
- renderItem?: RenderItemFn;
29
+ renderItem?: typeof Item;
33
30
  /**
34
31
  * A `List`-level custom `Group` renderer. Every `Group` within this `List`
35
32
  * without a `Group`-level custom `Item` renderer will be rendered using
@@ -61,7 +58,7 @@ export interface GroupedListProps extends ListPropsBase {
61
58
  * and `Group`-level custom `Item` or `Group` renderers.
62
59
  */
63
60
  groupMetadata: ((Omit<GroupProps, 'items'> | Omit<Partial<GroupProps> & {
64
- renderItem?: RenderItemFn;
61
+ renderItem?: typeof Item;
65
62
  renderGroup?: typeof Group;
66
63
  }, 'items'>) & {
67
64
  groupId: string;
@@ -71,7 +68,7 @@ export interface GroupedListProps extends ListPropsBase {
71
68
  * and `Item`-level custom `Item` renderers.
72
69
  */
73
70
  items: ((ItemProps | (Partial<ItemProps> & {
74
- renderItem: RenderItemFn;
71
+ renderItem: typeof Item;
75
72
  })) & {
76
73
  groupId: string;
77
74
  })[];
@@ -84,4 +81,3 @@ export declare type ListProps = ListPropsBase | GroupedListProps;
84
81
  * Lists `Item`s, either grouped or ungrouped, with a `Divider` between each `Group`.
85
82
  */
86
83
  export declare const List: React.ForwardRefExoticComponent<ListProps & React.RefAttributes<HTMLDivElement>>;
87
- export {};
@@ -106,11 +106,11 @@ const List = /*#__PURE__*/_react.default.forwardRef((props, forwardedRef) => {
106
106
 
107
107
 
108
108
  const renderItem = (itemProps, item, itemIndex) => {
109
- var _ref2, _ref3, _itemProps$id;
109
+ var _ref2, _itemProps$key, _itemProps$id;
110
110
 
111
111
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
112
112
  const ItemComponent = 'renderItem' in itemProps && itemProps.renderItem || props.renderItem || _Item.Item;
113
- const key = (_ref2 = (_ref3 = 'key' in itemProps ? itemProps.key : undefined) !== null && _ref3 !== void 0 ? _ref3 : (_itemProps$id = itemProps.id) === null || _itemProps$id === void 0 ? void 0 : _itemProps$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : itemIndex.toString();
113
+ const key = (_ref2 = (_itemProps$key = itemProps.key) !== null && _itemProps$key !== void 0 ? _itemProps$key : (_itemProps$id = itemProps.id) === null || _itemProps$id === void 0 ? void 0 : _itemProps$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : itemIndex.toString();
114
114
  return /*#__PURE__*/_react.default.createElement(ItemComponent, _extends({
115
115
  showDivider: props.showItemDividers,
116
116
  selectionVariant: props.selectionVariant
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Group } from './Group';
3
+ import { Item } from './Item';
3
4
  import { Divider } from './Divider';
4
5
  export type { ListProps as ActionListProps } from './List';
5
6
  export type { GroupProps } from './Group';
@@ -11,7 +12,7 @@ export declare const ActionList: import("react").ForwardRefExoticComponent<impor
11
12
  /** Collects related `Items` in an `ActionList`. */
12
13
  Group: typeof Group;
13
14
  /** An actionable or selectable `Item` with an optional icon and description. */
14
- Item: import("@radix-ui/react-polymorphic").ForwardRefComponent<"div", import("./Item").ItemProps>;
15
+ Item: typeof Item;
15
16
  /** Visually separates `Item`s or `Group`s in an `ActionList`. */
16
17
  Divider: typeof Divider;
17
18
  };
@@ -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, {
@@ -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.
@@ -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
- const autoFocusRef = (0, _react.useRef)(null);
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,
@@ -2,12 +2,10 @@ import { IconProps } from '@primer/octicons-react';
2
2
  import React from 'react';
3
3
  import { SxProp } from '../sx';
4
4
  import { ItemInput } from './List';
5
- import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
6
- import { AriaRole } from '../utils/types';
7
5
  /**
8
6
  * Contract for props passed to the `Item` component.
9
7
  */
10
- export interface ItemProps extends SxProp {
8
+ export interface ItemProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'id'>, SxProp {
11
9
  /**
12
10
  * Primary text which names an `Item`.
13
11
  */
@@ -70,18 +68,6 @@ export interface ItemProps extends SxProp {
70
68
  * An id associated with this item. Should be unique between items
71
69
  */
72
70
  id?: number | string;
73
- /**
74
- * Node to be included inside the item before the text.
75
- */
76
- children?: React.ReactNode;
77
- /**
78
- * The ARIA role describing the function of `List` component. `option` is a common value.
79
- */
80
- role?: AriaRole;
81
- /**
82
- * An item to pass back in the `onAction` callback, meant as
83
- */
84
- item?: ItemInput;
85
71
  }
86
72
  export declare const TextContainer: import("styled-components").StyledComponent<"span", any, {
87
73
  dangerouslySetInnerHtml?: React.DOMAttributes<HTMLDivElement>['dangerouslySetInnerHTML'];
@@ -89,4 +75,6 @@ export declare const TextContainer: import("styled-components").StyledComponent<
89
75
  /**
90
76
  * An actionable or selectable `Item` with an optional icon and description.
91
77
  */
92
- export declare const Item: PolymorphicForwardRefComponent<"div", ItemProps>;
78
+ export declare function Item(itemProps: Partial<ItemProps> & {
79
+ item?: ItemInput;
80
+ }): JSX.Element;
@@ -11,10 +11,10 @@ import { StyledDivider } from './Divider';
11
11
  import { useColorSchemeVar, useTheme } from '../ThemeProvider';
12
12
  import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
13
13
  import { useSSRSafeId } from '@react-aria/ssr';
14
-
15
14
  /**
16
15
  * These colors are not yet in our default theme. Need to remove this once they are added.
17
16
  */
17
+
18
18
  const customItemThemes = {
19
19
  default: {
20
20
  hover: {
@@ -85,7 +85,7 @@ const MainContent = styled.div.withConfig({
85
85
  const StyledItem = styled.div.withConfig({
86
86
  displayName: "Item__StyledItem",
87
87
  componentId: "jqpvy8-2"
88
- })(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], get('space.2'), get('radii.2'), ({
88
+ })(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], get('space.2'), get('radii.2'), ({
89
89
  variant,
90
90
  item
91
91
  }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).color, ({
@@ -144,9 +144,8 @@ const MultiSelectInput = styled.input.withConfig({
144
144
  * An actionable or selectable `Item` with an optional icon and description.
145
145
  */
146
146
 
147
- export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
147
+ export function Item(itemProps) {
148
148
  const {
149
- as: Component,
150
149
  text,
151
150
  description,
152
151
  descriptionVariant = 'inline',
@@ -202,8 +201,6 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
202
201
  theme
203
202
  } = useTheme();
204
203
  return /*#__PURE__*/React.createElement(StyledItem, _extends({
205
- ref: ref,
206
- as: Component,
207
204
  tabIndex: disabled ? undefined : -1,
208
205
  variant: variant,
209
206
  showDivider: showDivider,
@@ -249,5 +246,5 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
249
246
  variant: variant,
250
247
  disabled: disabled
251
248
  }, trailingText, TrailingIcon && /*#__PURE__*/React.createElement(TrailingIcon, null)) : null));
252
- });
253
- Item.displayName = 'ActionList.Item';
249
+ }
250
+ Item.displayName = "Item";
@@ -1,12 +1,9 @@
1
- import React, { Key } from 'react';
1
+ import React from 'react';
2
2
  import type { AriaRole } from '../utils/types';
3
3
  import { Group, GroupProps } from './Group';
4
- import { ItemProps } from './Item';
5
- declare type RenderItemFn = (props: ItemProps) => React.ReactElement;
6
- export declare type ItemInput = ItemProps | ((Partial<ItemProps> & {
7
- renderItem: RenderItemFn;
8
- }) & {
9
- key?: Key;
4
+ import { Item, ItemProps } from './Item';
5
+ export declare type ItemInput = ItemProps | (Partial<ItemProps> & {
6
+ renderItem: typeof Item;
10
7
  });
11
8
  /**
12
9
  * Contract for props passed to the `List` component.
@@ -29,7 +26,7 @@ export interface ListPropsBase {
29
26
  * without a `Group`-level or `Item`-level custom `Item` renderer will be
30
27
  * rendered using this function component.
31
28
  */
32
- renderItem?: RenderItemFn;
29
+ renderItem?: typeof Item;
33
30
  /**
34
31
  * A `List`-level custom `Group` renderer. Every `Group` within this `List`
35
32
  * without a `Group`-level custom `Item` renderer will be rendered using
@@ -61,7 +58,7 @@ export interface GroupedListProps extends ListPropsBase {
61
58
  * and `Group`-level custom `Item` or `Group` renderers.
62
59
  */
63
60
  groupMetadata: ((Omit<GroupProps, 'items'> | Omit<Partial<GroupProps> & {
64
- renderItem?: RenderItemFn;
61
+ renderItem?: typeof Item;
65
62
  renderGroup?: typeof Group;
66
63
  }, 'items'>) & {
67
64
  groupId: string;
@@ -71,7 +68,7 @@ export interface GroupedListProps extends ListPropsBase {
71
68
  * and `Item`-level custom `Item` renderers.
72
69
  */
73
70
  items: ((ItemProps | (Partial<ItemProps> & {
74
- renderItem: RenderItemFn;
71
+ renderItem: typeof Item;
75
72
  })) & {
76
73
  groupId: string;
77
74
  })[];
@@ -84,4 +81,3 @@ export declare type ListProps = ListPropsBase | GroupedListProps;
84
81
  * Lists `Item`s, either grouped or ungrouped, with a `Divider` between each `Group`.
85
82
  */
86
83
  export declare const List: React.ForwardRefExoticComponent<ListProps & React.RefAttributes<HTMLDivElement>>;
87
- export {};
@@ -90,11 +90,11 @@ export const List = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
90
90
 
91
91
 
92
92
  const renderItem = (itemProps, item, itemIndex) => {
93
- var _ref2, _ref3, _itemProps$id;
93
+ var _ref2, _itemProps$key, _itemProps$id;
94
94
 
95
95
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
96
96
  const ItemComponent = 'renderItem' in itemProps && itemProps.renderItem || props.renderItem || Item;
97
- const key = (_ref2 = (_ref3 = 'key' in itemProps ? itemProps.key : undefined) !== null && _ref3 !== void 0 ? _ref3 : (_itemProps$id = itemProps.id) === null || _itemProps$id === void 0 ? void 0 : _itemProps$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : itemIndex.toString();
97
+ const key = (_ref2 = (_itemProps$key = itemProps.key) !== null && _itemProps$key !== void 0 ? _itemProps$key : (_itemProps$id = itemProps.id) === null || _itemProps$id === void 0 ? void 0 : _itemProps$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : itemIndex.toString();
98
98
  return /*#__PURE__*/React.createElement(ItemComponent, _extends({
99
99
  showDivider: props.showItemDividers,
100
100
  selectionVariant: props.selectionVariant
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Group } from './Group';
3
+ import { Item } from './Item';
3
4
  import { Divider } from './Divider';
4
5
  export type { ListProps as ActionListProps } from './List';
5
6
  export type { GroupProps } from './Group';
@@ -11,7 +12,7 @@ export declare const ActionList: import("react").ForwardRefExoticComponent<impor
11
12
  /** Collects related `Items` in an `ActionList`. */
12
13
  Group: typeof Group;
13
14
  /** An actionable or selectable `Item` with an optional icon and description. */
14
- Item: import("@radix-ui/react-polymorphic").ForwardRefComponent<"div", import("./Item").ItemProps>;
15
+ Item: typeof Item;
15
16
  /** Visually separates `Item`s or `Group`s in an `ActionList`. */
16
17
  Divider: typeof Divider;
17
18
  };
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021830153742",
3
+ "version": "0.0.0-202183017829",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -45,7 +45,6 @@
45
45
  "dependencies": {
46
46
  "@primer/octicons-react": "^13.0.0",
47
47
  "@primer/primitives": "4.8.1",
48
- "@radix-ui/react-polymorphic": "0.0.14",
49
48
  "@react-aria/ssr": "3.1.0",
50
49
  "@styled-system/css": "5.1.5",
51
50
  "@styled-system/props": "5.1.5",
@@ -73,7 +72,7 @@
73
72
  "@changesets/cli": "2.17.0",
74
73
  "@github/prettier-config": "0.0.4",
75
74
  "@rollup/plugin-commonjs": "19.0.2",
76
- "@rollup/plugin-node-resolve": "13.0.0",
75
+ "@rollup/plugin-node-resolve": "13.0.5",
77
76
  "@size-limit/preset-big-lib": "5.0.2",
78
77
  "@storybook/addon-a11y": "6.3.4",
79
78
  "@storybook/addon-actions": "^6.2.9",
@@ -82,7 +81,7 @@
82
81
  "@storybook/react": "6.3.8",
83
82
  "@testing-library/dom": "7.31.2",
84
83
  "@testing-library/react": "11.2.7",
85
- "@testing-library/react-hooks": "7.0.0",
84
+ "@testing-library/react-hooks": "7.0.2",
86
85
  "@testing-library/user-event": "13.1.9",
87
86
  "@types/chroma-js": "2.1.3",
88
87
  "@types/enzyme": "3.10.9",
@@ -112,7 +111,7 @@
112
111
  "eslint-plugin-jsx-a11y": "6.4.1",
113
112
  "eslint-plugin-mdx": "1.15.1",
114
113
  "eslint-plugin-prettier": "3.4.0",
115
- "eslint-plugin-primer-react": "0.4.2",
114
+ "eslint-plugin-primer-react": "0.5.0",
116
115
  "eslint-plugin-react": "7.24.0",
117
116
  "eslint-plugin-react-hooks": "4.2.0",
118
117
  "jest": "27.0.4",