@primer/components 0.0.0-202182720420 → 0.0.0-202182722258

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 (246) hide show
  1. package/CHANGELOG.md +2 -40
  2. package/dist/browser.esm.js +627 -670
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +389 -432
  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/Autocomplete/Autocomplete.d.ts +26 -0
  12. package/lib/Autocomplete/Autocomplete.js +55 -0
  13. package/lib/Autocomplete/AutocompleteContext.d.ts +13 -0
  14. package/lib/Autocomplete/AutocompleteContext.js +15 -0
  15. package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
  16. package/lib/Autocomplete/AutocompleteInput.js +139 -0
  17. package/lib/Autocomplete/AutocompleteMenu.d.ts +67 -0
  18. package/lib/Autocomplete/AutocompleteMenu.js +284 -0
  19. package/lib/Autocomplete/index.d.ts +2 -0
  20. package/lib/Autocomplete/index.js +15 -0
  21. package/lib/Avatar.d.ts +0 -4
  22. package/lib/AvatarPair.js +1 -1
  23. package/lib/AvatarStack.d.ts +8 -4
  24. package/lib/AvatarStack.js +7 -6
  25. package/lib/Badge/Badge.d.ts +8 -0
  26. package/lib/Badge/Badge.js +59 -0
  27. package/lib/Badge/BadgeState.d.ts +13 -0
  28. package/lib/Badge/BadgeState.js +51 -0
  29. package/lib/Badge/_badgeStyleUtils.d.ts +3 -0
  30. package/lib/Badge/_badgeStyleUtils.js +39 -0
  31. package/lib/BranchName.js +1 -1
  32. package/lib/Breadcrumb.d.ts +23 -0
  33. package/lib/{Breadcrumbs.js → Breadcrumb.js} +23 -33
  34. package/lib/Button/Button.d.ts +1 -0
  35. package/lib/Button/Button.js +1 -1
  36. package/lib/Button/ButtonClose.d.ts +2 -1
  37. package/lib/Button/ButtonClose.js +1 -1
  38. package/lib/Button/ButtonDanger.d.ts +1 -0
  39. package/lib/Button/ButtonInvisible.d.ts +1 -0
  40. package/lib/Button/ButtonInvisible.js +1 -1
  41. package/lib/Button/ButtonOutline.d.ts +1 -0
  42. package/lib/Button/ButtonPrimary.d.ts +1 -0
  43. package/lib/Button/ButtonTableList.js +1 -1
  44. package/lib/CircleBadge.js +1 -1
  45. package/lib/CircleOcticon.d.ts +1 -0
  46. package/lib/CircleOcticon.js +1 -1
  47. package/lib/CounterLabel.js +2 -2
  48. package/lib/Dialog/ConfirmationDialog.js +1 -1
  49. package/lib/Dialog/Dialog.js +9 -9
  50. package/lib/Dialog.d.ts +3 -2
  51. package/lib/Dialog.js +4 -4
  52. package/lib/Dropdown.d.ts +4 -0
  53. package/lib/Dropdown.js +2 -2
  54. package/lib/DropdownMenu/DropdownButton.d.ts +2 -1
  55. package/lib/DropdownStyles.js +6 -6
  56. package/lib/FilterList.d.ts +1 -0
  57. package/lib/FilterList.js +1 -1
  58. package/lib/FilteredActionList/FilteredActionList.js +8 -34
  59. package/lib/Flash.js +1 -1
  60. package/lib/Label.js +2 -2
  61. package/lib/Link.js +1 -1
  62. package/lib/Overlay.d.ts +2 -1
  63. package/lib/Overlay.js +11 -6
  64. package/lib/Pagehead.js +1 -1
  65. package/lib/Pagination/Pagination.js +1 -1
  66. package/lib/Popover.js +1 -1
  67. package/lib/Position.d.ts +4 -4
  68. package/lib/ProgressBar.js +1 -1
  69. package/lib/SelectMenu/SelectMenu.d.ts +344 -15
  70. package/lib/SelectMenu/SelectMenuDivider.js +1 -1
  71. package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
  72. package/lib/SelectMenu/SelectMenuFilter.js +1 -1
  73. package/lib/SelectMenu/SelectMenuFooter.js +1 -1
  74. package/lib/SelectMenu/SelectMenuHeader.js +2 -2
  75. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  76. package/lib/SelectMenu/SelectMenuItem.js +1 -1
  77. package/lib/SelectMenu/SelectMenuList.js +1 -1
  78. package/lib/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  79. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  80. package/lib/SelectMenu/SelectMenuModal.js +2 -2
  81. package/lib/SelectMenu/SelectMenuTab.js +1 -1
  82. package/lib/SelectMenu/SelectMenuTabPanel.js +1 -1
  83. package/lib/SelectPanel/SelectPanel.js +2 -3
  84. package/lib/SideNav.js +5 -5
  85. package/lib/StateLabel.js +1 -1
  86. package/lib/SubNav.js +1 -1
  87. package/lib/TabNav.js +2 -2
  88. package/lib/TextInput.d.ts +10 -7
  89. package/lib/TextInput.js +24 -29
  90. package/lib/TextInputTokens.d.ts +43 -0
  91. package/lib/TextInputTokens.js +227 -0
  92. package/lib/TextInputWithTokens.d.ts +41 -0
  93. package/lib/TextInputWithTokens.js +396 -0
  94. package/lib/Timeline.d.ts +1 -0
  95. package/lib/Timeline.js +19 -16
  96. package/lib/Token/Token.d.ts +7 -0
  97. package/lib/Token/Token.js +63 -0
  98. package/lib/Token/TokenBase.d.ts +16 -0
  99. package/lib/Token/TokenBase.js +76 -0
  100. package/lib/Token/TokenLabel.d.ts +10 -0
  101. package/lib/Token/TokenLabel.js +115 -0
  102. package/lib/Token/TokenProfile.d.ts +7 -0
  103. package/lib/Token/TokenProfile.js +45 -0
  104. package/lib/Token/_RemoveTokenButton.d.ts +3 -0
  105. package/lib/Token/_RemoveTokenButton.js +43 -0
  106. package/lib/Token/_tokenButtonUtils.d.ts +9 -0
  107. package/lib/Token/_tokenButtonUtils.js +42 -0
  108. package/lib/Tooltip.js +1 -1
  109. package/lib/UnderlineNav.js +2 -2
  110. package/lib/_UnstyledTextInput.d.ts +2 -0
  111. package/lib/_UnstyledTextInput.js +20 -0
  112. package/lib/hooks/useOverlay.d.ts +2 -1
  113. package/lib/hooks/useOverlay.js +11 -6
  114. package/lib/index.d.ts +2 -3
  115. package/lib/index.js +2 -22
  116. package/lib/theme-preval.d.ts +6 -12
  117. package/lib/theme-preval.js +0 -940
  118. package/lib/utils/scrollIntoViewingArea.d.ts +1 -0
  119. package/lib/utils/scrollIntoViewingArea.js +39 -0
  120. package/lib/utils/testing.d.ts +0 -1854
  121. package/lib/utils/types.d.ts +3 -0
  122. package/lib/utils/uniqueId.js +0 -1
  123. package/lib-esm/ActionList/Divider.js +1 -1
  124. package/lib-esm/ActionList/Header.js +2 -2
  125. package/lib-esm/ActionList/Item.js +14 -14
  126. package/lib-esm/ActionList/List.js +1 -1
  127. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
  128. package/lib-esm/Autocomplete/Autocomplete.d.ts +26 -0
  129. package/lib-esm/Autocomplete/Autocomplete.js +36 -0
  130. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +13 -0
  131. package/lib-esm/Autocomplete/AutocompleteContext.js +6 -0
  132. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
  133. package/lib-esm/Autocomplete/AutocompleteInput.js +120 -0
  134. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +67 -0
  135. package/lib-esm/Autocomplete/AutocompleteMenu.js +258 -0
  136. package/lib-esm/Autocomplete/index.d.ts +2 -0
  137. package/lib-esm/Autocomplete/index.js +1 -0
  138. package/lib-esm/Avatar.d.ts +0 -4
  139. package/lib-esm/AvatarPair.js +1 -1
  140. package/lib-esm/AvatarStack.d.ts +8 -4
  141. package/lib-esm/AvatarStack.js +8 -7
  142. package/lib-esm/Badge/Badge.d.ts +8 -0
  143. package/lib-esm/Badge/Badge.js +44 -0
  144. package/lib-esm/Badge/BadgeState.d.ts +13 -0
  145. package/lib-esm/Badge/BadgeState.js +40 -0
  146. package/lib-esm/Badge/_badgeStyleUtils.d.ts +3 -0
  147. package/lib-esm/Badge/_badgeStyleUtils.js +29 -0
  148. package/lib-esm/BranchName.js +1 -1
  149. package/lib-esm/Breadcrumb.d.ts +23 -0
  150. package/lib-esm/{Breadcrumbs.js → Breadcrumb.js} +21 -30
  151. package/lib-esm/Button/Button.d.ts +1 -0
  152. package/lib-esm/Button/Button.js +1 -1
  153. package/lib-esm/Button/ButtonClose.d.ts +2 -1
  154. package/lib-esm/Button/ButtonClose.js +1 -1
  155. package/lib-esm/Button/ButtonDanger.d.ts +1 -0
  156. package/lib-esm/Button/ButtonInvisible.d.ts +1 -0
  157. package/lib-esm/Button/ButtonInvisible.js +1 -1
  158. package/lib-esm/Button/ButtonOutline.d.ts +1 -0
  159. package/lib-esm/Button/ButtonPrimary.d.ts +1 -0
  160. package/lib-esm/Button/ButtonTableList.js +1 -1
  161. package/lib-esm/CircleBadge.js +1 -1
  162. package/lib-esm/CircleOcticon.d.ts +1 -0
  163. package/lib-esm/CircleOcticon.js +1 -1
  164. package/lib-esm/CounterLabel.js +2 -2
  165. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  166. package/lib-esm/Dialog/Dialog.js +8 -8
  167. package/lib-esm/Dialog.d.ts +3 -2
  168. package/lib-esm/Dialog.js +4 -4
  169. package/lib-esm/Dropdown.d.ts +4 -0
  170. package/lib-esm/Dropdown.js +2 -2
  171. package/lib-esm/DropdownMenu/DropdownButton.d.ts +2 -1
  172. package/lib-esm/DropdownStyles.js +6 -6
  173. package/lib-esm/FilterList.d.ts +1 -0
  174. package/lib-esm/FilterList.js +1 -1
  175. package/lib-esm/FilteredActionList/FilteredActionList.js +6 -34
  176. package/lib-esm/Flash.js +1 -1
  177. package/lib-esm/Label.js +2 -2
  178. package/lib-esm/Link.js +1 -1
  179. package/lib-esm/Overlay.d.ts +2 -1
  180. package/lib-esm/Overlay.js +9 -6
  181. package/lib-esm/Pagehead.js +1 -1
  182. package/lib-esm/Pagination/Pagination.js +1 -1
  183. package/lib-esm/Popover.js +1 -1
  184. package/lib-esm/Position.d.ts +4 -4
  185. package/lib-esm/ProgressBar.js +1 -1
  186. package/lib-esm/SelectMenu/SelectMenu.d.ts +344 -15
  187. package/lib-esm/SelectMenu/SelectMenuDivider.js +1 -1
  188. package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
  189. package/lib-esm/SelectMenu/SelectMenuFilter.js +1 -1
  190. package/lib-esm/SelectMenu/SelectMenuFooter.js +1 -1
  191. package/lib-esm/SelectMenu/SelectMenuHeader.js +2 -2
  192. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  193. package/lib-esm/SelectMenu/SelectMenuItem.js +1 -1
  194. package/lib-esm/SelectMenu/SelectMenuList.js +1 -1
  195. package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  196. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  197. package/lib-esm/SelectMenu/SelectMenuModal.js +2 -2
  198. package/lib-esm/SelectMenu/SelectMenuTab.js +1 -1
  199. package/lib-esm/SelectMenu/SelectMenuTabPanel.js +1 -1
  200. package/lib-esm/SelectPanel/SelectPanel.js +2 -3
  201. package/lib-esm/SideNav.js +5 -5
  202. package/lib-esm/StateLabel.js +1 -1
  203. package/lib-esm/SubNav.js +1 -1
  204. package/lib-esm/TabNav.js +2 -2
  205. package/lib-esm/TextInput.d.ts +10 -7
  206. package/lib-esm/TextInput.js +23 -29
  207. package/lib-esm/TextInputTokens.d.ts +43 -0
  208. package/lib-esm/TextInputTokens.js +200 -0
  209. package/lib-esm/TextInputWithTokens.d.ts +41 -0
  210. package/lib-esm/TextInputWithTokens.js +361 -0
  211. package/lib-esm/Timeline.d.ts +1 -0
  212. package/lib-esm/Timeline.js +17 -12
  213. package/lib-esm/Token/Token.d.ts +7 -0
  214. package/lib-esm/Token/Token.js +44 -0
  215. package/lib-esm/Token/TokenBase.d.ts +16 -0
  216. package/lib-esm/Token/TokenBase.js +56 -0
  217. package/lib-esm/Token/TokenLabel.d.ts +10 -0
  218. package/lib-esm/Token/TokenLabel.js +99 -0
  219. package/lib-esm/Token/TokenProfile.d.ts +7 -0
  220. package/lib-esm/Token/TokenProfile.js +28 -0
  221. package/lib-esm/Token/_RemoveTokenButton.d.ts +3 -0
  222. package/lib-esm/Token/_RemoveTokenButton.js +28 -0
  223. package/lib-esm/Token/_tokenButtonUtils.d.ts +9 -0
  224. package/lib-esm/Token/_tokenButtonUtils.js +26 -0
  225. package/lib-esm/Tooltip.js +1 -1
  226. package/lib-esm/UnderlineNav.js +2 -2
  227. package/lib-esm/_UnstyledTextInput.d.ts +2 -0
  228. package/lib-esm/_UnstyledTextInput.js +7 -0
  229. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  230. package/lib-esm/hooks/useOverlay.js +11 -6
  231. package/lib-esm/index.d.ts +2 -3
  232. package/lib-esm/index.js +2 -3
  233. package/lib-esm/theme-preval.d.ts +6 -12
  234. package/lib-esm/theme-preval.js +0 -940
  235. package/lib-esm/utils/scrollIntoViewingArea.d.ts +1 -0
  236. package/lib-esm/utils/scrollIntoViewingArea.js +30 -0
  237. package/lib-esm/utils/testing.d.ts +0 -1854
  238. package/lib-esm/utils/types.d.ts +3 -0
  239. package/lib-esm/utils/uniqueId.js +0 -1
  240. package/package.json +14 -14
  241. package/lib/Breadcrumbs.d.ts +0 -40
  242. package/lib/utils/ssr.d.ts +0 -1
  243. package/lib/utils/ssr.js +0 -19
  244. package/lib-esm/Breadcrumbs.d.ts +0 -40
  245. package/lib-esm/utils/ssr.d.ts +0 -1
  246. package/lib-esm/utils/ssr.js +0 -1
@@ -12,3 +12,6 @@ export declare type ComponentProps<T> = T extends React.ComponentType<infer Prop
12
12
  */
13
13
  export declare type Flatten<T extends unknown> = T extends (infer U)[] ? U : never;
14
14
  export declare type AriaRole = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'button' | 'cell' | 'checkbox' | 'columnheader' | 'combobox' | 'complementary' | 'contentinfo' | 'definition' | 'dialog' | 'directory' | 'document' | 'feed' | 'figure' | 'form' | 'grid' | 'gridcell' | 'group' | 'heading' | 'img' | 'link' | 'list' | 'listbox' | 'listitem' | 'log' | 'main' | 'marquee' | 'math' | 'menu' | 'menubar' | 'menuitem' | 'menuitemcheckbox ' | 'menuitemradio' | 'navigation' | 'none' | 'note' | 'option' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'search' | 'searchbox' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'textbox' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem';
15
+ export declare type MandateProps<T extends {}, K extends keyof T> = Omit<T, K> & {
16
+ [MK in K]-?: NonNullable<T[MK]>;
17
+ };
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.uniqueId = uniqueId;
7
- // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
8
7
  let idSeed = 10000;
9
8
 
10
9
  function uniqueId() {
@@ -4,7 +4,7 @@ import { get } from '../constants';
4
4
  export const StyledDivider = styled.div.withConfig({
5
5
  displayName: "Divider__StyledDivider",
6
6
  componentId: "sc-42656i-0"
7
- })(["height:1px;background:", ";margin-top:calc(", " - 1px);margin-bottom:", ";"], get('colors.border.muted'), get('space.2'), get('space.2'));
7
+ })(["height:1px;background:", ";margin-top:calc(", " - 1px);margin-bottom:", ";"], get('colors.selectMenu.borderSecondary'), get('space.2'), get('space.2'));
8
8
  /**
9
9
  * Visually separates `Item`s or `Group`s in an `ActionList`.
10
10
  */
@@ -11,9 +11,9 @@ import sx from '../sx';
11
11
  export const StyledHeader = styled.div.withConfig({
12
12
  displayName: "Header__StyledHeader",
13
13
  componentId: "qmofje-0"
14
- })(["{}padding:6px ", ";font-size:", ";font-weight:", ";color:", ";", " ", ""], get('space.3'), get('fontSizes.0'), get('fontWeights.bold'), get('colors.fg.muted'), ({
14
+ })(["{}padding:6px ", ";font-size:", ";font-weight:", ";color:", ";", " ", ""], get('space.3'), get('fontSizes.0'), get('fontWeights.bold'), get('colors.text.secondary'), ({
15
15
  variant
16
- }) => variant === 'filled' && css(["background:", ";margin:", " 0;border-top:1px solid ", ";border-bottom:1px solid ", ";&:first-child{margin-top:0;}"], get('colors.canvas.subtle'), get('space.2'), get('colors.neutral.muted'), get('colors.neutral.muted')), sx);
16
+ }) => variant === 'filled' && css(["background:", ";margin:", " 0;border-top:1px solid ", ";border-bottom:1px solid ", ";&:first-child{margin-top:0;}"], get('colors.bg.tertiary'), get('space.2'), get('colors.border.tertiary'), get('colors.border.tertiary')), sx);
17
17
  /**
18
18
  * Displays the name and description of a `Group`.
19
19
  */
@@ -1,7 +1,7 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import { CheckIcon } from '@primer/octicons-react';
4
- import React, { useCallback } from 'react';
4
+ import React, { useCallback, useMemo } from 'react';
5
5
  import { get } from '../constants';
6
6
  import sx from '../sx';
7
7
  import Truncate from '../Truncate';
@@ -10,7 +10,7 @@ import { StyledHeader } from './Header';
10
10
  import { StyledDivider } from './Divider';
11
11
  import { useColorSchemeVar, useTheme } from '../ThemeProvider';
12
12
  import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
13
- import { useSSRSafeId } from '@react-aria/ssr';
13
+ import { uniqueId } from '../utils/uniqueId';
14
14
  /**
15
15
  * These colors are not yet in our default theme. Need to remove this once they are added.
16
16
  */
@@ -48,9 +48,9 @@ const customItemThemes = {
48
48
  const getItemVariant = (variant = 'default', disabled) => {
49
49
  if (disabled) {
50
50
  return {
51
- color: get('colors.fg.muted'),
52
- iconColor: get('colors.fg.muted'),
53
- annotationColor: get('colors.fg.muted'),
51
+ color: get('colors.text.disabled'),
52
+ iconColor: get('colors.text.disabled'),
53
+ annotationColor: get('colors.text.disabled'),
54
54
  hoverCursor: 'default'
55
55
  };
56
56
  }
@@ -58,17 +58,17 @@ const getItemVariant = (variant = 'default', disabled) => {
58
58
  switch (variant) {
59
59
  case 'danger':
60
60
  return {
61
- color: get('colors.danger.fg'),
62
- iconColor: get('colors.danger.fg'),
63
- annotationColor: get('colors.fg.muted'),
61
+ color: get('colors.text.danger'),
62
+ iconColor: get('colors.icon.danger'),
63
+ annotationColor: get('colors.text.disabled'),
64
64
  hoverCursor: 'pointer'
65
65
  };
66
66
 
67
67
  default:
68
68
  return {
69
69
  color: 'inherit',
70
- iconColor: get('colors.fg.muted'),
71
- annotationColor: get('colors.fg.muted'),
70
+ iconColor: get('colors.text.secondary'),
71
+ annotationColor: get('colors.text.secondary'),
72
72
  hoverCursor: 'pointer'
73
73
  };
74
74
  }
@@ -95,7 +95,7 @@ const StyledItem = styled.div.withConfig({
95
95
  item
96
96
  }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverCursor, StyledDivider, StyledHeader, ({
97
97
  showDivider
98
- }) => showDivider ? `1px` : '0', DividedContent, get('colors.border.muted'), ({
98
+ }) => showDivider ? `1px` : '0', DividedContent, get('colors.selectMenu.borderSecondary'), ({
99
99
  showDivider
100
100
  }) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, isActiveDescendantAttribute, DividedContent, isActiveDescendantAttribute, DividedContent, isActiveDescendantAttribute, activeDescendantActivatedDirectly, ({
101
101
  focusBackground
@@ -135,7 +135,7 @@ const TrailingContent = styled(ColoredVisualContainer).withConfig({
135
135
  const DescriptionContainer = styled.span.withConfig({
136
136
  displayName: "Item__DescriptionContainer",
137
137
  componentId: "jqpvy8-8"
138
- })(["color:", ";font-size:", ";line-height:16px;margin-left:var(--description-container-margin-left);min-width:0;flex-grow:1;flex-basis:var(--description-container-flex-basis);"], get('colors.fg.muted'), get('fontSizes.0'));
138
+ })(["color:", ";font-size:", ";line-height:16px;margin-left:var(--description-container-margin-left);min-width:0;flex-grow:1;flex-basis:var(--description-container-flex-basis);"], get('colors.text.secondary'), get('fontSizes.0'));
139
139
  const MultiSelectInput = styled.input.withConfig({
140
140
  displayName: "Item__MultiSelectInput",
141
141
  componentId: "jqpvy8-9"
@@ -164,8 +164,8 @@ export function Item(itemProps) {
164
164
  id,
165
165
  ...props
166
166
  } = itemProps;
167
- const labelId = useSSRSafeId();
168
- const descriptionId = useSSRSafeId();
167
+ const labelId = useMemo(() => uniqueId(), []);
168
+ const descriptionId = useMemo(() => uniqueId(), []);
169
169
  const keyPressHandler = useCallback(event => {
170
170
  if (disabled) {
171
171
  return;
@@ -23,7 +23,7 @@ function isGroupedListProps(props) {
23
23
  const StyledList = styled.div.withConfig({
24
24
  displayName: "List__StyledList",
25
25
  componentId: "yr2k7d-0"
26
- })(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], get('fontSizes.1'), hasActiveDescendantAttribute, get('colors.border.muted'));
26
+ })(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], get('fontSizes.1'), hasActiveDescendantAttribute, get('colors.selectMenu.borderSecondary'));
27
27
  /**
28
28
  * Returns `sx` prop values for `List` children matching the given `List` style variation.
29
29
  * @param variant `List` style variation.
@@ -1,11 +1,11 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
- import React, { useCallback, useEffect } from 'react';
3
+ import React, { useCallback, useEffect, useMemo } from 'react';
4
4
  import Overlay from '../Overlay';
5
5
  import { useFocusTrap } from '../hooks/useFocusTrap';
6
6
  import { useFocusZone } from '../hooks/useFocusZone';
7
7
  import { useAnchoredPosition, useProvidedRefOrCreate, useRenderForcingRef } from '../hooks';
8
- import { useSSRSafeId } from '@react-aria/ssr';
8
+ import { uniqueId } from '../utils/uniqueId';
9
9
 
10
10
  /**
11
11
  * An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor.
@@ -26,7 +26,7 @@ export const AnchoredOverlay = ({
26
26
  }) => {
27
27
  const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
28
28
  const [overlayRef, updateOverlayRef] = useRenderForcingRef();
29
- const anchorId = useSSRSafeId();
29
+ const anchorId = useMemo(uniqueId, []);
30
30
  const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
31
31
  const onEscape = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
32
32
  const onAnchorKeyDown = useCallback(event => {
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { ComponentProps } from '../utils/types';
3
+ import AutocompleteMenu from './AutocompleteMenu';
4
+ declare const Autocomplete: React.FC;
5
+ export declare type AutocompleteProps = ComponentProps<typeof Autocomplete>;
6
+ export type { AutocompleteInputProps } from './AutocompleteInput';
7
+ export type { AutocompleteMenuProps } from './AutocompleteMenu';
8
+ declare const _default: React.FC<{}> & {
9
+ AutocompleteContext: React.Context<{
10
+ activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
11
+ autocompleteSuggestion?: string | undefined;
12
+ inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
13
+ inputValue?: string | undefined;
14
+ showMenu?: boolean | undefined;
15
+ setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
16
+ setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
17
+ setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
18
+ isMenuDirectlyActivated?: boolean | undefined;
19
+ setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
20
+ }>;
21
+ Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
22
+ as?: React.ComponentType<any> | undefined;
23
+ }>;
24
+ Menu: typeof AutocompleteMenu;
25
+ };
26
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { AutocompleteContext } from './AutocompleteContext';
3
+ import AutocompleteInput from './AutocompleteInput';
4
+ import AutocompleteMenu from './AutocompleteMenu';
5
+
6
+ const Autocomplete = ({
7
+ children
8
+ }) => {
9
+ const activeDescendantRef = useRef(null);
10
+ const inputRef = useRef(null);
11
+ const [inputValue, setInputValue] = useState('');
12
+ const [showMenu, setShowMenu] = useState(false);
13
+ const [autocompleteSuggestion, setAutocompleteSuggestion] = useState('');
14
+ const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = useState(false);
15
+ return /*#__PURE__*/React.createElement(AutocompleteContext.Provider, {
16
+ value: {
17
+ activeDescendantRef,
18
+ autocompleteSuggestion,
19
+ inputRef,
20
+ inputValue,
21
+ isMenuDirectlyActivated,
22
+ setAutocompleteSuggestion,
23
+ setInputValue,
24
+ setIsMenuDirectlyActivated,
25
+ setShowMenu,
26
+ showMenu
27
+ }
28
+ }, children);
29
+ };
30
+
31
+ Autocomplete.displayName = "Autocomplete";
32
+ export default Object.assign(Autocomplete, {
33
+ AutocompleteContext,
34
+ Input: AutocompleteInput,
35
+ Menu: AutocompleteMenu
36
+ });
@@ -0,0 +1,13 @@
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
+ }>;
@@ -0,0 +1,6 @@
1
+ import { createContext } from 'react'; // TODO:
2
+ // - figure out how we can make all of these properties required without having to define them when calling `createContext`
3
+ // - figure out how we can reduce the number of properties that need to be passed
4
+ // COLEHELP
5
+
6
+ export const AutocompleteContext = /*#__PURE__*/createContext({});
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,120 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { useCallback, useContext, useEffect, useState } from 'react';
4
+ import { AutocompleteContext } from './AutocompleteContext';
5
+ import TextInput from '../TextInput';
6
+ import { useCombinedRefs } from '../hooks/useCombinedRefs';
7
+ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
8
+ as: Component = TextInput,
9
+ onFocus,
10
+ onBlur,
11
+ onChange,
12
+ onKeyDown,
13
+ onKeyPress,
14
+ value,
15
+ ...props
16
+ }, forwardedRef) => {
17
+ const {
18
+ activeDescendantRef,
19
+ autocompleteSuggestion = '',
20
+ inputRef,
21
+ inputValue = '',
22
+ isMenuDirectlyActivated,
23
+ setInputValue,
24
+ setShowMenu,
25
+ showMenu
26
+ } = useContext(AutocompleteContext);
27
+ const combinedInputRef = useCombinedRefs(inputRef, forwardedRef);
28
+ const [highlightRemainingText, setHighlightRemainingText] = useState(true);
29
+
30
+ const handleInputFocus = e => {
31
+ onFocus && onFocus(e);
32
+ setShowMenu && setShowMenu(true);
33
+ };
34
+
35
+ const handleInputBlur = e => {
36
+ onBlur && onBlur(e); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
37
+ // this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
38
+ // but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
39
+ // COLEHELP
40
+
41
+ setTimeout(() => {
42
+ if (setShowMenu && document.activeElement !== combinedInputRef.current) {
43
+ setShowMenu(false);
44
+ }
45
+ }, 0);
46
+ };
47
+
48
+ const handleInputChange = e => {
49
+ if (onChange) {
50
+ onChange(e);
51
+ }
52
+
53
+ if (setInputValue) {
54
+ setInputValue(e.currentTarget.value);
55
+ }
56
+
57
+ if (setShowMenu && !showMenu) {
58
+ setShowMenu(true);
59
+ }
60
+ };
61
+
62
+ const handleInputKeyDown = e => {
63
+ if (e.key === 'Backspace') {
64
+ setHighlightRemainingText(false);
65
+ }
66
+ };
67
+
68
+ const handleInputKeyUp = e => {
69
+ if (e.key === 'Backspace') {
70
+ setHighlightRemainingText(true);
71
+ }
72
+ };
73
+
74
+ const onInputKeyPress = useCallback(event => {
75
+ if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
76
+ event.preventDefault();
77
+ event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
78
+
79
+ const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
80
+ activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
81
+ }
82
+ }, [activeDescendantRef]);
83
+ useEffect(() => {
84
+ if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
85
+ return;
86
+ } // resets input value to being empty after a selection has been made
87
+
88
+
89
+ if (!autocompleteSuggestion) {
90
+ inputRef.current.value = inputValue;
91
+ } // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
92
+ // is the same as what I'm typing
93
+ // e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
94
+ // COLEHELP
95
+
96
+
97
+ if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
98
+ inputRef.current.value = autocompleteSuggestion;
99
+
100
+ if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
101
+ inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
102
+ }
103
+ }
104
+ }, [autocompleteSuggestion, inputValue]);
105
+ useEffect(() => {
106
+ if (value && setInputValue) {
107
+ setInputValue(value.toString());
108
+ }
109
+ }, [value]);
110
+ return /*#__PURE__*/React.createElement(Component, _extends({
111
+ onFocus: handleInputFocus,
112
+ onBlur: handleInputBlur,
113
+ onChange: handleInputChange,
114
+ onKeyDown: handleInputKeyDown,
115
+ onKeyPress: onInputKeyPress,
116
+ onKeyUp: handleInputKeyUp,
117
+ ref: combinedInputRef
118
+ }, props));
119
+ });
120
+ export default AutocompleteInput;
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import { ItemProps } from '../ActionList';
3
+ import { OverlayProps } from '../Overlay';
4
+ import { ComponentProps, MandateProps } from '../utils/types';
5
+ declare type OnAction<T> = (item: T, event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
6
+ declare type AutocompleteMenuInternalProps<T extends MandateProps<ItemProps, 'id'>> = {
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<T, 'onAction' | 'leadingVisual' | 'id'> & {
12
+ handleAddItem: (item: Omit<T, 'onAction' | 'leadingVisual'>) => void;
13
+ };
14
+ /**
15
+ * The text that appears in the menu when there are no options in the array passed to the `items` prop.
16
+ */
17
+ emptyStateText?: React.ReactNode | false;
18
+ /**
19
+ * A custom function used to filter the options in the array passed to the `items` prop.
20
+ * By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
21
+ */
22
+ filterFn?: (item: T, i: number) => boolean;
23
+ /**
24
+ * The options for field values that are displayed in the dropdown menu.
25
+ * One or more may be selected depending on the value of the `selectionVariant` prop.
26
+ */
27
+ items: T[];
28
+ /**
29
+ * The function that is called when an item in the list is de-selected
30
+ */
31
+ onItemDeselect?: OnAction<T>;
32
+ /**
33
+ * The function that is called when an item in the list is selected
34
+ */
35
+ onItemSelect?: OnAction<T>;
36
+ /**
37
+ * Whether the data is loaded for the menu items
38
+ */
39
+ loading?: boolean;
40
+ /**
41
+ * The IDs of the selected items
42
+ */
43
+ selectedItemIds: Array<string | number>;
44
+ /**
45
+ * The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
46
+ * By default, selected items are sorted to the top after the user closes the menu.
47
+ */
48
+ selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
49
+ /**
50
+ * Whether there can be one item selected from the menu or multiple items selected from the menu
51
+ */
52
+ selectionVariant?: 'single' | 'multiple';
53
+ /**
54
+ * The ref of the element that the position of the menu is based on. By default, the menu is positioned based on the text input
55
+ */
56
+ menuAnchorRef?: React.RefObject<Element>;
57
+ };
58
+ declare function AutocompleteMenu<T extends MandateProps<ItemProps, 'id'>>(props: AutocompleteMenuInternalProps<T> & Pick<OverlayProps, 'width' | 'height' | 'maxHeight'>): JSX.Element;
59
+ declare namespace AutocompleteMenu {
60
+ var defaultProps: {
61
+ emptyStateText: string;
62
+ selectionVariant: string;
63
+ };
64
+ var displayName: string;
65
+ }
66
+ export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
67
+ export default AutocompleteMenu;