@primer/components 0.0.0-20211030175556 → 0.0.0-20211030182910

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.
Files changed (272) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/dist/browser.esm.js +186 -183
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +190 -187
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.js +3 -3
  7. package/lib/ActionList/index.js +23 -12
  8. package/lib/ActionList2/Item.js +3 -1
  9. package/lib/ActionList2/List.js +1 -2
  10. package/lib/ActionList2/Selection.js +3 -1
  11. package/lib/ActionList2/index.js +41 -23
  12. package/lib/AnchoredOverlay/index.js +12 -4
  13. package/lib/Autocomplete/Autocomplete.d.ts +1 -0
  14. package/lib/Autocomplete/AutocompleteInput.d.ts +1 -0
  15. package/lib/Autocomplete/index.js +14 -7
  16. package/lib/Avatar.d.ts +1 -2
  17. package/lib/Avatar.js +1 -1
  18. package/lib/BranchName.d.ts +1 -2
  19. package/lib/BranchName.js +1 -1
  20. package/lib/Button/Button.d.ts +1 -0
  21. package/lib/Button/ButtonClose.d.ts +2 -1
  22. package/lib/Button/ButtonDanger.d.ts +1 -0
  23. package/lib/Button/ButtonInvisible.d.ts +1 -0
  24. package/lib/Button/ButtonOutline.d.ts +1 -0
  25. package/lib/Button/ButtonPrimary.d.ts +1 -0
  26. package/lib/Button/index.js +70 -21
  27. package/lib/Checkbox.d.ts +29 -0
  28. package/lib/Checkbox.js +64 -0
  29. package/lib/CircleOcticon.d.ts +1 -0
  30. package/lib/Details.d.ts +1 -2
  31. package/lib/Details.js +1 -3
  32. package/lib/Dialog.d.ts +3 -2
  33. package/lib/Dropdown.d.ts +6 -66
  34. package/lib/DropdownMenu/DropdownButton.d.ts +2 -1
  35. package/lib/DropdownMenu/index.js +20 -6
  36. package/lib/DropdownStyles.js +26 -18
  37. package/lib/FilterList.d.ts +1 -0
  38. package/lib/FilteredActionList/index.js +12 -4
  39. package/lib/Heading.d.ts +1 -2
  40. package/lib/Heading.js +1 -6
  41. package/lib/NewButton/index.js +12 -5
  42. package/lib/NewButton/types.js +1 -2
  43. package/lib/Overlay.d.ts +5 -3
  44. package/lib/Pagination/index.js +12 -6
  45. package/lib/Portal/index.js +16 -5
  46. package/lib/Position.d.ts +4 -4
  47. package/lib/ProgressBar.d.ts +16 -11
  48. package/lib/ProgressBar.js +6 -10
  49. package/lib/SelectMenu/SelectMenu.d.ts +10 -4
  50. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  51. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  52. package/lib/SelectMenu/hooks/useKeyboardNav.js +96 -80
  53. package/lib/SelectMenu/index.js +14 -7
  54. package/lib/SelectPanel/index.js +12 -4
  55. package/lib/Spinner.d.ts +1 -2
  56. package/lib/Spinner.js +1 -3
  57. package/lib/TextInputWithTokens.d.ts +1 -0
  58. package/lib/Token/AvatarToken.d.ts +1 -1
  59. package/lib/Token/IssueLabelToken.d.ts +1 -1
  60. package/lib/Token/Token.d.ts +1 -1
  61. package/lib/Token/index.js +30 -11
  62. package/lib/behaviors/anchoredPosition.js +234 -205
  63. package/lib/behaviors/focusTrap.js +157 -121
  64. package/lib/behaviors/focusZone.js +509 -434
  65. package/lib/behaviors/scrollIntoViewingArea.js +35 -18
  66. package/lib/constants.js +43 -39
  67. package/lib/drafts.js +30 -20
  68. package/lib/hooks/index.js +60 -16
  69. package/lib/hooks/useAnchoredPosition.js +40 -32
  70. package/lib/hooks/useCombinedRefs.js +36 -32
  71. package/lib/hooks/useDialog.js +96 -72
  72. package/lib/hooks/useFocusTrap.js +60 -43
  73. package/lib/hooks/useFocusZone.js +50 -54
  74. package/lib/hooks/useOnEscapePress.js +36 -25
  75. package/lib/hooks/useOpenAndCloseFocus.js +34 -22
  76. package/lib/hooks/useProvidedRefOrCreate.js +14 -10
  77. package/lib/hooks/useProvidedStateOrCreate.js +16 -13
  78. package/lib/hooks/useRenderForcingRef.js +17 -13
  79. package/lib/hooks/useResizeObserver.js +18 -15
  80. package/lib/hooks/useSafeTimeout.js +30 -22
  81. package/lib/hooks/useScrollFlash.js +23 -16
  82. package/lib/index.d.ts +2 -0
  83. package/lib/index.js +652 -163
  84. package/lib/polyfills/eventListenerSignal.js +45 -37
  85. package/lib/sx.js +22 -10
  86. package/lib/theme-preval.js +3169 -64
  87. package/lib/theme.js +12 -3
  88. package/lib/utils/iterateFocusableElements.js +85 -63
  89. package/lib/utils/testing.d.ts +2 -1
  90. package/lib/utils/testing.js +29 -0
  91. package/lib/utils/theme.js +47 -33
  92. package/lib/utils/types/AriaRole.js +1 -2
  93. package/lib/utils/types/ComponentProps.js +1 -2
  94. package/lib/utils/types/Flatten.js +1 -2
  95. package/lib/utils/types/KeyPaths.js +1 -2
  96. package/lib/utils/types/MandateProps.js +1 -16
  97. package/lib/utils/types/Merge.js +1 -2
  98. package/lib/utils/types/index.js +69 -16
  99. package/lib/utils/uniqueId.js +8 -5
  100. package/lib/utils/use-force-update.js +14 -8
  101. package/lib/utils/useIsomorphicLayoutEffect.js +11 -8
  102. package/lib/utils/userAgent.js +12 -8
  103. package/lib-esm/ActionList/Item.js +3 -3
  104. package/lib-esm/ActionList2/Item.js +3 -1
  105. package/lib-esm/ActionList2/List.js +1 -2
  106. package/lib-esm/ActionList2/Selection.js +3 -1
  107. package/lib-esm/Autocomplete/Autocomplete.d.ts +1 -0
  108. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +1 -0
  109. package/lib-esm/Avatar.d.ts +1 -2
  110. package/lib-esm/Avatar.js +2 -2
  111. package/lib-esm/BranchName.d.ts +1 -2
  112. package/lib-esm/BranchName.js +2 -2
  113. package/lib-esm/Button/Button.d.ts +1 -0
  114. package/lib-esm/Button/ButtonClose.d.ts +2 -1
  115. package/lib-esm/Button/ButtonDanger.d.ts +1 -0
  116. package/lib-esm/Button/ButtonInvisible.d.ts +1 -0
  117. package/lib-esm/Button/ButtonOutline.d.ts +1 -0
  118. package/lib-esm/Button/ButtonPrimary.d.ts +1 -0
  119. package/lib-esm/Checkbox.d.ts +29 -0
  120. package/lib-esm/Checkbox.js +44 -0
  121. package/lib-esm/CircleOcticon.d.ts +1 -0
  122. package/lib-esm/Details.d.ts +1 -2
  123. package/lib-esm/Details.js +1 -2
  124. package/lib-esm/Dialog.d.ts +3 -2
  125. package/lib-esm/Dropdown.d.ts +6 -66
  126. package/lib-esm/DropdownMenu/DropdownButton.d.ts +2 -1
  127. package/lib-esm/FilterList.d.ts +1 -0
  128. package/lib-esm/Heading.d.ts +1 -2
  129. package/lib-esm/Heading.js +2 -6
  130. package/lib-esm/Overlay.d.ts +5 -3
  131. package/lib-esm/Position.d.ts +4 -4
  132. package/lib-esm/ProgressBar.d.ts +16 -11
  133. package/lib-esm/ProgressBar.js +7 -11
  134. package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -4
  135. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  136. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  137. package/lib-esm/Spinner.d.ts +1 -2
  138. package/lib-esm/Spinner.js +1 -2
  139. package/lib-esm/TextInputWithTokens.d.ts +1 -0
  140. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  141. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  142. package/lib-esm/Token/Token.d.ts +1 -1
  143. package/lib-esm/index.d.ts +2 -0
  144. package/lib-esm/index.js +1 -0
  145. package/lib-esm/theme-preval.js +446 -0
  146. package/lib-esm/utils/testing.d.ts +2 -1
  147. package/lib-esm/utils/testing.js +24 -0
  148. package/package.json +4 -5
  149. package/lib/ActionList/Divider.jsx +0 -29
  150. package/lib/ActionList/Group.jsx +0 -23
  151. package/lib/ActionList/Header.jsx +0 -66
  152. package/lib/ActionList/Item.jsx +0 -288
  153. package/lib/ActionList/List.jsx +0 -138
  154. package/lib/ActionList2/Description.jsx +0 -29
  155. package/lib/ActionList2/Divider.jsx +0 -22
  156. package/lib/ActionList2/Group.jsx +0 -54
  157. package/lib/ActionList2/Header.d.ts +0 -26
  158. package/lib/ActionList2/Header.js +0 -55
  159. package/lib/ActionList2/Header.jsx +0 -36
  160. package/lib/ActionList2/Item.jsx +0 -174
  161. package/lib/ActionList2/LinkItem.jsx +0 -28
  162. package/lib/ActionList2/List.jsx +0 -41
  163. package/lib/ActionList2/Selection.jsx +0 -50
  164. package/lib/ActionList2/Visuals.jsx +0 -48
  165. package/lib/ActionMenu.jsx +0 -73
  166. package/lib/AnchoredOverlay/AnchoredOverlay.jsx +0 -100
  167. package/lib/Autocomplete/Autocomplete.jsx +0 -100
  168. package/lib/Autocomplete/AutocompleteContext.jsx +0 -5
  169. package/lib/Autocomplete/AutocompleteInput.jsx +0 -113
  170. package/lib/Autocomplete/AutocompleteMenu.jsx +0 -190
  171. package/lib/Autocomplete/AutocompleteOverlay.jsx +0 -55
  172. package/lib/Avatar.jsx +0 -34
  173. package/lib/AvatarPair.jsx +0 -29
  174. package/lib/AvatarStack.jsx +0 -151
  175. package/lib/BaseStyles.jsx +0 -65
  176. package/lib/BorderBox.jsx +0 -18
  177. package/lib/Box.jsx +0 -10
  178. package/lib/BranchName.jsx +0 -20
  179. package/lib/Breadcrumbs.jsx +0 -71
  180. package/lib/Button/Button.jsx +0 -40
  181. package/lib/Button/ButtonBase.jsx +0 -33
  182. package/lib/Button/ButtonClose.jsx +0 -53
  183. package/lib/Button/ButtonDanger.jsx +0 -43
  184. package/lib/Button/ButtonGroup.jsx +0 -55
  185. package/lib/Button/ButtonInvisible.jsx +0 -32
  186. package/lib/Button/ButtonOutline.jsx +0 -43
  187. package/lib/Button/ButtonPrimary.jsx +0 -42
  188. package/lib/Button/ButtonStyles.jsx +0 -37
  189. package/lib/Button/ButtonTableList.jsx +0 -46
  190. package/lib/Caret.jsx +0 -93
  191. package/lib/CircleBadge.jsx +0 -42
  192. package/lib/CircleOcticon.jsx +0 -21
  193. package/lib/CounterLabel.jsx +0 -43
  194. package/lib/Details.jsx +0 -21
  195. package/lib/Dialog/ConfirmationDialog.jsx +0 -146
  196. package/lib/Dialog/Dialog.jsx +0 -279
  197. package/lib/Dialog.jsx +0 -129
  198. package/lib/Dropdown.jsx +0 -131
  199. package/lib/DropdownMenu/DropdownButton.jsx +0 -14
  200. package/lib/DropdownMenu/DropdownMenu.jsx +0 -70
  201. package/lib/FilterList.jsx +0 -59
  202. package/lib/FilteredActionList/FilteredActionList.jsx +0 -100
  203. package/lib/FilteredSearch.jsx +0 -28
  204. package/lib/Flash.jsx +0 -69
  205. package/lib/Flex.jsx +0 -15
  206. package/lib/FormGroup.jsx +0 -22
  207. package/lib/Grid.jsx +0 -15
  208. package/lib/Header.jsx +0 -83
  209. package/lib/Heading.jsx +0 -21
  210. package/lib/Label.jsx +0 -82
  211. package/lib/LabelGroup.jsx +0 -18
  212. package/lib/Link.jsx +0 -36
  213. package/lib/NewButton/button-counter.jsx +0 -14
  214. package/lib/NewButton/button.jsx +0 -279
  215. package/lib/Overlay.jsx +0 -154
  216. package/lib/Pagehead.jsx +0 -17
  217. package/lib/Pagination/Pagination.jsx +0 -161
  218. package/lib/Pagination/model.jsx +0 -174
  219. package/lib/PointerBox.jsx +0 -25
  220. package/lib/Popover.jsx +0 -202
  221. package/lib/Portal/Portal.jsx +0 -79
  222. package/lib/Position.jsx +0 -46
  223. package/lib/ProgressBar.jsx +0 -39
  224. package/lib/SelectMenu/SelectMenu.jsx +0 -112
  225. package/lib/SelectMenu/SelectMenuContext.jsx +0 -5
  226. package/lib/SelectMenu/SelectMenuDivider.jsx +0 -42
  227. package/lib/SelectMenu/SelectMenuFilter.jsx +0 -58
  228. package/lib/SelectMenu/SelectMenuFooter.jsx +0 -45
  229. package/lib/SelectMenu/SelectMenuHeader.jsx +0 -42
  230. package/lib/SelectMenu/SelectMenuItem.jsx +0 -142
  231. package/lib/SelectMenu/SelectMenuList.jsx +0 -59
  232. package/lib/SelectMenu/SelectMenuLoadingAnimation.jsx +0 -22
  233. package/lib/SelectMenu/SelectMenuModal.jsx +0 -118
  234. package/lib/SelectMenu/SelectMenuTab.jsx +0 -92
  235. package/lib/SelectMenu/SelectMenuTabPanel.jsx +0 -42
  236. package/lib/SelectMenu/SelectMenuTabs.jsx +0 -57
  237. package/lib/SelectPanel/SelectPanel.jsx +0 -105
  238. package/lib/SideNav.jsx +0 -173
  239. package/lib/Spinner.jsx +0 -35
  240. package/lib/StateLabel.jsx +0 -93
  241. package/lib/StyledOcticon.jsx +0 -18
  242. package/lib/SubNav.jsx +0 -101
  243. package/lib/TabNav.jsx +0 -58
  244. package/lib/Text.jsx +0 -14
  245. package/lib/TextInput.jsx +0 -23
  246. package/lib/TextInputWithTokens.jsx +0 -218
  247. package/lib/ThemeProvider.jsx +0 -130
  248. package/lib/Timeline.jsx +0 -123
  249. package/lib/Token/AvatarToken.jsx +0 -54
  250. package/lib/Token/IssueLabelToken.jsx +0 -125
  251. package/lib/Token/Token.jsx +0 -103
  252. package/lib/Token/TokenBase.jsx +0 -88
  253. package/lib/Token/_RemoveTokenButton.jsx +0 -108
  254. package/lib/Token/_TokenTextContainer.jsx +0 -49
  255. package/lib/Tooltip.jsx +0 -246
  256. package/lib/Truncate.jsx +0 -24
  257. package/lib/UnderlineNav.jsx +0 -88
  258. package/lib/_TextInputWrapper.jsx +0 -120
  259. package/lib/_UnstyledTextInput.jsx +0 -22
  260. package/lib/hooks/useDetails.jsx +0 -39
  261. package/lib/hooks/useOnOutsideClick.jsx +0 -61
  262. package/lib/hooks/useOverlay.jsx +0 -15
  263. package/lib/utils/create-slots.jsx +0 -65
  264. package/lib/utils/deprecate.jsx +0 -59
  265. package/lib/utils/isNumeric.jsx +0 -7
  266. package/lib/utils/ssr.jsx +0 -6
  267. package/lib/utils/test-deprecations.jsx +0 -20
  268. package/lib/utils/test-helpers.jsx +0 -8
  269. package/lib/utils/test-matchers.jsx +0 -100
  270. package/lib/utils/testing.jsx +0 -206
  271. package/lib-esm/ActionList2/Header.d.ts +0 -26
  272. package/lib-esm/ActionList2/Header.js +0 -44
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const Box_1 = __importDefault(require("./Box"));
8
- function CircleOcticon(props) {
9
- const { size, as } = props;
10
- const { icon: IconComponent, bg, ...rest } = props;
11
- return (<Box_1.default as={as} bg={bg} overflow="hidden" borderWidth={0} size={size} borderRadius="50%" borderStyle="solid" borderColor="border.default">
12
- <Box_1.default display="flex" {...rest} alignItems="center" justifyContent="center">
13
- <IconComponent size={size}/>
14
- </Box_1.default>
15
- </Box_1.default>);
16
- }
17
- CircleOcticon.defaultProps = {
18
- ...Box_1.default.defaultProps,
19
- size: 32
20
- };
21
- exports.default = CircleOcticon;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const styled_components_1 = __importDefault(require("styled-components"));
7
- const constants_1 = require("./constants");
8
- const sx_1 = __importDefault(require("./sx"));
9
- const colorStyles = ({ scheme, ...props }) => {
10
- return {
11
- color: scheme === 'secondary'
12
- ? constants_1.get('colors.fg.default')(props)
13
- : scheme === 'primary'
14
- ? constants_1.get('colors.fg.onEmphasis')(props)
15
- : constants_1.get('colors.fg.default')(props)
16
- };
17
- };
18
- const bgStyles = ({ scheme, ...props }) => {
19
- return {
20
- backgroundColor: scheme === 'secondary'
21
- ? constants_1.get('colors.neutral.muted')(props)
22
- : scheme === 'primary'
23
- ? constants_1.get('colors.neutral.emphasis')(props)
24
- : constants_1.get('colors.neutral.muted')(props)
25
- };
26
- };
27
- const CounterLabel = styled_components_1.default.span `
28
- display: inline-block;
29
- padding: 2px 5px;
30
- font-size: ${constants_1.get('fontSizes.0')};
31
- font-weight: ${constants_1.get('fontWeights.bold')};
32
- line-height: ${constants_1.get('lineHeights.condensedUltra')};
33
- border-radius: 20px;
34
- ${colorStyles};
35
- ${bgStyles};
36
-
37
- &:empty {
38
- display: none;
39
- }
40
-
41
- ${sx_1.default};
42
- `;
43
- exports.default = CounterLabel;
package/lib/Details.jsx DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const styled_components_1 = __importDefault(require("styled-components"));
7
- const constants_1 = require("./constants");
8
- const sx_1 = __importDefault(require("./sx"));
9
- const Details = styled_components_1.default.details `
10
- & > summary {
11
- list-style: none;
12
- }
13
- & > summary::-webkit-details-marker {
14
- display: none;
15
- }
16
-
17
- ${constants_1.COMMON}
18
- ${sx_1.default};
19
- `;
20
- Details.displayName = 'Details';
21
- exports.default = Details;
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.useConfirm = exports.ConfirmationDialog = void 0;
26
- const react_1 = __importStar(require("react"));
27
- const react_dom_1 = __importDefault(require("react-dom"));
28
- const styled_components_1 = __importDefault(require("styled-components"));
29
- const Box_1 = __importDefault(require("../Box"));
30
- const ThemeProvider_1 = require("../ThemeProvider");
31
- const focusZone_1 = require("../behaviors/focusZone");
32
- const constants_1 = require("../constants");
33
- const Dialog_1 = require("../Dialog/Dialog");
34
- const useFocusZone_1 = require("../hooks/useFocusZone");
35
- const StyledConfirmationHeader = styled_components_1.default.header `
36
- padding: ${constants_1.get('space.2')};
37
- display: flex;
38
- flex-direction: row;
39
- `;
40
- const StyledTitle = styled_components_1.default(Box_1.default) `
41
- font-size: ${constants_1.get('fontSizes.3')};
42
- font-weight: ${constants_1.get('fontWeights.bold')};
43
- padding: 6px ${constants_1.get('space.2')};
44
- flex-grow: 1;
45
- `;
46
- const ConfirmationHeader = ({ title, onClose, dialogLabelId }) => {
47
- const onCloseClick = react_1.useCallback(() => {
48
- onClose('close-button');
49
- }, [onClose]);
50
- return (<StyledConfirmationHeader>
51
- <StyledTitle id={dialogLabelId}>{title}</StyledTitle>
52
- <Dialog_1.Dialog.CloseButton onClose={onCloseClick}/>
53
- </StyledConfirmationHeader>);
54
- };
55
- const StyledConfirmationBody = styled_components_1.default(Box_1.default) `
56
- font-size: ${constants_1.get('fontSizes.1')};
57
- padding: 0 ${constants_1.get('space.3')} ${constants_1.get('space.3')} ${constants_1.get('space.3')};
58
- color: ${constants_1.get('colors.fg.muted')};
59
- flex-grow: 1;
60
- `;
61
- const ConfirmationBody = ({ children }) => {
62
- return <StyledConfirmationBody>{children}</StyledConfirmationBody>;
63
- };
64
- const StyledConfirmationFooter = styled_components_1.default(Box_1.default) `
65
- display: grid;
66
- grid-auto-flow: column;
67
- grid-auto-columns: max-content;
68
- grid-gap: ${constants_1.get('space.2')};
69
- align-items: end;
70
- justify-content: end;
71
- padding: ${constants_1.get('space.1')} ${constants_1.get('space.3')} ${constants_1.get('space.3')};
72
- `;
73
- const ConfirmationFooter = ({ footerButtons }) => {
74
- const { containerRef: footerRef } = useFocusZone_1.useFocusZone({
75
- bindKeys: focusZone_1.FocusKeys.ArrowHorizontal | focusZone_1.FocusKeys.Tab,
76
- focusInStrategy: 'closest'
77
- });
78
- // Must have exactly 2 buttons!
79
- return (<StyledConfirmationFooter ref={footerRef}>
80
- <Dialog_1.Dialog.Buttons buttons={footerButtons ?? []}/>
81
- </StyledConfirmationFooter>);
82
- };
83
- /**
84
- * A ConfirmationDialog is a special kind of dialog with more rigid behavior. It
85
- * is used to confirm a user action. ConfirmationDialogs always have exactly
86
- * two buttons: one to cancel the action and one to confirm it. No custom
87
- * rendering capabilities are provided for ConfirmationDialog.
88
- */
89
- const ConfirmationDialog = props => {
90
- const { onClose, title, cancelButtonContent = 'Cancel', confirmButtonContent = 'OK', confirmButtonType = 'normal', children } = props;
91
- const onCancelButtonClick = react_1.useCallback(() => {
92
- onClose('cancel');
93
- }, [onClose]);
94
- const onConfirmButtonClick = react_1.useCallback(() => {
95
- onClose('confirm');
96
- }, [onClose]);
97
- const cancelButton = {
98
- content: cancelButtonContent,
99
- onClick: onCancelButtonClick
100
- };
101
- const confirmButton = {
102
- content: confirmButtonContent,
103
- buttonType: confirmButtonType,
104
- onClick: onConfirmButtonClick,
105
- autoFocus: true
106
- };
107
- const footerButtons = [cancelButton, confirmButton];
108
- return (<Dialog_1.Dialog onClose={onClose} title={title} footerButtons={footerButtons} role="alertdialog" width="medium" renderHeader={ConfirmationHeader} renderBody={ConfirmationBody} renderFooter={ConfirmationFooter}>
109
- {children}
110
- </Dialog_1.Dialog>);
111
- };
112
- exports.ConfirmationDialog = ConfirmationDialog;
113
- async function confirm(themeProps, options) {
114
- const { content, ...confirmationDialogProps } = options;
115
- return new Promise(resolve => {
116
- const hostElement = document.createElement('div');
117
- const onClose = gesture => {
118
- react_dom_1.default.unmountComponentAtNode(hostElement);
119
- if (gesture === 'confirm') {
120
- resolve(true);
121
- }
122
- else {
123
- resolve(false);
124
- }
125
- };
126
- react_dom_1.default.render(<ThemeProvider_1.ThemeProvider {...themeProps}>
127
- <exports.ConfirmationDialog {...confirmationDialogProps} onClose={onClose}>
128
- {content}
129
- </exports.ConfirmationDialog>
130
- </ThemeProvider_1.ThemeProvider>, hostElement);
131
- });
132
- }
133
- /**
134
- * This hook takes no parameters and returns an `async` function, `confirm`. When `confirm`
135
- * is called, it shows the confirmation dialog. When the dialog is dismissed, a promise is
136
- * resolved with `true` or `false` depending on whether or not the confirm button was used.
137
- */
138
- function useConfirm() {
139
- const { theme, colorMode, dayScheme, nightScheme } = ThemeProvider_1.useTheme();
140
- const result = react_1.useCallback((options) => {
141
- const themeProps = { theme, colorMode, dayScheme, nightScheme };
142
- return confirm(themeProps, options);
143
- }, [theme, colorMode, dayScheme, nightScheme]);
144
- return result;
145
- }
146
- exports.useConfirm = useConfirm;
@@ -1,279 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Dialog = void 0;
26
- const react_1 = __importStar(require("react"));
27
- const styled_components_1 = __importDefault(require("styled-components"));
28
- const Button_1 = __importStar(require("../Button"));
29
- const Box_1 = __importDefault(require("../Box"));
30
- const constants_1 = require("../constants");
31
- const hooks_1 = require("../hooks");
32
- const useFocusTrap_1 = require("../hooks/useFocusTrap");
33
- const sx_1 = __importDefault(require("../sx"));
34
- const StyledOcticon_1 = __importDefault(require("../StyledOcticon"));
35
- const octicons_react_1 = require("@primer/octicons-react");
36
- const useFocusZone_1 = require("../hooks/useFocusZone");
37
- const focusZone_1 = require("../behaviors/focusZone");
38
- const Portal_1 = __importDefault(require("../Portal"));
39
- const useCombinedRefs_1 = require("../hooks/useCombinedRefs");
40
- const ssr_1 = require("@react-aria/ssr");
41
- const ANIMATION_DURATION = '200ms';
42
- const Backdrop = styled_components_1.default('div') `
43
- position: fixed;
44
- top: 0;
45
- left: 0;
46
- bottom: 0;
47
- right: 0;
48
- display: flex;
49
- align-items: center;
50
- justify-content: center;
51
- background-color: rgba(0, 0, 0, 0.4);
52
- animation: dialog-backdrop-appear ${ANIMATION_DURATION} ${constants_1.get('animation.easeOutCubic')};
53
-
54
- @keyframes dialog-backdrop-appear {
55
- 0% {
56
- opacity: 0;
57
- }
58
- 100% {
59
- opacity: 1;
60
- }
61
- }
62
- `;
63
- const heightMap = {
64
- small: '480px',
65
- large: '640px',
66
- auto: 'auto'
67
- };
68
- const widthMap = {
69
- small: '296px',
70
- medium: '320px',
71
- large: '480px',
72
- xlarge: '640px'
73
- };
74
- const StyledDialog = styled_components_1.default.div `
75
- display: flex;
76
- flex-direction: column;
77
- background-color: ${constants_1.get('colors.canvas.overlay')};
78
- box-shadow: ${constants_1.get('shadows.overlay.shadow')};
79
- min-width: 296px;
80
- max-width: calc(100vw - 64px);
81
- max-height: calc(100vh - 64px);
82
- width: ${props => widthMap[props.width ?? 'xlarge']};
83
- height: ${props => heightMap[props.height ?? 'auto']};
84
- border-radius: 12px;
85
- opacity: 1;
86
- animation: overlay--dialog-appear ${ANIMATION_DURATION} ${constants_1.get('animation.easeOutCubic')};
87
-
88
- @keyframes overlay--dialog-appear {
89
- 0% {
90
- opacity: 0;
91
- transform: scale(0.5);
92
- }
93
- 100% {
94
- opacity: 1;
95
- transform: scale(1);
96
- }
97
- }
98
-
99
- ${sx_1.default};
100
- `;
101
- const DefaultHeader = ({ dialogLabelId, title, subtitle, dialogDescriptionId, onClose }) => {
102
- const onCloseClick = react_1.useCallback(() => {
103
- onClose('close-button');
104
- }, [onClose]);
105
- return (<exports.Dialog.Header>
106
- <Box_1.default display="flex">
107
- <Box_1.default display="flex" px={2} py="6px" flexDirection="column" flexGrow={1}>
108
- <exports.Dialog.Title id={dialogLabelId}>{title ?? 'Dialog'}</exports.Dialog.Title>
109
- {subtitle && <exports.Dialog.Subtitle id={dialogDescriptionId}>{subtitle}</exports.Dialog.Subtitle>}
110
- </Box_1.default>
111
- <exports.Dialog.CloseButton onClose={onCloseClick}/>
112
- </Box_1.default>
113
- </exports.Dialog.Header>);
114
- };
115
- const DefaultBody = ({ children }) => {
116
- return <exports.Dialog.Body>{children}</exports.Dialog.Body>;
117
- };
118
- const DefaultFooter = ({ footerButtons }) => {
119
- const { containerRef: footerRef } = useFocusZone_1.useFocusZone({
120
- bindKeys: focusZone_1.FocusKeys.ArrowHorizontal | focusZone_1.FocusKeys.Tab,
121
- focusInStrategy: 'closest'
122
- });
123
- return footerButtons ? (<exports.Dialog.Footer ref={footerRef}>
124
- <exports.Dialog.Buttons buttons={footerButtons}/>
125
- </exports.Dialog.Footer>) : null;
126
- };
127
- const _Dialog = react_1.default.forwardRef((props, forwardedRef) => {
128
- const { title = 'Dialog', subtitle = '', renderHeader, renderBody, renderFooter, onClose, role = 'dialog', width = 'xlarge', height = 'auto', footerButtons = [] } = props;
129
- const dialogLabelId = ssr_1.useSSRSafeId();
130
- const dialogDescriptionId = ssr_1.useSSRSafeId();
131
- const autoFocusedFooterButtonRef = react_1.useRef(null);
132
- for (const footerButton of footerButtons) {
133
- if (footerButton.autoFocus) {
134
- footerButton.ref = autoFocusedFooterButtonRef;
135
- }
136
- }
137
- const defaultedProps = { ...props, title, subtitle, role, dialogLabelId, dialogDescriptionId };
138
- const dialogRef = react_1.useRef(null);
139
- const combinedRef = useCombinedRefs_1.useCombinedRefs(dialogRef, forwardedRef);
140
- const backdropRef = react_1.useRef(null);
141
- useFocusTrap_1.useFocusTrap({ containerRef: dialogRef, restoreFocusOnCleanUp: true, initialFocusRef: autoFocusedFooterButtonRef });
142
- hooks_1.useOnEscapePress((event) => {
143
- onClose('escape');
144
- event.preventDefault();
145
- }, [onClose]);
146
- const header = (renderHeader ?? DefaultHeader)(defaultedProps);
147
- const body = (renderBody ?? DefaultBody)(defaultedProps);
148
- const footer = (renderFooter ?? DefaultFooter)(defaultedProps);
149
- return (<>
150
- <Portal_1.default>
151
- <Backdrop ref={backdropRef}>
152
- <StyledDialog width={width} height={height} ref={combinedRef} role={role} aria-labelledby={dialogLabelId} aria-describedby={dialogDescriptionId}>
153
- {header}
154
- {body}
155
- {footer}
156
- </StyledDialog>
157
- </Backdrop>
158
- </Portal_1.default>
159
- </>);
160
- });
161
- _Dialog.displayName = 'Dialog';
162
- const Header = styled_components_1.default.div.attrs({ as: 'header' }) `
163
- box-shadow: 0 1px 0 ${constants_1.get('colors.border.default')};
164
- padding: ${constants_1.get('space.2')};
165
- z-index: 1;
166
- flex-shrink: 0;
167
- `;
168
- const Title = styled_components_1.default.div `
169
- font-size: ${constants_1.get('fontSizes.1')};
170
- font-weight: ${constants_1.get('fontWeights.bold')};
171
-
172
- ${sx_1.default};
173
- `;
174
- const Subtitle = styled_components_1.default.div `
175
- font-size: ${constants_1.get('fontSizes.0')};
176
- margin-top: ${constants_1.get('space.1')};
177
- color: ${constants_1.get('colors.fg.muted')};
178
-
179
- ${sx_1.default};
180
- `;
181
- const Body = styled_components_1.default.div `
182
- flex-grow: 1;
183
- overflow: auto;
184
- padding: ${constants_1.get('space.3')};
185
-
186
- ${sx_1.default};
187
- `;
188
- const Footer = styled_components_1.default.div.attrs({ as: 'footer' }) `
189
- box-shadow: 0 -1px 0 ${constants_1.get('colors.border.default')};
190
- padding: ${constants_1.get('space.3')};
191
- display: flex;
192
- flex-flow: wrap;
193
- justify-content: flex-end;
194
- z-index: 1;
195
- flex-shrink: 0;
196
-
197
- button {
198
- margin-left: ${constants_1.get('space.1')};
199
- &:first-child {
200
- margin-left: 0;
201
- }
202
- }
203
-
204
- ${sx_1.default};
205
- `;
206
- const buttonTypes = {
207
- normal: Button_1.default,
208
- primary: Button_1.ButtonPrimary,
209
- danger: Button_1.ButtonDanger
210
- };
211
- const Buttons = ({ buttons }) => {
212
- const autoFocusRef = hooks_1.useProvidedRefOrCreate(buttons.find(button => button.autoFocus)?.ref);
213
- let autoFocusCount = 0;
214
- const [hasRendered, setHasRendered] = react_1.useState(0);
215
- react_1.useEffect(() => {
216
- // hack to work around dialogs originating from other focus traps.
217
- if (hasRendered === 1) {
218
- autoFocusRef.current?.focus();
219
- }
220
- else {
221
- setHasRendered(hasRendered + 1);
222
- }
223
- }, [autoFocusRef, hasRendered]);
224
- return (<>
225
- {buttons.map((dialogButtonProps, index) => {
226
- const { content, buttonType = 'normal', autoFocus = false, ...buttonProps } = dialogButtonProps;
227
- const ButtonElement = buttonTypes[buttonType];
228
- return (<ButtonElement key={index} {...buttonProps} variant={buttonType} ref={autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null}>
229
- {content}
230
- </ButtonElement>);
231
- })}
232
- </>);
233
- };
234
- const DialogCloseButton = styled_components_1.default(Button_1.default) `
235
- border-radius: 4px;
236
- background: transparent;
237
- border: 0;
238
- vertical-align: middle;
239
- color: ${constants_1.get('colors.fg.muted')};
240
- padding: ${constants_1.get('space.2')};
241
- align-self: flex-start;
242
- line-height: normal;
243
- box-shadow: none;
244
- `;
245
- const CloseButton = ({ onClose }) => {
246
- return (<DialogCloseButton aria-label="Close" onClick={onClose}>
247
- <StyledOcticon_1.default icon={octicons_react_1.XIcon}/>
248
- </DialogCloseButton>);
249
- };
250
- /**
251
- * A dialog is a type of overlay that can be used for confirming actions, asking
252
- * for disambiguation, and presenting small forms. They generally allow the user
253
- * to focus on a quick task without having to navigate to a different page.
254
- *
255
- * Dialogs appear in the page after a direct user interaction. Don't show dialogs
256
- * on page load or as system alerts.
257
- *
258
- * Dialogs appear centered in the page, with a visible backdrop that dims the rest
259
- * of the window for focus.
260
- *
261
- * All dialogs have a title and a close button.
262
- *
263
- * Dialogs are modal. Dialogs can be dismissed by clicking on the close button,
264
- * pressing the escape key, or by interacting with another button in the dialog.
265
- * To avoid losing information and missing important messages, clicking outside
266
- * of the dialog will not close it.
267
- *
268
- * The sub components provided (e.g. Header, Title, etc.) are available for custom
269
- * renderers only. They are not intended to be used otherwise.
270
- */
271
- exports.Dialog = Object.assign(_Dialog, {
272
- Header,
273
- Title,
274
- Subtitle,
275
- Body,
276
- Footer,
277
- Buttons,
278
- CloseButton
279
- });
package/lib/Dialog.jsx DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const react_1 = __importStar(require("react"));
26
- const styled_components_1 = __importDefault(require("styled-components"));
27
- const ButtonClose_1 = __importDefault(require("./Button/ButtonClose"));
28
- const constants_1 = require("./constants");
29
- const Box_1 = __importDefault(require("./Box"));
30
- const useDialog_1 = __importDefault(require("./hooks/useDialog"));
31
- const sx_1 = __importDefault(require("./sx"));
32
- const Text_1 = __importDefault(require("./Text"));
33
- const useCombinedRefs_1 = require("./hooks/useCombinedRefs");
34
- const noop = () => null;
35
- const DialogBase = styled_components_1.default.div `
36
- box-shadow: ${constants_1.get('shadows.shadow.large')};
37
- border-radius: ${constants_1.get('radii.2')};
38
- position: fixed;
39
- top: 0;
40
- left: 50%;
41
- transform: translateX(-50%);
42
- max-height: 80vh;
43
- z-index: 999;
44
- margin: 10vh auto;
45
- background-color: ${constants_1.get('colors.canvas.default')};
46
- width: ${props => (props.narrow ? '320px' : props.wide ? '640px' : '440px')};
47
- outline: none;
48
-
49
- @media screen and (max-width: 750px) {
50
- width: 100vw;
51
- margin: 0;
52
- border-radius: 0;
53
- height: 100vh;
54
- }
55
-
56
- ${sx_1.default};
57
- `;
58
- const DialogHeaderBase = styled_components_1.default(Box_1.default) `
59
- border-radius: ${constants_1.get('radii.2')} ${constants_1.get('radii.2')} 0px 0px;
60
- border-bottom: 1px solid ${constants_1.get('colors.border.default')};
61
- display: flex;
62
-
63
- @media screen and (max-width: 750px) {
64
- border-radius: 0px;
65
- }
66
-
67
- ${sx_1.default};
68
- `;
69
- function DialogHeader({ theme, children, backgroundColor = 'gray.1', ...rest }) {
70
- if (react_1.default.Children.toArray(children).every(ch => typeof ch === 'string')) {
71
- children = (<Text_1.default theme={theme} color="fg.default" fontSize={1} fontWeight="bold" fontFamily="sans-serif">
72
- {children}
73
- </Text_1.default>);
74
- }
75
- return (<DialogHeaderBase theme={theme} p={3} backgroundColor={backgroundColor} {...rest}>
76
- {children}
77
- </DialogHeaderBase>);
78
- }
79
- const Overlay = styled_components_1.default.span `
80
- &:before {
81
- position: fixed;
82
- top: 0;
83
- right: 0;
84
- bottom: 0;
85
- left: 0;
86
- display: block;
87
- cursor: default;
88
- content: ' ';
89
- background: transparent;
90
- z-index: 99;
91
- background: ${constants_1.get('colors.primer.canvas.backdrop')};
92
- }
93
- `;
94
- const Dialog = react_1.forwardRef(({ children, onDismiss = noop, isOpen, initialFocusRef, returnFocusRef, ...props }, forwardedRef) => {
95
- const overlayRef = react_1.useRef(null);
96
- const modalRef = useCombinedRefs_1.useCombinedRefs(forwardedRef);
97
- const closeButtonRef = react_1.useRef(null);
98
- const onCloseClick = () => {
99
- onDismiss();
100
- if (returnFocusRef && returnFocusRef.current) {
101
- returnFocusRef.current.focus();
102
- }
103
- };
104
- const { getDialogProps } = useDialog_1.default({
105
- modalRef,
106
- onDismiss: onCloseClick,
107
- isOpen,
108
- initialFocusRef,
109
- closeButtonRef,
110
- returnFocusRef,
111
- overlayRef
112
- });
113
- return isOpen ? (<>
114
- <Overlay ref={overlayRef}/>
115
- <DialogBase tabIndex={-1} ref={modalRef} role="dialog" aria-modal="true" {...props} {...getDialogProps()}>
116
- <ButtonClose_1.default ref={closeButtonRef} onClick={onCloseClick} sx={{ position: 'absolute', top: '16px', right: '16px' }}/>
117
- {children}
118
- </DialogBase>
119
- </>) : null;
120
- });
121
- DialogHeader.defaultProps = {
122
- backgroundColor: 'canvas.subtle'
123
- };
124
- DialogHeader.propTypes = {
125
- ...Box_1.default.propTypes
126
- };
127
- DialogHeader.displayName = 'Dialog.Header';
128
- Dialog.displayName = 'Dialog';
129
- exports.default = Object.assign(Dialog, { Header: DialogHeader });