@primer/components 0.0.0-2021821193917 → 0.0.0-2021823142332

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 (234) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/dist/browser.esm.js +665 -619
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +432 -386
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Divider.js +1 -1
  7. package/lib/ActionList/Header.js +2 -2
  8. package/lib/ActionList/Item.js +13 -13
  9. package/lib/ActionList/List.js +1 -1
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
  11. package/lib/Avatar.d.ts +4 -0
  12. package/lib/AvatarPair.js +1 -1
  13. package/lib/AvatarStack.js +1 -1
  14. package/lib/BranchName.js +1 -1
  15. package/lib/Breadcrumb.js +2 -2
  16. package/lib/Button/Button.d.ts +0 -1
  17. package/lib/Button/Button.js +1 -1
  18. package/lib/Button/ButtonClose.d.ts +1 -2
  19. package/lib/Button/ButtonClose.js +1 -1
  20. package/lib/Button/ButtonDanger.d.ts +0 -1
  21. package/lib/Button/ButtonInvisible.d.ts +0 -1
  22. package/lib/Button/ButtonInvisible.js +1 -1
  23. package/lib/Button/ButtonOutline.d.ts +0 -1
  24. package/lib/Button/ButtonPrimary.d.ts +0 -1
  25. package/lib/Button/ButtonTableList.js +1 -1
  26. package/lib/CircleBadge.js +1 -1
  27. package/lib/CircleOcticon.d.ts +0 -1
  28. package/lib/CircleOcticon.js +1 -1
  29. package/lib/CounterLabel.js +2 -2
  30. package/lib/Dialog/ConfirmationDialog.js +1 -1
  31. package/lib/Dialog/Dialog.js +9 -9
  32. package/lib/Dialog.d.ts +2 -3
  33. package/lib/Dialog.js +4 -4
  34. package/lib/Dropdown.d.ts +0 -4
  35. package/lib/Dropdown.js +2 -2
  36. package/lib/DropdownMenu/DropdownButton.d.ts +1 -2
  37. package/lib/DropdownStyles.js +6 -6
  38. package/lib/FilterList.d.ts +0 -1
  39. package/lib/FilterList.js +1 -1
  40. package/lib/FilteredActionList/FilteredActionList.js +5 -5
  41. package/lib/Flash.js +1 -1
  42. package/lib/Label.js +2 -2
  43. package/lib/Link.js +1 -1
  44. package/lib/Overlay.d.ts +1 -2
  45. package/lib/Overlay.js +6 -11
  46. package/lib/Pagehead.js +1 -1
  47. package/lib/Pagination/Pagination.js +1 -1
  48. package/lib/Popover.js +1 -1
  49. package/lib/Position.d.ts +4 -4
  50. package/lib/ProgressBar.js +1 -1
  51. package/lib/SelectMenu/SelectMenu.d.ts +15 -337
  52. package/lib/SelectMenu/SelectMenuDivider.js +1 -1
  53. package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
  54. package/lib/SelectMenu/SelectMenuFilter.js +1 -1
  55. package/lib/SelectMenu/SelectMenuFooter.js +1 -1
  56. package/lib/SelectMenu/SelectMenuHeader.js +2 -2
  57. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  58. package/lib/SelectMenu/SelectMenuItem.js +1 -1
  59. package/lib/SelectMenu/SelectMenuList.js +1 -1
  60. package/lib/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  61. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  62. package/lib/SelectMenu/SelectMenuModal.js +2 -2
  63. package/lib/SelectMenu/SelectMenuTab.js +1 -1
  64. package/lib/SelectMenu/SelectMenuTabPanel.js +1 -1
  65. package/lib/SelectPanel/SelectPanel.js +3 -2
  66. package/lib/SideNav.js +5 -5
  67. package/lib/StateLabel.js +1 -1
  68. package/lib/SubNav.js +1 -1
  69. package/lib/TabNav.js +2 -2
  70. package/lib/TextInput.d.ts +6 -6
  71. package/lib/TextInput.js +21 -16
  72. package/lib/Timeline.d.ts +0 -1
  73. package/lib/Timeline.js +16 -19
  74. package/lib/Tooltip.js +1 -1
  75. package/lib/UnderlineNav.js +2 -2
  76. package/lib/hooks/useOverlay.d.ts +1 -2
  77. package/lib/hooks/useOverlay.js +6 -11
  78. package/lib/index.d.ts +1 -0
  79. package/lib/index.js +14 -0
  80. package/lib/theme-preval.d.ts +12 -6
  81. package/lib/theme-preval.js +940 -0
  82. package/lib/utils/ssr.d.ts +1 -0
  83. package/lib/utils/ssr.js +19 -0
  84. package/lib/utils/testing.d.ts +1854 -0
  85. package/lib/utils/uniqueId.js +1 -0
  86. package/lib-esm/ActionList/Divider.js +1 -1
  87. package/lib-esm/ActionList/Header.js +2 -2
  88. package/lib-esm/ActionList/Item.js +14 -14
  89. package/lib-esm/ActionList/List.js +1 -1
  90. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
  91. package/lib-esm/Avatar.d.ts +4 -0
  92. package/lib-esm/AvatarPair.js +1 -1
  93. package/lib-esm/AvatarStack.js +1 -1
  94. package/lib-esm/BranchName.js +1 -1
  95. package/lib-esm/Breadcrumb.js +2 -2
  96. package/lib-esm/Button/Button.d.ts +0 -1
  97. package/lib-esm/Button/Button.js +1 -1
  98. package/lib-esm/Button/ButtonClose.d.ts +1 -2
  99. package/lib-esm/Button/ButtonClose.js +1 -1
  100. package/lib-esm/Button/ButtonDanger.d.ts +0 -1
  101. package/lib-esm/Button/ButtonInvisible.d.ts +0 -1
  102. package/lib-esm/Button/ButtonInvisible.js +1 -1
  103. package/lib-esm/Button/ButtonOutline.d.ts +0 -1
  104. package/lib-esm/Button/ButtonPrimary.d.ts +0 -1
  105. package/lib-esm/Button/ButtonTableList.js +1 -1
  106. package/lib-esm/CircleBadge.js +1 -1
  107. package/lib-esm/CircleOcticon.d.ts +0 -1
  108. package/lib-esm/CircleOcticon.js +1 -1
  109. package/lib-esm/CounterLabel.js +2 -2
  110. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  111. package/lib-esm/Dialog/Dialog.js +8 -8
  112. package/lib-esm/Dialog.d.ts +2 -3
  113. package/lib-esm/Dialog.js +4 -4
  114. package/lib-esm/Dropdown.d.ts +0 -4
  115. package/lib-esm/Dropdown.js +2 -2
  116. package/lib-esm/DropdownMenu/DropdownButton.d.ts +1 -2
  117. package/lib-esm/DropdownStyles.js +6 -6
  118. package/lib-esm/FilterList.d.ts +0 -1
  119. package/lib-esm/FilterList.js +1 -1
  120. package/lib-esm/FilteredActionList/FilteredActionList.js +5 -5
  121. package/lib-esm/Flash.js +1 -1
  122. package/lib-esm/Label.js +2 -2
  123. package/lib-esm/Link.js +1 -1
  124. package/lib-esm/Overlay.d.ts +1 -2
  125. package/lib-esm/Overlay.js +6 -9
  126. package/lib-esm/Pagehead.js +1 -1
  127. package/lib-esm/Pagination/Pagination.js +1 -1
  128. package/lib-esm/Popover.js +1 -1
  129. package/lib-esm/Position.d.ts +4 -4
  130. package/lib-esm/ProgressBar.js +1 -1
  131. package/lib-esm/SelectMenu/SelectMenu.d.ts +15 -337
  132. package/lib-esm/SelectMenu/SelectMenuDivider.js +1 -1
  133. package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
  134. package/lib-esm/SelectMenu/SelectMenuFilter.js +1 -1
  135. package/lib-esm/SelectMenu/SelectMenuFooter.js +1 -1
  136. package/lib-esm/SelectMenu/SelectMenuHeader.js +2 -2
  137. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  138. package/lib-esm/SelectMenu/SelectMenuItem.js +1 -1
  139. package/lib-esm/SelectMenu/SelectMenuList.js +1 -1
  140. package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  141. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  142. package/lib-esm/SelectMenu/SelectMenuModal.js +2 -2
  143. package/lib-esm/SelectMenu/SelectMenuTab.js +1 -1
  144. package/lib-esm/SelectMenu/SelectMenuTabPanel.js +1 -1
  145. package/lib-esm/SelectPanel/SelectPanel.js +3 -2
  146. package/lib-esm/SideNav.js +5 -5
  147. package/lib-esm/StateLabel.js +1 -1
  148. package/lib-esm/SubNav.js +1 -1
  149. package/lib-esm/TabNav.js +2 -2
  150. package/lib-esm/TextInput.d.ts +6 -6
  151. package/lib-esm/TextInput.js +22 -16
  152. package/lib-esm/Timeline.d.ts +0 -1
  153. package/lib-esm/Timeline.js +12 -17
  154. package/lib-esm/Tooltip.js +1 -1
  155. package/lib-esm/UnderlineNav.js +2 -2
  156. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  157. package/lib-esm/hooks/useOverlay.js +6 -11
  158. package/lib-esm/index.d.ts +1 -0
  159. package/lib-esm/index.js +2 -1
  160. package/lib-esm/theme-preval.d.ts +12 -6
  161. package/lib-esm/theme-preval.js +940 -0
  162. package/lib-esm/utils/ssr.d.ts +1 -0
  163. package/lib-esm/utils/ssr.js +1 -0
  164. package/lib-esm/utils/testing.d.ts +1854 -0
  165. package/lib-esm/utils/uniqueId.js +1 -0
  166. package/package.json +9 -9
  167. package/lib/Autocomplete/Autocomplete.d.ts +0 -36
  168. package/lib/Autocomplete/Autocomplete.js +0 -55
  169. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -13
  170. package/lib/Autocomplete/AutocompleteContext.js +0 -14
  171. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
  172. package/lib/Autocomplete/AutocompleteInput.js +0 -128
  173. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -54
  174. package/lib/Autocomplete/AutocompleteMenu.js +0 -268
  175. package/lib/Autocomplete/index.d.ts +0 -2
  176. package/lib/Autocomplete/index.js +0 -15
  177. package/lib/Badge/Badge.d.ts +0 -8
  178. package/lib/Badge/Badge.js +0 -59
  179. package/lib/Badge/BadgeState.d.ts +0 -13
  180. package/lib/Badge/BadgeState.js +0 -51
  181. package/lib/Badge/_badgeStyleUtils.d.ts +0 -3
  182. package/lib/Badge/_badgeStyleUtils.js +0 -39
  183. package/lib/TextInputTokens.d.ts +0 -32
  184. package/lib/TextInputTokens.js +0 -241
  185. package/lib/TextInputWithTokens.d.ts +0 -41
  186. package/lib/TextInputWithTokens.js +0 -396
  187. package/lib/Token/Token.d.ts +0 -7
  188. package/lib/Token/Token.js +0 -69
  189. package/lib/Token/TokenBase.d.ts +0 -16
  190. package/lib/Token/TokenBase.js +0 -76
  191. package/lib/Token/TokenLabel.d.ts +0 -10
  192. package/lib/Token/TokenLabel.js +0 -115
  193. package/lib/Token/TokenProfile.d.ts +0 -7
  194. package/lib/Token/TokenProfile.js +0 -45
  195. package/lib/Token/_AddTokenButton.d.ts +0 -3
  196. package/lib/Token/_AddTokenButton.js +0 -42
  197. package/lib/Token/_RemoveTokenButton.d.ts +0 -3
  198. package/lib/Token/_RemoveTokenButton.js +0 -42
  199. package/lib/Token/_tokenButtonUtils.d.ts +0 -8
  200. package/lib/Token/_tokenButtonUtils.js +0 -42
  201. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -36
  202. package/lib-esm/Autocomplete/Autocomplete.js +0 -36
  203. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -13
  204. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -5
  205. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
  206. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -109
  207. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -54
  208. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -244
  209. package/lib-esm/Autocomplete/index.d.ts +0 -2
  210. package/lib-esm/Autocomplete/index.js +0 -1
  211. package/lib-esm/Badge/Badge.d.ts +0 -8
  212. package/lib-esm/Badge/Badge.js +0 -44
  213. package/lib-esm/Badge/BadgeState.d.ts +0 -13
  214. package/lib-esm/Badge/BadgeState.js +0 -40
  215. package/lib-esm/Badge/_badgeStyleUtils.d.ts +0 -3
  216. package/lib-esm/Badge/_badgeStyleUtils.js +0 -29
  217. package/lib-esm/TextInputTokens.d.ts +0 -32
  218. package/lib-esm/TextInputTokens.js +0 -211
  219. package/lib-esm/TextInputWithTokens.d.ts +0 -41
  220. package/lib-esm/TextInputWithTokens.js +0 -361
  221. package/lib-esm/Token/Token.d.ts +0 -7
  222. package/lib-esm/Token/Token.js +0 -49
  223. package/lib-esm/Token/TokenBase.d.ts +0 -16
  224. package/lib-esm/Token/TokenBase.js +0 -56
  225. package/lib-esm/Token/TokenLabel.d.ts +0 -10
  226. package/lib-esm/Token/TokenLabel.js +0 -99
  227. package/lib-esm/Token/TokenProfile.d.ts +0 -7
  228. package/lib-esm/Token/TokenProfile.js +0 -28
  229. package/lib-esm/Token/_AddTokenButton.d.ts +0 -3
  230. package/lib-esm/Token/_AddTokenButton.js +0 -27
  231. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
  232. package/lib-esm/Token/_RemoveTokenButton.js +0 -27
  233. package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -8
  234. package/lib-esm/Token/_tokenButtonUtils.js +0 -26
@@ -1,3 +1,4 @@
1
+ // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
1
2
  let idSeed = 10000;
2
3
  export function uniqueId() {
3
4
  return `__primer_id_${idSeed++}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021821193917",
3
+ "version": "0.0.0-2021823142332",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -15,7 +15,7 @@
15
15
  "start": "concurrently npm:start:*",
16
16
  "start:docs": "cd docs && npm run develop",
17
17
  "start:storybook": "start-storybook -p 6006",
18
- "lint": "eslint '**/*.{js,ts,tsx}'",
18
+ "lint": "eslint '**/*.{js,ts,tsx,md,mdx}'",
19
19
  "lint:fix": "npm run lint -- --fix",
20
20
  "test": "jest",
21
21
  "test:update": "npm run test -- --updateSnapshot",
@@ -45,20 +45,19 @@
45
45
  "dependencies": {
46
46
  "@primer/octicons-react": "^13.0.0",
47
47
  "@primer/primitives": "4.7.1",
48
- "@radix-ui/react-polymorphic": "0.0.14",
48
+ "@react-aria/ssr": "3.1.0",
49
49
  "@styled-system/css": "5.1.5",
50
50
  "@styled-system/props": "5.1.5",
51
51
  "@styled-system/theme-get": "5.1.2",
52
52
  "@types/history": "4.7.8",
53
53
  "@types/styled-components": "5.1.11",
54
54
  "@types/styled-system": "5.1.12",
55
- "@types/styled-system__css": "5.0.15",
55
+ "@types/styled-system__css": "5.0.16",
56
56
  "@types/styled-system__theme-get": "5.0.1",
57
57
  "classnames": "2.3.1",
58
58
  "deepmerge": "4.2.2",
59
59
  "focus-visible": "5.2.0",
60
- "styled-system": "5.1.5",
61
- "tinycolor2": "1.4.2"
60
+ "styled-system": "5.1.5"
62
61
  },
63
62
  "devDependencies": {
64
63
  "@babel/cli": "7.14.5",
@@ -79,7 +78,7 @@
79
78
  "@storybook/addon-actions": "^6.2.9",
80
79
  "@storybook/addon-essentials": "6.2.9",
81
80
  "@storybook/addon-links": "^6.2.9",
82
- "@storybook/react": "6.3.6",
81
+ "@storybook/react": "6.3.8",
83
82
  "@testing-library/dom": "7.31.2",
84
83
  "@testing-library/react": "11.2.7",
85
84
  "@testing-library/react-hooks": "7.0.0",
@@ -90,7 +89,6 @@
90
89
  "@types/jest-axe": "3.5.1",
91
90
  "@types/lodash.isempty": "4.4.6",
92
91
  "@types/lodash.isobject": "3.0.6",
93
- "@types/tinycolor2": "1.4.3",
94
92
  "@typescript-eslint/eslint-plugin": "4.26.1",
95
93
  "@typescript-eslint/parser": "4.26.1",
96
94
  "@wojtekmaj/enzyme-adapter-react-17": "0.6.3",
@@ -111,7 +109,9 @@
111
109
  "eslint-plugin-github": "4.1.3",
112
110
  "eslint-plugin-jest": "24.3.6",
113
111
  "eslint-plugin-jsx-a11y": "6.4.1",
112
+ "eslint-plugin-mdx": "1.15.1",
114
113
  "eslint-plugin-prettier": "3.4.0",
114
+ "eslint-plugin-primer-react": "0.4.2",
115
115
  "eslint-plugin-react": "7.24.0",
116
116
  "eslint-plugin-react-hooks": "4.2.0",
117
117
  "jest": "27.0.4",
@@ -124,7 +124,7 @@
124
124
  "react": "17.0.2",
125
125
  "react-dom": "17.0.2",
126
126
  "react-test-renderer": "17.0.2",
127
- "rollup": "2.51.2",
127
+ "rollup": "2.56.3",
128
128
  "rollup-plugin-babel": "4.4.0",
129
129
  "rollup-plugin-terser": "7.0.2",
130
130
  "rollup-plugin-visualizer": "5.5.0",
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import { ComponentProps } from '../utils/types';
3
- declare const Autocomplete: React.FC;
4
- export declare type AutocompleteProps = ComponentProps<typeof Autocomplete>;
5
- export type { AutocompleteInputProps } from './AutocompleteInput';
6
- export type { AutocompleteMenuProps } from './AutocompleteMenu';
7
- declare const _default: React.FC<{}> & {
8
- AutocompleteContext: React.Context<{
9
- activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
10
- autocompleteSuggestion?: string | undefined;
11
- inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
12
- inputValue?: string | undefined;
13
- showMenu?: boolean | undefined;
14
- setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
15
- setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
16
- setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
17
- isMenuDirectlyActivated?: boolean | undefined;
18
- setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
19
- }>;
20
- Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
21
- as?: React.ComponentType<any> | undefined;
22
- }>;
23
- Menu: React.ForwardRefExoticComponent<{
24
- addNewItem?: Omit<import("../ActionList/List").ItemInput, "onAction"> | undefined;
25
- emptyStateText?: React.ReactNode;
26
- filterFn?: ((item: import("../ActionList/List").ItemInput, i: number) => boolean) | undefined;
27
- items: import("../ActionList/List").ItemInput[];
28
- onItemDeselect?: ((item: import("../ActionList").ItemProps, event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
29
- onItemSelect?: ((item: import("../ActionList").ItemProps, event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
30
- loading?: boolean | undefined;
31
- selectedItemIds: (string | number)[];
32
- selectedSortFn?: ((itemIdA: string | number, itemIdB: string | number) => number) | undefined;
33
- selectionVariant?: "multiple" | "single" | undefined;
34
- } & Pick<import("..").OverlayProps, "height" | "maxHeight" | "width"> & React.RefAttributes<HTMLInputElement>>;
35
- };
36
- export default _default;
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _AutocompleteContext = require("./AutocompleteContext");
11
-
12
- var _AutocompleteInput = _interopRequireDefault(require("./AutocompleteInput"));
13
-
14
- var _AutocompleteMenu = _interopRequireDefault(require("./AutocompleteMenu"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- const Autocomplete = ({
23
- children
24
- }) => {
25
- const activeDescendantRef = (0, _react.useRef)(null);
26
- const inputRef = (0, _react.useRef)(null);
27
- const [inputValue, setInputValue] = (0, _react.useState)('');
28
- const [showMenu, setShowMenu] = (0, _react.useState)(false);
29
- const [autocompleteSuggestion, setAutocompleteSuggestion] = (0, _react.useState)('');
30
- const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = (0, _react.useState)(false);
31
- return /*#__PURE__*/_react.default.createElement(_AutocompleteContext.AutocompleteContext.Provider, {
32
- value: {
33
- activeDescendantRef,
34
- autocompleteSuggestion,
35
- inputRef,
36
- inputValue,
37
- isMenuDirectlyActivated,
38
- setAutocompleteSuggestion,
39
- setInputValue,
40
- setIsMenuDirectlyActivated,
41
- setShowMenu,
42
- showMenu
43
- }
44
- }, children);
45
- };
46
-
47
- Autocomplete.displayName = "Autocomplete";
48
-
49
- var _default = Object.assign(Autocomplete, {
50
- AutocompleteContext: _AutocompleteContext.AutocompleteContext,
51
- Input: _AutocompleteInput.default,
52
- Menu: _AutocompleteMenu.default
53
- });
54
-
55
- exports.default = _default;
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const AutocompleteContext: import("react").Context<{
3
- activeDescendantRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
4
- autocompleteSuggestion?: string | undefined;
5
- inputRef?: import("react").MutableRefObject<HTMLInputElement | null> | undefined;
6
- inputValue?: string | undefined;
7
- showMenu?: boolean | undefined;
8
- setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
9
- setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
10
- setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
11
- isMenuDirectlyActivated?: boolean | undefined;
12
- setIsMenuDirectlyActivated?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
13
- }>;
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AutocompleteContext = void 0;
7
-
8
- var _react = require("react");
9
-
10
- // TODO:
11
- // - figure out how we can make all of these properties required without having to define them when calling `createContext`
12
- // - figure out how we can reduce the number of properties that need to be passed
13
- const AutocompleteContext = /*#__PURE__*/(0, _react.createContext)({});
14
- exports.AutocompleteContext = AutocompleteContext;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import type * as Polymorphic from "@radix-ui/react-polymorphic";
3
- import { ComponentProps } from '../utils/types';
4
- declare type InternalAutocompleteInputProps = {
5
- as?: React.ComponentType<any>;
6
- };
7
- declare const AutocompleteInput: Polymorphic.ForwardRefComponent<"input", InternalAutocompleteInputProps>;
8
- export declare type AutocompleteInputProps = ComponentProps<typeof AutocompleteInput>;
9
- export default AutocompleteInput;
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _AutocompleteContext = require("./AutocompleteContext");
11
-
12
- var _TextInput = _interopRequireDefault(require("../TextInput"));
13
-
14
- var _useCombinedRefs = require("../hooks/useCombinedRefs");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
-
24
- const AutocompleteInput = /*#__PURE__*/_react.default.forwardRef(({
25
- as: Component = _TextInput.default,
26
- onFocus,
27
- onChange,
28
- onKeyDown,
29
- onKeyPress,
30
- value,
31
- ...props
32
- }, forwardedRef) => {
33
- const {
34
- activeDescendantRef,
35
- autocompleteSuggestion = '',
36
- inputRef,
37
- inputValue = '',
38
- isMenuDirectlyActivated,
39
- setInputValue,
40
- setShowMenu,
41
- showMenu
42
- } = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
43
- const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(inputRef, forwardedRef);
44
- const [highlightRemainingText, setHighlightRemainingText] = (0, _react.useState)(true);
45
-
46
- const handleInputFocus = () => {
47
- if (setShowMenu) {
48
- setShowMenu(true);
49
- }
50
- };
51
-
52
- const handleInputBlur = e => {
53
- // HACK: wait a tick and check the focused element before hiding the autocomplete menu
54
- // this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
55
- // but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
56
- setTimeout(() => {
57
- if (setShowMenu && document.activeElement !== combinedInputRef.current) {
58
- setShowMenu(false);
59
- }
60
- }, 0);
61
- };
62
-
63
- const handleInputChange = e => {
64
- if (setInputValue) {
65
- setInputValue(e.currentTarget.value);
66
- }
67
-
68
- if (setShowMenu && !showMenu) {
69
- setShowMenu(true);
70
- }
71
- };
72
-
73
- const handleInputKeyDown = e => {
74
- if (e.key === 'Backspace') {
75
- setHighlightRemainingText(false);
76
- }
77
- };
78
-
79
- const handleInputKeyUp = e => {
80
- if (e.key === 'Backspace') {
81
- setHighlightRemainingText(true);
82
- }
83
- };
84
-
85
- const onInputKeyPress = (0, _react.useCallback)(event => {
86
- if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
87
- event.preventDefault();
88
- event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
89
-
90
- const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
91
- activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
92
- }
93
- }, [activeDescendantRef]);
94
- (0, _react.useEffect)(() => {
95
- if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
96
- return;
97
- }
98
-
99
- if (!autocompleteSuggestion) {
100
- inputRef.current.value = inputValue;
101
- }
102
-
103
- if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
104
- inputRef.current.value = autocompleteSuggestion;
105
-
106
- if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
107
- inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
108
- }
109
- }
110
- }, [autocompleteSuggestion, inputValue]);
111
- (0, _react.useEffect)(() => {
112
- if (value && setInputValue) {
113
- setInputValue(value.toString());
114
- }
115
- }, [value]);
116
- return /*#__PURE__*/_react.default.createElement(Component, _extends({
117
- onFocus: handleInputFocus,
118
- onBlur: handleInputBlur,
119
- onChange: handleInputChange,
120
- onKeyDown: handleInputKeyDown,
121
- onKeyPress: onInputKeyPress,
122
- onKeyUp: handleInputKeyUp,
123
- ref: combinedInputRef
124
- }, props));
125
- });
126
-
127
- var _default = AutocompleteInput;
128
- exports.default = _default;
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { ItemProps } from '../ActionList';
3
- import { ItemInput } from '../ActionList/List';
4
- import { OverlayProps } from '../Overlay';
5
- import { ComponentProps } from '../utils/types';
6
- declare type AutocompleteMenuInternalProps = {
7
- /**
8
- * A menu item that is used to allow users make a selection that is not available in the array passed to the `items` prop.
9
- * This menu item gets appended to the end of the list of options.
10
- */
11
- addNewItem?: Omit<ItemInput, 'onAction'>;
12
- /**
13
- * The text that appears in the menu when there are no options in the array passed to the `items` prop.
14
- */
15
- emptyStateText?: React.ReactNode | false;
16
- /**
17
- * A custom function used to filter the options in the array passed to the `items` prop.
18
- * By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
19
- */
20
- filterFn?: (item: ItemInput, i: number) => boolean;
21
- /**
22
- * The options for field values that are displayed in the dropdown menu.
23
- * One or more may be selected depending on the value of the `selectionVariant` prop.
24
- */
25
- items: ItemInput[];
26
- /**
27
- * The function that is called when an item in the list is de-selected
28
- */
29
- onItemDeselect?: NonNullable<ItemProps['onAction']>;
30
- /**
31
- * The function that is called when an item in the list is selected
32
- */
33
- onItemSelect?: NonNullable<ItemProps['onAction']>;
34
- /**
35
- * Whether the data is loaded for the menu items
36
- */
37
- loading?: boolean;
38
- /**
39
- * The IDs of the selected items
40
- */
41
- selectedItemIds: Array<string | number>;
42
- /**
43
- * The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
44
- * By default, selected items are sorted to the top after the user closes the menu.
45
- */
46
- selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
47
- /**
48
- * Whether there can be one item selected from the menu or multiple items selected from the menu
49
- */
50
- selectionVariant?: 'single' | 'multiple';
51
- };
52
- declare const AutocompleteMenu: React.ForwardRefExoticComponent<AutocompleteMenuInternalProps & Pick<OverlayProps, "height" | "maxHeight" | "width"> & React.RefAttributes<HTMLInputElement>>;
53
- export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
54
- export default AutocompleteMenu;
@@ -1,268 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _ActionList = require("../ActionList");
11
-
12
- var _hooks = require("../hooks");
13
-
14
- var _useFocusZone = require("../hooks/useFocusZone");
15
-
16
- var _Overlay = _interopRequireDefault(require("../Overlay"));
17
-
18
- var _ = require("../");
19
-
20
- var _Portal = require("../Portal");
21
-
22
- var _AutocompleteContext = require("./AutocompleteContext");
23
-
24
- var _useCombinedRefs = require("../hooks/useCombinedRefs");
25
-
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
-
30
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
-
32
- const DROPDOWN_PORTAL_CONTAINER_NAME = '__listcontainerportal__';
33
-
34
- const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
35
-
36
- function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
37
- const {
38
- top: childTop,
39
- bottom: childBottom
40
- } = child.getBoundingClientRect();
41
- const {
42
- top: containerTop,
43
- bottom: containerBottom
44
- } = container.getBoundingClientRect();
45
- const isChildTopAboveViewingArea = childTop < containerTop + margin;
46
- const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
47
-
48
- if (isChildTopAboveViewingArea) {
49
- const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
50
- container.scrollTo({
51
- behavior,
52
- top: scrollHeightToChildTop - margin
53
- });
54
- } else if (isChildBottomBelowViewingArea) {
55
- const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
56
- container.scrollTo({
57
- behavior,
58
- top: scrollHeightToChildBottom + margin
59
- });
60
- } // either completely in view or outside viewing area on both ends, don't scroll
61
-
62
- }
63
-
64
- const defaultItemFilter = filterValue => (item, _i) => {
65
- var _item$text;
66
-
67
- return Boolean(item === null || item === void 0 ? void 0 : (_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.toLowerCase().startsWith(filterValue.toLowerCase()));
68
- }; // TODO:
69
- // insteaad of using `forwardRef`, just use a regular Functional Component
70
- // get rid of unused props
71
-
72
-
73
- const AutocompleteMenu = /*#__PURE__*/_react.default.forwardRef(({
74
- items,
75
- selectedItemIds,
76
- selectedSortFn,
77
- onItemSelect,
78
- onItemDeselect,
79
- emptyStateText,
80
- addNewItem,
81
- loading,
82
- selectionVariant,
83
- filterFn: externalFilterFn,
84
- width,
85
- height,
86
- maxHeight
87
- }, ref) => {
88
- const {
89
- activeDescendantRef,
90
- inputRef,
91
- inputValue = '',
92
- setAutocompleteSuggestion,
93
- setShowMenu,
94
- setInputValue,
95
- setIsMenuDirectlyActivated,
96
- showMenu
97
- } = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
98
- const filterFn = externalFilterFn ? externalFilterFn : defaultItemFilter(inputValue);
99
- const listContainerRef = (0, _react.useRef)(null);
100
- const scrollContainerRef = (0, _react.useRef)(null);
101
- const [highlightedItem, setHighlightedItem] = (0, _react.useState)(); // TODO: clean up this mess by making id required on ItemProps
102
-
103
- const [sortedItemIds, setSortedItemIds] = (0, _react.useState)(items.map(({
104
- id
105
- }) => id || id === 0 ? id : ''));
106
- const {
107
- floatingElementRef,
108
- position
109
- } = (0, _hooks.useAnchoredPosition)({
110
- side: 'outside-bottom',
111
- align: 'start',
112
- anchorElementRef: inputRef
113
- }, [showMenu, selectedItemIds]);
114
- const combinedOverlayRef = (0, _useCombinedRefs.useCombinedRefs)(scrollContainerRef, floatingElementRef);
115
-
116
- const closeOptionList = () => {
117
- if (setShowMenu) {
118
- setShowMenu(false);
119
- }
120
- };
121
-
122
- const isItemSelected = itemId => {
123
- var _items$find;
124
-
125
- return ((_items$find = items.find(selectableItem => selectableItem.id === itemId)) === null || _items$find === void 0 ? void 0 : _items$find.selected) || selectedItemIds.includes(itemId);
126
- };
127
-
128
- const itemsToRender = [// selectable tokens
129
- ...items.map(selectableItem => {
130
- return { ...selectableItem,
131
- //TODO: just make `id` required
132
- selected: selectionVariant === 'multiple' ? isItemSelected(selectableItem.id) : undefined,
133
- onAction: (item, e) => {
134
- // TODO: clean up all of these `if/else` statements
135
- if (item.selected) {
136
- // TODO: make `onItemDeselect` optional
137
- if (onItemDeselect) {
138
- onItemDeselect(item, e);
139
- }
140
- } else {
141
- // TODO: make `onItemSelect` optional
142
- if (onItemSelect) {
143
- onItemSelect(item, e);
144
- }
145
-
146
- if (selectionVariant === 'multiple') {
147
- if (setInputValue) {
148
- setInputValue('');
149
- }
150
-
151
- if (setAutocompleteSuggestion) {
152
- setAutocompleteSuggestion('');
153
- }
154
- }
155
- }
156
-
157
- if (selectionVariant === 'single') {
158
- if (setShowMenu) {
159
- setShowMenu(false);
160
- }
161
-
162
- if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
163
- inputRef.current.setSelectionRange(inputRef.current.value.length, inputRef.current.value.length);
164
- }
165
- }
166
- }
167
- };
168
- }), // menu item used for creating a token from whatever is in the text input
169
- ...(addNewItem ? [{ ...addNewItem,
170
- onAction: onItemSelect ? (_item, e) => {
171
- onItemSelect({
172
- text: inputValue,
173
- id: `randomlyGeneratedId-${inputValue}`
174
- }, e);
175
- } : undefined
176
- }] : [])];
177
- (0, _useFocusZone.useFocusZone)({
178
- containerRef: listContainerRef,
179
- focusOutBehavior: 'wrap',
180
- focusableElementFilter: element => {
181
- return !(element instanceof HTMLInputElement);
182
- },
183
- activeDescendantFocus: inputRef,
184
- onActiveDescendantChanged: (current, _previous, directlyActivated) => {
185
- if (activeDescendantRef) {
186
- activeDescendantRef.current = current || null;
187
- }
188
-
189
- if (current) {
190
- const selectedItem = itemsToRender.find(item => {
191
- var _item$id;
192
-
193
- return ((_item$id = item.id) === null || _item$id === void 0 ? void 0 : _item$id.toString()) === (current === null || current === void 0 ? void 0 : current.dataset.id);
194
- });
195
- setHighlightedItem({ ...selectedItem,
196
- isDirectlyActivated: directlyActivated
197
- });
198
-
199
- if (setIsMenuDirectlyActivated) {
200
- setIsMenuDirectlyActivated(directlyActivated);
201
- }
202
- }
203
-
204
- if (current && scrollContainerRef.current && directlyActivated) {
205
- scrollIntoViewingArea(current, scrollContainerRef.current);
206
- }
207
- }
208
- });
209
- (0, _react.useEffect)(() => {
210
- var _highlightedItem$text;
211
-
212
- if (!setAutocompleteSuggestion) {
213
- return;
214
- }
215
-
216
- if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputValue || '')) {
217
- setAutocompleteSuggestion(highlightedItem.text);
218
- } else {
219
- setAutocompleteSuggestion('');
220
- }
221
- }, [highlightedItem, inputValue]);
222
- (0, _react.useEffect)(() => {
223
- setSortedItemIds([...sortedItemIds].sort(selectedSortFn ? selectedSortFn : getDefaultSortFn(isItemSelected)));
224
- }, [showMenu]);
225
-
226
- if (listContainerRef.current) {
227
- (0, _Portal.registerPortalRoot)(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
228
- }
229
-
230
- const itemSortOrderData = sortedItemIds.reduce((acc, curr, i) => {
231
- acc[curr] = i;
232
- return acc;
233
- }, {});
234
- const sortedAndFilteredItemsToRender = [...(filterFn ? itemsToRender.filter(filterFn) : itemsToRender)].sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]);
235
- return /*#__PURE__*/_react.default.createElement("div", {
236
- ref: listContainerRef
237
- }, showMenu && emptyStateText ? /*#__PURE__*/_react.default.createElement(_Overlay.default, {
238
- returnFocusRef: inputRef,
239
- portalContainerName: DROPDOWN_PORTAL_CONTAINER_NAME,
240
- preventFocusOnOpen: true,
241
- onClickOutside: closeOptionList,
242
- onEscape: closeOptionList,
243
- ref: combinedOverlayRef,
244
- top: position === null || position === void 0 ? void 0 : position.top,
245
- left: position === null || position === void 0 ? void 0 : position.left,
246
- width: width,
247
- height: height,
248
- maxHeight: maxHeight
249
- }, loading ? /*#__PURE__*/_react.default.createElement(_.Box, {
250
- p: 3,
251
- display: "flex",
252
- justifyContent: "center"
253
- }, /*#__PURE__*/_react.default.createElement(_.Spinner, null)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, sortedAndFilteredItemsToRender.length ? /*#__PURE__*/_react.default.createElement(_ActionList.ActionList, {
254
- selectionVariant: "multiple",
255
- items: sortedAndFilteredItemsToRender,
256
- role: "listbox"
257
- }) : /*#__PURE__*/_react.default.createElement(_.Box, {
258
- p: 3
259
- }, emptyStateText))) : null);
260
- });
261
-
262
- AutocompleteMenu.defaultProps = {
263
- emptyStateText: 'No selectable options',
264
- selectionVariant: 'single'
265
- };
266
- AutocompleteMenu.displayName = 'AutocompleteMenu';
267
- var _default = AutocompleteMenu;
268
- exports.default = _default;
@@ -1,2 +0,0 @@
1
- export { default } from './Autocomplete';
2
- export type { AutocompleteMenuProps, AutocompleteInputProps, } from './Autocomplete';