@primer/components 30.3.0-rc.2010c7d4 → 31.0.0-rc.15aa0a10

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 (180) hide show
  1. package/.eslintrc.json +2 -1
  2. package/.storybook/preview.js +4 -4
  3. package/CHANGELOG.md +12 -2
  4. package/codemods/deprecateUtilityComponents.js +1 -1
  5. package/contributor-docs/adrs/adr-003-prop-norms.md +72 -0
  6. package/dist/browser.esm.js +798 -794
  7. package/dist/browser.esm.js.map +1 -1
  8. package/dist/browser.umd.js +801 -797
  9. package/dist/browser.umd.js.map +1 -1
  10. package/docs/content/Autocomplete.mdx +627 -0
  11. package/docs/content/TextInputTokens.mdx +89 -0
  12. package/docs/content/getting-started.md +1 -1
  13. package/docs/content/overriding-styles.mdx +7 -6
  14. package/docs/content/theming.md +5 -5
  15. package/docs/package-lock.json +288 -511
  16. package/docs/package.json +1 -1
  17. package/docs/src/@primer/gatsby-theme-doctocat/components/hero.js +14 -12
  18. package/docs/src/@primer/gatsby-theme-doctocat/nav.yml +2 -0
  19. package/docs/src/@primer/gatsby-theme-doctocat/primer-components-hero.svg +7 -7
  20. package/lib/ActionList/Item.js +1 -1
  21. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
  22. package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
  23. package/lib/Autocomplete/Autocomplete.d.ts +304 -0
  24. package/lib/Autocomplete/Autocomplete.js +145 -0
  25. package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
  26. package/lib/Autocomplete/AutocompleteContext.js +11 -0
  27. package/lib/Autocomplete/AutocompleteInput.d.ts +292 -0
  28. package/lib/Autocomplete/AutocompleteInput.js +157 -0
  29. package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
  30. package/lib/Autocomplete/AutocompleteMenu.js +224 -0
  31. package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
  32. package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
  33. package/lib/Autocomplete/index.d.ts +2 -0
  34. package/lib/Autocomplete/index.js +15 -0
  35. package/lib/BaseStyles.js +1 -1
  36. package/lib/BorderBox.js +1 -1
  37. package/lib/Button/ButtonInvisible.js +1 -1
  38. package/lib/Caret.js +2 -2
  39. package/lib/Dialog.js +1 -1
  40. package/lib/FilteredActionList/FilteredActionList.js +5 -31
  41. package/lib/Flash.js +16 -16
  42. package/lib/Label.js +1 -1
  43. package/lib/Overlay.d.ts +1 -0
  44. package/lib/Overlay.js +3 -1
  45. package/lib/ProgressBar.js +1 -1
  46. package/lib/StateLabel.js +13 -19
  47. package/lib/Token/_RemoveTokenButton.js +1 -1
  48. package/lib/__tests__/Autocomplete.test.d.ts +1 -0
  49. package/lib/__tests__/Autocomplete.test.js +528 -0
  50. package/lib/__tests__/BorderBox.test.js +1 -1
  51. package/lib/__tests__/CircleOcticon.test.js +1 -1
  52. package/lib/__tests__/CounterLabel.test.js +4 -4
  53. package/lib/__tests__/Flash.test.js +4 -4
  54. package/lib/__tests__/Link.test.js +1 -1
  55. package/lib/__tests__/behaviors/scrollIntoViewingArea.test.d.ts +1 -0
  56. package/lib/__tests__/behaviors/scrollIntoViewingArea.test.js +226 -0
  57. package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
  58. package/lib/behaviors/scrollIntoViewingArea.js +39 -0
  59. package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
  60. package/lib/hooks/useOpenAndCloseFocus.js +7 -2
  61. package/lib/hooks/useOverlay.d.ts +2 -1
  62. package/lib/hooks/useOverlay.js +4 -2
  63. package/lib/index.d.ts +2 -0
  64. package/lib/index.js +8 -0
  65. package/lib/stories/Autocomplete.stories.js +608 -0
  66. package/lib/stories/Dialog.stories.js +3 -3
  67. package/lib/stories/IssueLabelToken.stories.js +1 -1
  68. package/lib/stories/ProfileToken.stories.js +1 -1
  69. package/lib/theme-preval.js +370 -3100
  70. package/lib/utils/testing.d.ts +50 -493
  71. package/lib/utils/types/MandateProps.d.ts +3 -0
  72. package/lib/utils/types/MandateProps.js +1 -0
  73. package/lib/utils/types/index.d.ts +1 -0
  74. package/lib/utils/types/index.js +13 -0
  75. package/lib-esm/ActionList/Item.js +1 -1
  76. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
  77. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
  78. package/lib-esm/Autocomplete/Autocomplete.d.ts +304 -0
  79. package/lib-esm/Autocomplete/Autocomplete.js +123 -0
  80. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
  81. package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
  82. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +292 -0
  83. package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
  84. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
  85. package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
  86. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
  87. package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
  88. package/lib-esm/Autocomplete/index.d.ts +2 -0
  89. package/lib-esm/Autocomplete/index.js +1 -0
  90. package/lib-esm/BaseStyles.js +1 -1
  91. package/lib-esm/BorderBox.js +1 -1
  92. package/lib-esm/Button/ButtonInvisible.js +1 -1
  93. package/lib-esm/Caret.js +2 -2
  94. package/lib-esm/Dialog.js +1 -1
  95. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
  96. package/lib-esm/Flash.js +16 -16
  97. package/lib-esm/Label.js +1 -1
  98. package/lib-esm/Overlay.d.ts +1 -0
  99. package/lib-esm/Overlay.js +3 -1
  100. package/lib-esm/ProgressBar.js +1 -1
  101. package/lib-esm/StateLabel.js +13 -19
  102. package/lib-esm/Token/_RemoveTokenButton.js +1 -1
  103. package/lib-esm/__tests__/Autocomplete.test.d.ts +1 -0
  104. package/lib-esm/__tests__/Autocomplete.test.js +494 -0
  105. package/lib-esm/__tests__/BorderBox.test.js +1 -1
  106. package/lib-esm/__tests__/CircleOcticon.test.js +1 -1
  107. package/lib-esm/__tests__/CounterLabel.test.js +4 -4
  108. package/lib-esm/__tests__/Flash.test.js +4 -4
  109. package/lib-esm/__tests__/Link.test.js +1 -1
  110. package/lib-esm/__tests__/behaviors/scrollIntoViewingArea.test.d.ts +1 -0
  111. package/lib-esm/__tests__/behaviors/scrollIntoViewingArea.test.js +224 -0
  112. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
  113. package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
  114. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
  115. package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
  116. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  117. package/lib-esm/hooks/useOverlay.js +4 -2
  118. package/lib-esm/index.d.ts +2 -0
  119. package/lib-esm/index.js +1 -0
  120. package/lib-esm/stories/Autocomplete.stories.js +549 -0
  121. package/lib-esm/stories/Dialog.stories.js +3 -3
  122. package/lib-esm/stories/IssueLabelToken.stories.js +1 -1
  123. package/lib-esm/stories/ProfileToken.stories.js +1 -1
  124. package/lib-esm/theme-preval.js +370 -3100
  125. package/lib-esm/utils/testing.d.ts +50 -493
  126. package/lib-esm/utils/types/MandateProps.d.ts +3 -0
  127. package/lib-esm/utils/types/MandateProps.js +1 -0
  128. package/lib-esm/utils/types/index.d.ts +1 -0
  129. package/lib-esm/utils/types/index.js +2 -1
  130. package/package-lock.json +11 -8
  131. package/package.json +3 -3
  132. package/src/ActionList/Item.tsx +1 -1
  133. package/src/AnchoredOverlay/AnchoredOverlay.tsx +14 -3
  134. package/src/Autocomplete/Autocomplete.tsx +103 -0
  135. package/src/Autocomplete/AutocompleteContext.tsx +19 -0
  136. package/src/Autocomplete/AutocompleteInput.tsx +179 -0
  137. package/src/Autocomplete/AutocompleteMenu.tsx +341 -0
  138. package/src/Autocomplete/AutocompleteOverlay.tsx +68 -0
  139. package/src/Autocomplete/index.ts +2 -0
  140. package/src/BaseStyles.tsx +1 -1
  141. package/src/BorderBox.tsx +1 -1
  142. package/src/Button/ButtonInvisible.tsx +7 -2
  143. package/src/Caret.tsx +2 -2
  144. package/src/Dialog.tsx +1 -1
  145. package/src/FilteredActionList/FilteredActionList.tsx +10 -25
  146. package/src/Flash.tsx +16 -16
  147. package/src/Label.tsx +1 -1
  148. package/src/Overlay.tsx +4 -1
  149. package/src/ProgressBar.tsx +1 -1
  150. package/src/StateLabel.tsx +12 -20
  151. package/src/Token/_RemoveTokenButton.tsx +4 -2
  152. package/src/__tests__/Autocomplete.test.tsx +444 -0
  153. package/src/__tests__/BorderBox.test.tsx +1 -1
  154. package/src/__tests__/CircleOcticon.test.tsx +1 -1
  155. package/src/__tests__/CounterLabel.test.tsx +4 -4
  156. package/src/__tests__/Flash.test.tsx +4 -4
  157. package/src/__tests__/Link.test.tsx +1 -1
  158. package/src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap +3 -3
  159. package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +3414 -0
  160. package/src/__tests__/__snapshots__/Button.test.tsx.snap +9 -1
  161. package/src/__tests__/__snapshots__/ConfirmationDialog.test.tsx.snap +1 -1
  162. package/src/__tests__/__snapshots__/SelectPanel.test.tsx.snap +1 -1
  163. package/src/__tests__/__snapshots__/StateLabel.test.tsx.snap +0 -21
  164. package/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +16 -16
  165. package/src/__tests__/__snapshots__/Token.test.tsx.snap +34 -34
  166. package/src/__tests__/behaviors/scrollIntoViewingArea.test.ts +195 -0
  167. package/src/behaviors/scrollIntoViewingArea.ts +27 -0
  168. package/src/hooks/useOpenAndCloseFocus.ts +7 -2
  169. package/src/hooks/useOverlay.tsx +4 -2
  170. package/src/index.ts +2 -0
  171. package/src/stories/Autocomplete.stories.tsx +572 -0
  172. package/src/stories/Dialog.stories.tsx +3 -3
  173. package/src/stories/IssueLabelToken.stories.tsx +1 -1
  174. package/src/stories/ProfileToken.stories.tsx +1 -1
  175. package/src/utils/types/MandateProps.ts +19 -0
  176. package/src/utils/types/index.ts +1 -0
  177. package/stats.html +1 -1
  178. package/docs/src/@primer/gatsby-theme-doctocat/components/live-code.js +0 -84
  179. package/docs/src/@primer/gatsby-theme-doctocat/components/nav-dropdown.js +0 -48
  180. package/docs/src/@primer/gatsby-theme-doctocat/components/wrap-page-element.js +0 -25
@@ -0,0 +1,89 @@
1
+ ---
2
+ title: TextInputWithTokens
3
+ status: Alpha
4
+ source: https://github.com/primer/react/tree/main/src/TextInputWithTokens.tsx
5
+ ---
6
+
7
+ import {Props} from '../src/props'
8
+ import {TextInputWithTokens} from '@primer/components'
9
+
10
+ A `TextInputWithTokens` component is used to show multiple values in one field.
11
+
12
+ It supports all of the features of a [TextInput](/TextInput) component, but it can render a list of [Tokens](/Token) next to the area a user types in.
13
+
14
+ ## Basic Example
15
+
16
+ ```javascript live noinline
17
+ const BasicExample = () => {
18
+ const [tokens, setTokens] = React.useState([
19
+ {text: 'zero', id: 0},
20
+ {text: 'one', id: 1},
21
+ {text: 'two', id: 2}
22
+ ])
23
+ const onTokenRemove = tokenId => {
24
+ setTokens(tokens.filter(token => token.id !== tokenId))
25
+ }
26
+
27
+ return (
28
+ <>
29
+ <Box as="label" display="block" htmlFor="inputWithTokens-basic">
30
+ Basic example tokens
31
+ </Box>
32
+ <TextInputWithTokens tokens={tokens} onTokenRemove={onTokenRemove} id="inputWithTokens-basic" />
33
+ </>
34
+ )
35
+ }
36
+
37
+ render(BasicExample)
38
+ ```
39
+
40
+ ## Component Props
41
+
42
+ <Props of={TextInputWithTokens} />
43
+
44
+ ## Adding and removing tokens
45
+
46
+ The array passed to the `tokens` prop needs to be manually updated to add and remove tokens.
47
+
48
+ The function passed to the `onRemoveToken` prop is called when:
49
+
50
+ - Clicking the remove button in the token
51
+ - Pressing the `Backspace` key when the input is empty
52
+ - Selecting a token using the arrow keys or by clicking on a token and then pressing the `Backspace` key
53
+
54
+ There is no function that gets called to "add" a token, so the user needs to be provided with a UI to select tokens.
55
+
56
+ ## Custom token rendering
57
+
58
+ By default, the `Token` component is used to render the tokens in the input. If this component does not make sense for the kinds of tokens you're rendering, you can pass a component to the `tokenComponent` prop
59
+
60
+ Example: a `TextInputWithTokens` that renders tokens as `IssueLabelToken`:
61
+
62
+ ```javascript live noinline
63
+ const UsingIssueLabelTokens = () => {
64
+ const [tokens, setTokens] = React.useState([
65
+ {text: 'enhancement', id: 1, fillColor: '#a2eeef'},
66
+ {text: 'bug', id: 2, fillColor: '#d73a4a'},
67
+ {text: 'good first issue', id: 3, fillColor: '#0cf478'}
68
+ ])
69
+ const onTokenRemove = tokenId => {
70
+ setTokens(tokens.filter(token => token.id !== tokenId))
71
+ }
72
+
73
+ return (
74
+ <>
75
+ <Box as="label" display="block" htmlFor="inputWithTokens-issueLabels">
76
+ Issue labels
77
+ </Box>
78
+ <TextInputWithTokens
79
+ tokenComponent={IssueLabelToken}
80
+ tokens={tokens}
81
+ onTokenRemove={onTokenRemove}
82
+ id="inputWithTokens-issueLabels"
83
+ />
84
+ </>
85
+ )
86
+ }
87
+
88
+ render(<UsingIssueLabelTokens />)
89
+ ```
@@ -90,7 +90,7 @@ import {BaseStyles, Box, Heading} from '@primer/components'
90
90
  export default () => (
91
91
  <BaseStyles>
92
92
  <Box m={4}>
93
- <Heading mb={2}>Hello, world!</Heading>
93
+ <Heading sx={{mb: 2}}>Hello, world!</Heading>
94
94
  <p>This will get Primer text styles.</p>
95
95
  </Box>
96
96
  </BaseStyles>
@@ -25,10 +25,11 @@ This example demonstrates applying a bottom border to `Heading`, a component tha
25
25
  pb={2}
26
26
  sx={{
27
27
  borderBottomWidth: 1,
28
- borderBottomColor: 'border.primary',
28
+ borderBottomColor: 'border.default',
29
29
  borderBottomStyle: 'solid'
30
- }}>
31
- Heading with bottom border
30
+ }}
31
+ >
32
+ Heading with bottom border
32
33
  </Heading>
33
34
  </>
34
35
  ```
@@ -45,7 +46,7 @@ Just like [values passed to system props](https://styled-system.com/responsive-s
45
46
  borderRadius={2}
46
47
  p={2}
47
48
  sx={{
48
- bg: ['bg.primary', 'bg.info', 'bg.success', 'bg.warning', 'bg.danger']
49
+ bg: ['neutral.subtle', 'accent.subtle', 'success.subtle', 'attention.subtle', 'danger.subtle']
49
50
  }}
50
51
  >
51
52
  Responsive background color
@@ -61,7 +62,7 @@ The `sx` prop also allows for declaring styles based on media queries, psueudo-c
61
62
  sx={{
62
63
  '> *': {
63
64
  borderWidth: 1,
64
- borderColor: "border.default",
65
+ borderColor: 'border.default',
65
66
  borderStyle: 'solid',
66
67
  borderBottomWidth: 0,
67
68
  padding: 2,
@@ -69,7 +70,7 @@ The `sx` prop also allows for declaring styles based on media queries, psueudo-c
69
70
  borderBottomWidth: 1
70
71
  },
71
72
  ':hover': {
72
- bg: "neutral.muted"
73
+ bg: 'neutral.muted'
73
74
  }
74
75
  }
75
76
  }}
@@ -57,8 +57,8 @@ Some [system props](/system-props) and [`sx` prop](/overriding-styles) keys are
57
57
  ```jsx
58
58
  const theme = {
59
59
  colors: {
60
- bg: {
61
- primary: '#fff'
60
+ canvas: {
61
+ default: '#fff'
62
62
  }
63
63
  }
64
64
  }
@@ -67,7 +67,7 @@ function App() {
67
67
  return (
68
68
  <ThemeProvider theme={theme}>
69
69
  <Box bg="canvas.default"></Box>
70
- <Box sx={{bg: "canvas.default"}}></Box>
70
+ <Box sx={{bg: 'canvas.default'}}></Box>
71
71
  </ThemeProvider>
72
72
  )
73
73
  }
@@ -84,7 +84,7 @@ import {themeGet} from '@primer/components'
84
84
  import styled from 'styled-components'
85
85
 
86
86
  const Example = styled.div`
87
- background-color: ${themeGet("colors.canvas.default")};
87
+ background-color: ${themeGet('colors.canvas.default')};
88
88
  `
89
89
  ```
90
90
 
@@ -97,7 +97,7 @@ import {ThemeProvider, useTheme} from '@primer/components'
97
97
 
98
98
  function Example() {
99
99
  const {theme} = useTheme()
100
- // theme.colors.bg.primary
100
+ // theme.colors.canvas.default
101
101
  }
102
102
 
103
103
  function App() {