@primer/components 0.0.0-2021109221452 → 0.0.0-2021109223232

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 (175) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/dist/browser.esm.js +178 -178
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +179 -179
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/index.js +23 -12
  7. package/lib/AnchoredOverlay/index.js +12 -4
  8. package/lib/Autocomplete/index.js +14 -7
  9. package/lib/Button/index.js +70 -21
  10. package/lib/DropdownMenu/index.js +20 -6
  11. package/lib/DropdownStyles.js +26 -18
  12. package/lib/FilteredActionList/index.js +12 -4
  13. package/lib/Overlay.js +3 -1
  14. package/lib/Pagination/index.js +12 -6
  15. package/lib/Portal/Portal.js +3 -2
  16. package/lib/Portal/index.js +16 -5
  17. package/lib/SelectMenu/hooks/useKeyboardNav.js +96 -80
  18. package/lib/SelectMenu/index.js +14 -7
  19. package/lib/SelectPanel/index.js +12 -4
  20. package/lib/Token/index.js +30 -11
  21. package/lib/behaviors/anchoredPosition.js +234 -205
  22. package/lib/behaviors/focusTrap.js +157 -121
  23. package/lib/behaviors/focusZone.js +509 -434
  24. package/lib/behaviors/scrollIntoViewingArea.js +35 -18
  25. package/lib/constants.js +43 -39
  26. package/lib/hooks/index.js +60 -16
  27. package/lib/hooks/useAnchoredPosition.js +40 -31
  28. package/lib/hooks/useCombinedRefs.d.ts +2 -2
  29. package/lib/hooks/useCombinedRefs.js +35 -46
  30. package/lib/hooks/useDialog.js +96 -72
  31. package/lib/hooks/useFocusTrap.js +60 -43
  32. package/lib/hooks/useFocusZone.js +50 -54
  33. package/lib/hooks/useOnEscapePress.js +36 -25
  34. package/lib/hooks/useOpenAndCloseFocus.js +34 -22
  35. package/lib/hooks/useProvidedRefOrCreate.js +14 -10
  36. package/lib/hooks/useProvidedStateOrCreate.js +16 -13
  37. package/lib/hooks/useRenderForcingRef.js +17 -13
  38. package/lib/hooks/useResizeObserver.js +18 -15
  39. package/lib/hooks/useSafeTimeout.js +30 -22
  40. package/lib/hooks/useScrollFlash.js +23 -16
  41. package/lib/index.js +636 -161
  42. package/lib/polyfills/eventListenerSignal.js +45 -37
  43. package/lib/sx.js +14 -7
  44. package/lib/theme-preval.js +2945 -64
  45. package/lib/theme.js +12 -3
  46. package/lib/utils/iterateFocusableElements.js +85 -63
  47. package/lib/utils/theme.js +47 -33
  48. package/lib/utils/types/AriaRole.js +1 -2
  49. package/lib/utils/types/ComponentProps.js +1 -2
  50. package/lib/utils/types/Flatten.js +1 -2
  51. package/lib/utils/types/KeyPaths.js +1 -2
  52. package/lib/utils/types/MandateProps.js +1 -16
  53. package/lib/utils/types/Merge.js +1 -2
  54. package/lib/utils/types/index.js +69 -16
  55. package/lib/utils/uniqueId.js +8 -5
  56. package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  57. package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
  58. package/lib/utils/userAgent.js +12 -8
  59. package/lib-esm/Overlay.js +2 -1
  60. package/lib-esm/Portal/Portal.js +2 -1
  61. package/lib-esm/hooks/useAnchoredPosition.js +2 -1
  62. package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
  63. package/lib-esm/hooks/useCombinedRefs.js +3 -2
  64. package/lib-esm/hooks/useResizeObserver.js +2 -2
  65. package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  66. package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
  67. package/package.json +2 -3
  68. package/lib/ActionList/Divider.jsx +0 -29
  69. package/lib/ActionList/Group.jsx +0 -23
  70. package/lib/ActionList/Header.jsx +0 -66
  71. package/lib/ActionList/Item.jsx +0 -301
  72. package/lib/ActionList/List.jsx +0 -138
  73. package/lib/ActionMenu.jsx +0 -73
  74. package/lib/AnchoredOverlay/AnchoredOverlay.jsx +0 -100
  75. package/lib/Autocomplete/Autocomplete.jsx +0 -100
  76. package/lib/Autocomplete/AutocompleteContext.jsx +0 -5
  77. package/lib/Autocomplete/AutocompleteInput.jsx +0 -113
  78. package/lib/Autocomplete/AutocompleteMenu.jsx +0 -190
  79. package/lib/Autocomplete/AutocompleteOverlay.jsx +0 -55
  80. package/lib/Avatar.jsx +0 -34
  81. package/lib/AvatarPair.jsx +0 -29
  82. package/lib/AvatarStack.jsx +0 -151
  83. package/lib/BaseStyles.jsx +0 -65
  84. package/lib/BorderBox.jsx +0 -18
  85. package/lib/Box.jsx +0 -10
  86. package/lib/BranchName.jsx +0 -20
  87. package/lib/Breadcrumbs.jsx +0 -74
  88. package/lib/Button/Button.jsx +0 -60
  89. package/lib/Button/ButtonBase.jsx +0 -36
  90. package/lib/Button/ButtonClose.jsx +0 -55
  91. package/lib/Button/ButtonDanger.jsx +0 -63
  92. package/lib/Button/ButtonGroup.jsx +0 -55
  93. package/lib/Button/ButtonInvisible.jsx +0 -52
  94. package/lib/Button/ButtonOutline.jsx +0 -63
  95. package/lib/Button/ButtonPrimary.jsx +0 -62
  96. package/lib/Button/ButtonStyles.jsx +0 -37
  97. package/lib/Button/ButtonTableList.jsx +0 -49
  98. package/lib/Caret.jsx +0 -93
  99. package/lib/CircleBadge.jsx +0 -43
  100. package/lib/CircleOcticon.jsx +0 -21
  101. package/lib/CounterLabel.jsx +0 -44
  102. package/lib/Details.jsx +0 -21
  103. package/lib/Dialog/ConfirmationDialog.jsx +0 -146
  104. package/lib/Dialog/Dialog.jsx +0 -273
  105. package/lib/Dialog.jsx +0 -131
  106. package/lib/Dropdown.jsx +0 -134
  107. package/lib/DropdownMenu/DropdownButton.jsx +0 -14
  108. package/lib/DropdownMenu/DropdownMenu.jsx +0 -70
  109. package/lib/FilterList.jsx +0 -63
  110. package/lib/FilteredActionList/FilteredActionList.jsx +0 -100
  111. package/lib/FilteredSearch.jsx +0 -29
  112. package/lib/Flash.jsx +0 -70
  113. package/lib/Flex.jsx +0 -15
  114. package/lib/FormGroup.jsx +0 -25
  115. package/lib/Grid.jsx +0 -15
  116. package/lib/Header.jsx +0 -90
  117. package/lib/Heading.jsx +0 -21
  118. package/lib/Label.jsx +0 -84
  119. package/lib/LabelGroup.jsx +0 -19
  120. package/lib/Link.jsx +0 -38
  121. package/lib/Overlay.jsx +0 -155
  122. package/lib/Pagehead.jsx +0 -18
  123. package/lib/Pagination/Pagination.jsx +0 -163
  124. package/lib/Pagination/model.jsx +0 -174
  125. package/lib/PointerBox.jsx +0 -25
  126. package/lib/Popover.jsx +0 -210
  127. package/lib/Portal/Portal.jsx +0 -78
  128. package/lib/Position.jsx +0 -46
  129. package/lib/ProgressBar.jsx +0 -39
  130. package/lib/SelectMenu/SelectMenu.jsx +0 -114
  131. package/lib/SelectMenu/SelectMenuContext.jsx +0 -5
  132. package/lib/SelectMenu/SelectMenuDivider.jsx +0 -43
  133. package/lib/SelectMenu/SelectMenuFilter.jsx +0 -59
  134. package/lib/SelectMenu/SelectMenuFooter.jsx +0 -46
  135. package/lib/SelectMenu/SelectMenuHeader.jsx +0 -44
  136. package/lib/SelectMenu/SelectMenuItem.jsx +0 -143
  137. package/lib/SelectMenu/SelectMenuList.jsx +0 -60
  138. package/lib/SelectMenu/SelectMenuLoadingAnimation.jsx +0 -21
  139. package/lib/SelectMenu/SelectMenuModal.jsx +0 -119
  140. package/lib/SelectMenu/SelectMenuTab.jsx +0 -93
  141. package/lib/SelectMenu/SelectMenuTabPanel.jsx +0 -43
  142. package/lib/SelectMenu/SelectMenuTabs.jsx +0 -58
  143. package/lib/SelectPanel/SelectPanel.jsx +0 -105
  144. package/lib/SideNav.jsx +0 -177
  145. package/lib/Spinner.jsx +0 -35
  146. package/lib/StateLabel.jsx +0 -89
  147. package/lib/StyledOcticon.jsx +0 -20
  148. package/lib/SubNav.jsx +0 -104
  149. package/lib/TabNav.jsx +0 -60
  150. package/lib/Text.jsx +0 -14
  151. package/lib/TextInput.jsx +0 -23
  152. package/lib/TextInputWithTokens.jsx +0 -218
  153. package/lib/ThemeProvider.jsx +0 -130
  154. package/lib/Timeline.jsx +0 -124
  155. package/lib/Token/AvatarToken.jsx +0 -54
  156. package/lib/Token/IssueLabelToken.jsx +0 -125
  157. package/lib/Token/Token.jsx +0 -103
  158. package/lib/Token/TokenBase.jsx +0 -88
  159. package/lib/Token/_RemoveTokenButton.jsx +0 -108
  160. package/lib/Token/_TokenTextContainer.jsx +0 -49
  161. package/lib/Tooltip.jsx +0 -246
  162. package/lib/Truncate.jsx +0 -27
  163. package/lib/UnderlineNav.jsx +0 -90
  164. package/lib/_TextInputWrapper.jsx +0 -114
  165. package/lib/_UnstyledTextInput.jsx +0 -22
  166. package/lib/hooks/useDetails.jsx +0 -39
  167. package/lib/hooks/useOnOutsideClick.jsx +0 -61
  168. package/lib/hooks/useOverlay.jsx +0 -15
  169. package/lib/utils/deprecate.jsx +0 -59
  170. package/lib/utils/isNumeric.jsx +0 -7
  171. package/lib/utils/ssr.jsx +0 -6
  172. package/lib/utils/test-deprecations.jsx +0 -20
  173. package/lib/utils/test-helpers.jsx +0 -8
  174. package/lib/utils/test-matchers.jsx +0 -100
  175. package/lib/utils/testing.jsx +0 -206
package/lib/Pagehead.jsx DELETED
@@ -1,18 +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 Pagehead = styled_components_1.default.div `
10
- position: relative;
11
- padding-top: ${constants_1.get('space.4')};
12
- padding-bottom: ${constants_1.get('space.4')};
13
- margin-bottom: ${constants_1.get('space.4')};
14
- border-bottom: 1px solid ${constants_1.get('colors.border.default')};
15
- ${constants_1.COMMON};
16
- ${sx_1.default};
17
- `;
18
- exports.default = Pagehead;
@@ -1,163 +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 styled_components_1 = __importDefault(require("styled-components"));
8
- const Box_1 = __importDefault(require("../Box"));
9
- const constants_1 = require("../constants");
10
- const sx_1 = __importDefault(require("../sx"));
11
- const model_1 = require("./model");
12
- const Page = styled_components_1.default.a `
13
- display: inline-block;
14
- min-width: 32px;
15
- padding: 5px 10px;
16
- font-style: normal;
17
- line-height: 20px;
18
- color: ${constants_1.get('colors.fg.default')};
19
- text-align: center;
20
- white-space: nowrap;
21
- vertical-align: middle;
22
- cursor: pointer;
23
- user-select: none;
24
- text-decoration: none;
25
-
26
- margin-right: ${constants_1.get('space.1')};
27
-
28
- &:last-child {
29
- margin-right: 0;
30
- }
31
-
32
- border: ${constants_1.get('borderWidths.1')} solid transparent;
33
- border-radius: ${constants_1.get('radii.2')};
34
- transition: border-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);
35
-
36
- &:hover,
37
- &:focus {
38
- text-decoration: none;
39
- border-color: ${constants_1.get('colors.border.default')};
40
- outline: 0;
41
- transition-duration: 0.1s;
42
- }
43
-
44
- &:active {
45
- border-color: ${constants_1.get('colors.border.muted')};
46
- }
47
-
48
- &[rel='prev'],
49
- &[rel='next'] {
50
- color: ${constants_1.get('colors.accent.fg')};
51
- }
52
-
53
- &[aria-current],
54
- &[aria-current]:hover {
55
- color: ${constants_1.get('colors.fg.onEmphasis')};
56
- background-color: ${constants_1.get('colors.accent.emphasis')};
57
- border-color: transparent;
58
- }
59
-
60
- &[aria-disabled],
61
- &[aria-disabled]:hover {
62
- color: ${constants_1.get('colors.primer.fg.disabled')}; // check
63
- cursor: default;
64
- border-color: transparent;
65
- }
66
-
67
- @supports (clip-path: polygon(50% 0, 100% 50%, 50% 100%)) {
68
- &[rel='prev']::before,
69
- &[rel='next']::after {
70
- display: inline-block;
71
- width: 16px;
72
- height: 16px;
73
- vertical-align: text-bottom;
74
- content: '';
75
- background-color: currentColor;
76
- }
77
-
78
- // chevron-left
79
- &[rel='prev']::before {
80
- margin-right: ${constants_1.get('space.1')};
81
- clip-path: polygon(
82
- 9.8px 12.8px,
83
- 8.7px 12.8px,
84
- 4.5px 8.5px,
85
- 4.5px 7.5px,
86
- 8.7px 3.2px,
87
- 9.8px 4.3px,
88
- 6.1px 8px,
89
- 9.8px 11.7px,
90
- 9.8px 12.8px
91
- );
92
- }
93
-
94
- // chevron-right
95
- &[rel='next']::after {
96
- margin-left: ${constants_1.get('space.1')};
97
- clip-path: polygon(
98
- 6.2px 3.2px,
99
- 7.3px 3.2px,
100
- 11.5px 7.5px,
101
- 11.5px 8.5px,
102
- 7.3px 12.8px,
103
- 6.2px 11.7px,
104
- 9.9px 8px,
105
- 6.2px 4.3px,
106
- 6.2px 3.2px
107
- );
108
- }
109
- }
110
-
111
- ${constants_1.COMMON};
112
- `;
113
- function usePaginationPages({ theme, pageCount, currentPage, onPageChange, hrefBuilder, marginPageCount, showPages, surroundingPageCount }) {
114
- const pageChange = react_1.default.useCallback(n => (e) => onPageChange(e, n), [onPageChange]);
115
- const model = react_1.default.useMemo(() => {
116
- return model_1.buildPaginationModel(pageCount, currentPage, !!showPages, marginPageCount, surroundingPageCount);
117
- }, [pageCount, currentPage, showPages, marginPageCount, surroundingPageCount]);
118
- const children = react_1.default.useMemo(() => {
119
- return model.map(page => {
120
- const { props, key, content } = model_1.buildComponentData(page, hrefBuilder, pageChange(page.num));
121
- return (<Page {...props} key={key} theme={theme}>
122
- {content}
123
- </Page>);
124
- });
125
- }, [model, hrefBuilder, pageChange, theme]);
126
- return children;
127
- }
128
- const PaginationContainer = styled_components_1.default.nav `
129
- margin-top: 20px;
130
- margin-bottom: 15px;
131
- text-align: center;
132
- ${sx_1.default};
133
- `;
134
- function Pagination({ theme, pageCount, currentPage, onPageChange = noop, hrefBuilder = defaultHrefBuilder, marginPageCount = 1, showPages = true, surroundingPageCount = 2, ...rest }) {
135
- const pageElements = usePaginationPages({
136
- theme,
137
- pageCount,
138
- currentPage,
139
- onPageChange,
140
- hrefBuilder,
141
- marginPageCount,
142
- showPages,
143
- surroundingPageCount
144
- });
145
- return (<PaginationContainer aria-label="Pagination" {...rest} theme={theme}>
146
- <Box_1.default display="inline-block" theme={theme}>
147
- {pageElements}
148
- </Box_1.default>
149
- </PaginationContainer>);
150
- }
151
- function defaultHrefBuilder(pageNum) {
152
- return `#${pageNum}`;
153
- }
154
- // eslint-disable-next-line @typescript-eslint/no-empty-function
155
- function noop() { }
156
- Pagination.defaultProps = {
157
- hrefBuilder: defaultHrefBuilder,
158
- marginPageCount: 1,
159
- onPageChange: noop,
160
- showPages: true,
161
- surroundingPageCount: 2
162
- };
163
- exports.default = Pagination;
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildComponentData = exports.buildPaginationModel = void 0;
4
- function buildPaginationModel(pageCount, currentPage, showPages, marginPageCount, surroundingPageCount) {
5
- const pages = [];
6
- if (showPages) {
7
- const pageNums = [];
8
- const addPage = (n) => {
9
- if (n >= 1 && n <= pageCount) {
10
- pageNums.push(n);
11
- }
12
- };
13
- // Start by defining the window of pages to show around the current page.
14
- // If the window goes off either edge, shift it until it fits.
15
- let extentLeft = currentPage - surroundingPageCount;
16
- let extentRight = currentPage + surroundingPageCount;
17
- if (extentLeft < 1 && extentRight > pageCount) {
18
- // Our window is larger than the entire range,
19
- // so simply display every page.
20
- extentLeft = 1;
21
- extentRight = pageCount;
22
- }
23
- else if (extentLeft < 1) {
24
- while (extentLeft < 1) {
25
- extentLeft++;
26
- extentRight++;
27
- }
28
- }
29
- else if (extentRight > pageCount) {
30
- while (extentRight > pageCount) {
31
- extentLeft--;
32
- extentRight--;
33
- }
34
- }
35
- // Next, include the pages in the margins.
36
- // If a margin page is already covered in the window,
37
- // extend the window to the other direction.
38
- for (let i = 1; i <= marginPageCount; i++) {
39
- const leftPage = i;
40
- const rightPage = pageCount - (i - 1);
41
- if (leftPage >= extentLeft) {
42
- extentRight++;
43
- }
44
- else {
45
- addPage(leftPage);
46
- }
47
- if (rightPage <= extentRight) {
48
- extentLeft--;
49
- }
50
- else {
51
- addPage(rightPage);
52
- }
53
- }
54
- for (let i = extentLeft; i <= extentRight; i++) {
55
- addPage(i);
56
- }
57
- const sorted = pageNums
58
- .slice()
59
- .sort((a, b) => a - b)
60
- .filter((item, idx, ary) => !idx || item !== ary[idx - 1]);
61
- for (let idx = 0; idx < sorted.length; idx++) {
62
- const num = sorted[idx];
63
- const selected = num === currentPage;
64
- if (idx === 0) {
65
- if (num !== 1) {
66
- // If the first page isn't page one,
67
- // we need to add a break
68
- pages.push({
69
- type: 'BREAK',
70
- num: 1
71
- });
72
- }
73
- pages.push({
74
- type: 'NUM',
75
- num,
76
- selected
77
- });
78
- }
79
- else {
80
- const last = sorted[idx - 1];
81
- const delta = num - last;
82
- if (delta === 1) {
83
- pages.push({
84
- type: 'NUM',
85
- num,
86
- selected
87
- });
88
- }
89
- else {
90
- // We skipped some, so add a break
91
- pages.push({
92
- type: 'BREAK',
93
- num: num - 1
94
- });
95
- pages.push({
96
- type: 'NUM',
97
- num,
98
- selected
99
- });
100
- }
101
- }
102
- }
103
- const lastPage = pages[pages.length - 1];
104
- if (lastPage.type === 'NUM' && lastPage.num !== pageCount) {
105
- // The last page we rendered wasn't the actual last page,
106
- // so we need an additional break
107
- pages.push({
108
- type: 'BREAK',
109
- num: pageCount
110
- });
111
- }
112
- }
113
- const prev = { type: 'PREV', num: currentPage - 1, disabled: currentPage === 1 };
114
- const next = { type: 'NEXT', num: currentPage + 1, disabled: currentPage === pageCount };
115
- return [prev, ...pages, next];
116
- }
117
- exports.buildPaginationModel = buildPaginationModel;
118
- function buildComponentData(page, hrefBuilder, onClick) {
119
- const props = {};
120
- let content = '';
121
- let key = '';
122
- switch (page.type) {
123
- case 'PREV': {
124
- key = 'page-prev';
125
- content = 'Previous';
126
- if (page.disabled) {
127
- Object.assign(props, { as: 'span', 'aria-disabled': 'true' });
128
- }
129
- else {
130
- Object.assign(props, {
131
- rel: 'prev',
132
- href: hrefBuilder(page.num),
133
- 'aria-label': 'Previous Page',
134
- onClick
135
- });
136
- }
137
- break;
138
- }
139
- case 'NEXT': {
140
- key = 'page-next';
141
- content = 'Next';
142
- if (page.disabled) {
143
- Object.assign(props, { as: 'span', 'aria-disabled': 'true' });
144
- }
145
- else {
146
- Object.assign(props, {
147
- rel: 'next',
148
- href: hrefBuilder(page.num),
149
- 'aria-label': 'Next Page',
150
- onClick
151
- });
152
- }
153
- break;
154
- }
155
- case 'NUM': {
156
- key = `page-${page.num}`;
157
- content = String(page.num);
158
- if (page.selected) {
159
- Object.assign(props, { as: 'em', 'aria-current': 'page' });
160
- }
161
- else {
162
- Object.assign(props, { href: hrefBuilder(page.num), 'aria-label': `Page ${page.num}`, onClick });
163
- }
164
- break;
165
- }
166
- case 'BREAK': {
167
- key = `page-${page.num}-break`;
168
- content = '…';
169
- Object.assign(props, { as: 'span', 'aria-disabled': true });
170
- }
171
- }
172
- return { props, key, content };
173
- }
174
- exports.buildComponentData = buildComponentData;
@@ -1,25 +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 BorderBox_1 = __importDefault(require("./BorderBox"));
8
- const Caret_1 = __importDefault(require("./Caret"));
9
- function PointerBox(props) {
10
- // don't destructure these, just grab them
11
- const { bg, border, borderColor, theme } = props;
12
- const { caret, children, ...boxProps } = props;
13
- const caretProps = {
14
- bg,
15
- borderColor,
16
- borderWidth: border,
17
- location: caret,
18
- theme
19
- };
20
- return (<BorderBox_1.default sx={{ position: 'relative' }} {...boxProps}>
21
- {children}
22
- <Caret_1.default {...caretProps}/>
23
- </BorderBox_1.default>);
24
- }
25
- exports.default = PointerBox;
package/lib/Popover.jsx DELETED
@@ -1,210 +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 classnames_1 = __importDefault(require("classnames"));
7
- const styled_components_1 = __importDefault(require("styled-components"));
8
- const Box_1 = __importDefault(require("./Box"));
9
- const constants_1 = require("./constants");
10
- const sx_1 = __importDefault(require("./sx"));
11
- const Popover = styled_components_1.default.div.attrs(({ className, caret }) => {
12
- return {
13
- className: classnames_1.default(className, `caret-pos--${caret}`)
14
- };
15
- }) `
16
- position: ${props => (props.relative ? 'relative' : 'absolute')};
17
- z-index: 100;
18
- display: ${props => (props.open ? 'block' : 'none')};
19
-
20
- ${constants_1.COMMON};
21
- ${constants_1.LAYOUT};
22
- ${constants_1.POSITION};
23
- ${sx_1.default};
24
- `;
25
- const PopoverContent = styled_components_1.default(Box_1.default) `
26
- border: 1px solid ${constants_1.get('colors.border.default')};
27
- border-radius: ${constants_1.get('radii.2')};
28
- position: relative;
29
- width: 232px;
30
- margin-right: auto;
31
- margin-left: auto;
32
- padding: ${constants_1.get('space.4')};
33
- background-color: ${constants_1.get('colors.canvas.overlay')};
34
-
35
- ${constants_1.COMMON};
36
- ${constants_1.LAYOUT};
37
-
38
- // Carets
39
- &::before,
40
- &::after {
41
- position: absolute;
42
- left: 50%;
43
- display: inline-block;
44
- content: '';
45
- }
46
-
47
- &::before {
48
- top: -${constants_1.get('space.3')};
49
- margin-left: -9px;
50
- border: ${constants_1.get('space.2')} solid transparent; // TODO: solid?
51
- border-bottom-color: ${constants_1.get('colors.border.default')};
52
- }
53
-
54
- &::after {
55
- top: -14px;
56
- margin-left: -${constants_1.get('space.2')};
57
- border: 7px solid transparent; // todo: solid
58
- border-bottom-color: ${constants_1.get('colors.canvas.overlay')};
59
- }
60
-
61
- // Bottom-oriented carets
62
- ${Popover}.caret-pos--bottom & ,
63
- ${Popover}.caret-pos--bottom-right & ,
64
- ${Popover}.caret-pos--bottom-left & {
65
- &::before,
66
- &::after {
67
- top: auto;
68
- border-bottom-color: transparent;
69
- }
70
-
71
- &::before {
72
- bottom: -${constants_1.get('space.3')};
73
- border-top-color: ${constants_1.get('colors.border.default')};
74
- }
75
-
76
- &::after {
77
- bottom: -14px;
78
- // stylelint-disable-next-line primer/borders
79
- border-top-color: ${constants_1.get('colors.canvas.overlay')};
80
- }
81
- }
82
-
83
- // Top & Bottom: Right-oriented carets
84
- ${Popover}.caret-pos--top-right & ,
85
- ${Popover}.caret-pos--bottom-right & {
86
- right: -9px;
87
- margin-right: 0;
88
-
89
- &::before,
90
- &::after {
91
- left: auto;
92
- margin-left: 0;
93
- }
94
-
95
- &::before {
96
- right: 20px;
97
- }
98
-
99
- &::after {
100
- right: 21px;
101
- }
102
- }
103
-
104
- // Top & Bottom: Left-oriented carets
105
- ${Popover}.caret-pos--top-left & ,
106
- ${Popover}.caret-pos--bottom-left & {
107
- left: -9px;
108
- margin-left: 0;
109
-
110
- &::before,
111
- &::after {
112
- left: ${constants_1.get('space.4')};
113
- margin-left: 0;
114
- }
115
-
116
- &::after {
117
- left: calc(${constants_1.get('space.4')} + 1px);
118
- }
119
- }
120
-
121
- // Right- & Left-oriented carets
122
- ${Popover}.caret-pos--right & ,
123
- ${Popover}.caret-pos--right-top & ,
124
- ${Popover}.caret-pos--right-bottom & ,
125
- ${Popover}.caret-pos--left & ,
126
- ${Popover}.caret-pos--left-top & ,
127
- ${Popover}.caret-pos--left-bottom & {
128
- &::before,
129
- &::after {
130
- top: 50%;
131
- left: auto;
132
- margin-left: 0;
133
- border-bottom-color: transparent;
134
- }
135
-
136
- &::before {
137
- // stylelint-disable-next-line primer/spacing
138
- margin-top: calc((${constants_1.get('space.2')} + 1px) * -1);
139
- }
140
-
141
- &::after {
142
- margin-top: -${constants_1.get('space.2')};
143
- }
144
- }
145
-
146
- // Right-oriented carets
147
- ${Popover}.caret-pos--right & ,
148
- ${Popover}.caret-pos--right-top & ,
149
- ${Popover}.caret-pos--right-bottom & {
150
- &::before {
151
- right: -${constants_1.get('space.3')};
152
- border-left-color: ${constants_1.get('colors.border.default')};
153
- }
154
-
155
- &::after {
156
- right: -14px;
157
- // stylelint-disable-next-line primer/borders
158
- border-left-color: ${constants_1.get('colors.canvas.overlay')};
159
- }
160
- }
161
-
162
- // Left-oriented carets
163
- ${Popover}.caret-pos--left & ,
164
- ${Popover}.caret-pos--left-top & ,
165
- ${Popover}.caret-pos--left-bottom & {
166
- &::before {
167
- left: -${constants_1.get('space.3')};
168
- border-right-color: ${constants_1.get('colors.border.default')};
169
- }
170
-
171
- &::after {
172
- left: -14px;
173
- // stylelint-disable-next-line primer/borders
174
- border-right-color: ${constants_1.get('colors.canvas.overlay')};
175
- }
176
- }
177
-
178
- // Right & Left: Top-oriented carets
179
- ${Popover}.caret-pos--right-top & ,
180
- ${Popover}.caret-pos--left-top & {
181
- &::before,
182
- &::after {
183
- top: ${constants_1.get('space.4')};
184
- }
185
- }
186
-
187
- // Right & Left: Bottom-oriented carets
188
- ${Popover}.caret-pos--right-bottom & ,
189
- ${Popover}.caret-pos--left-bottom & {
190
- &::before,
191
- &::after {
192
- top: auto;
193
- }
194
-
195
- &::before {
196
- bottom: ${constants_1.get('space.3')};
197
- }
198
-
199
- &::after {
200
- bottom: calc(${constants_1.get('space.3')} + 1px);
201
- }
202
- }
203
-
204
- ${sx_1.default};
205
- `;
206
- Popover.defaultProps = {
207
- caret: 'top'
208
- };
209
- PopoverContent.displayName = 'Popover.Content';
210
- exports.default = Object.assign(Popover, { Content: PopoverContent });
@@ -1,78 +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
- exports.Portal = exports.registerPortalRoot = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const react_dom_1 = require("react-dom");
9
- const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';
10
- const DEFAULT_PORTAL_CONTAINER_NAME = '__default__';
11
- const portalRootRegistry = {};
12
- /**
13
- * Register a container to serve as a portal root.
14
- * @param root The element that will be the root for portals created in this container
15
- * @param name The name of the container, to be used with the `containerName` prop on the Portal Component.
16
- * If name is not specified, registers the default portal root.
17
- */
18
- function registerPortalRoot(root, name = DEFAULT_PORTAL_CONTAINER_NAME) {
19
- portalRootRegistry[name] = root;
20
- }
21
- exports.registerPortalRoot = registerPortalRoot;
22
- // Ensures that a default portal root exists and is registered. If a DOM element exists
23
- // with id __primerPortalRoot__, allow that element to serve as the default portal root.
24
- // Otherwise, create that element and attach it to the end of document.body.
25
- function ensureDefaultPortal() {
26
- const existingDefaultPortalContainer = portalRootRegistry[DEFAULT_PORTAL_CONTAINER_NAME];
27
- if (!existingDefaultPortalContainer || !document.body.contains(existingDefaultPortalContainer)) {
28
- let defaultPortalContainer = document.getElementById(PRIMER_PORTAL_ROOT_ID);
29
- if (!(defaultPortalContainer instanceof Element)) {
30
- defaultPortalContainer = document.createElement('div');
31
- defaultPortalContainer.setAttribute('id', PRIMER_PORTAL_ROOT_ID);
32
- defaultPortalContainer.style.position = 'absolute';
33
- defaultPortalContainer.style.top = '0';
34
- defaultPortalContainer.style.left = '0';
35
- const suitablePortalRoot = document.querySelector('[data-portal-root]');
36
- if (suitablePortalRoot) {
37
- suitablePortalRoot.appendChild(defaultPortalContainer);
38
- }
39
- else {
40
- document.body.appendChild(defaultPortalContainer);
41
- }
42
- }
43
- registerPortalRoot(defaultPortalContainer);
44
- }
45
- }
46
- /**
47
- * Creates a React Portal, placing all children in a separate physical DOM root node.
48
- * @see https://reactjs.org/docs/portals.html
49
- */
50
- const Portal = ({ children, onMount, containerName: _containerName }) => {
51
- const hostElement = document.createElement('div');
52
- // Portaled content should get their own stacking context so they don't interfere
53
- // with each other in unexpected ways. One should never find themselves tempted
54
- // to change the zIndex to a value other than "1".
55
- hostElement.style.position = 'relative';
56
- hostElement.style.zIndex = '1';
57
- const elementRef = react_1.default.useRef(hostElement);
58
- react_1.default.useLayoutEffect(() => {
59
- let containerName = _containerName;
60
- if (containerName === undefined) {
61
- containerName = DEFAULT_PORTAL_CONTAINER_NAME;
62
- ensureDefaultPortal();
63
- }
64
- const parentElement = portalRootRegistry[containerName];
65
- if (!parentElement) {
66
- throw new Error(`Portal container '${_containerName}' is not yet registered. Container must be registered with registerPortal before use.`);
67
- }
68
- const element = elementRef.current;
69
- parentElement.appendChild(element);
70
- onMount?.();
71
- return () => {
72
- parentElement.removeChild(element);
73
- };
74
- // eslint-disable-next-line react-hooks/exhaustive-deps
75
- }, [elementRef]);
76
- return react_dom_1.createPortal(children, elementRef.current);
77
- };
78
- exports.Portal = Portal;