@primer/components 31.0.2-rc.c7dafefb → 31.2.0-rc.a53b3afb

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 (100) hide show
  1. package/.storybook/main.js +7 -9
  2. package/.storybook/preview.js +5 -1
  3. package/CHANGELOG.md +11 -1
  4. package/dist/browser.esm.js +11 -10
  5. package/dist/browser.esm.js.map +1 -1
  6. package/dist/browser.umd.js +11 -10
  7. package/dist/browser.umd.js.map +1 -1
  8. package/docs/content/FilterList.md +2 -2
  9. package/docs/content/TextInputWithTokens.mdx +114 -0
  10. package/docs/content/theming.md +23 -0
  11. package/lib/Autocomplete/Autocomplete.d.ts +4 -4
  12. package/lib/Autocomplete/AutocompleteInput.d.ts +4 -4
  13. package/lib/Button/Button.d.ts +5 -5
  14. package/lib/Button/ButtonBase.d.ts +1 -1
  15. package/lib/Button/ButtonClose.d.ts +3 -3
  16. package/lib/Button/ButtonDanger.d.ts +5 -5
  17. package/lib/Button/ButtonInvisible.d.ts +5 -5
  18. package/lib/Button/ButtonOutline.d.ts +5 -5
  19. package/lib/Button/ButtonPrimary.d.ts +5 -5
  20. package/lib/CircleBadge.d.ts +2 -2
  21. package/lib/CircleOcticon.d.ts +4 -4
  22. package/lib/Dialog.d.ts +4 -4
  23. package/lib/Dropdown.d.ts +16 -16
  24. package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
  25. package/lib/FilterList.d.ts +3 -3
  26. package/lib/Flash.d.ts +1 -1
  27. package/lib/Label.d.ts +1 -1
  28. package/lib/Position.d.ts +4 -4
  29. package/lib/ProgressBar.d.ts +1 -1
  30. package/lib/SelectMenu/SelectMenu.d.ts +24 -24
  31. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  32. package/lib/TextInputWithTokens.d.ts +8 -4
  33. package/lib/TextInputWithTokens.js +61 -8
  34. package/lib/Timeline.d.ts +4 -4
  35. package/lib/Token/AvatarToken.d.ts +1 -1
  36. package/lib/Token/IssueLabelToken.d.ts +1 -1
  37. package/lib/Token/Token.d.ts +1 -1
  38. package/lib/_TextInputWrapper.d.ts +1 -1
  39. package/lib/_TextInputWrapper.js +1 -1
  40. package/lib/__tests__/KeyPaths.types.test.d.ts +10 -0
  41. package/lib/__tests__/KeyPaths.types.test.js +10 -0
  42. package/lib/__tests__/TextInputWithTokens.test.js +149 -9
  43. package/lib/stories/TextInputWithTokens.stories.js +18 -1
  44. package/lib/sx.d.ts +8 -2
  45. package/lib/theme.d.ts +78 -0
  46. package/lib/theme.js +3 -1
  47. package/lib/utils/types/KeyPaths.d.ts +3 -0
  48. package/lib/utils/types/KeyPaths.js +1 -0
  49. package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -4
  50. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -4
  51. package/lib-esm/Button/Button.d.ts +5 -5
  52. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  53. package/lib-esm/Button/ButtonClose.d.ts +3 -3
  54. package/lib-esm/Button/ButtonDanger.d.ts +5 -5
  55. package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
  56. package/lib-esm/Button/ButtonOutline.d.ts +5 -5
  57. package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
  58. package/lib-esm/CircleBadge.d.ts +2 -2
  59. package/lib-esm/CircleOcticon.d.ts +4 -4
  60. package/lib-esm/Dialog.d.ts +4 -4
  61. package/lib-esm/Dropdown.d.ts +16 -16
  62. package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
  63. package/lib-esm/FilterList.d.ts +3 -3
  64. package/lib-esm/Flash.d.ts +1 -1
  65. package/lib-esm/Label.d.ts +1 -1
  66. package/lib-esm/Position.d.ts +4 -4
  67. package/lib-esm/ProgressBar.d.ts +1 -1
  68. package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
  69. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  70. package/lib-esm/TextInputWithTokens.d.ts +8 -4
  71. package/lib-esm/TextInputWithTokens.js +60 -8
  72. package/lib-esm/Timeline.d.ts +4 -4
  73. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  74. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  75. package/lib-esm/Token/Token.d.ts +1 -1
  76. package/lib-esm/_TextInputWrapper.d.ts +1 -1
  77. package/lib-esm/_TextInputWrapper.js +1 -1
  78. package/lib-esm/__tests__/KeyPaths.types.test.d.ts +10 -0
  79. package/lib-esm/__tests__/KeyPaths.types.test.js +3 -0
  80. package/lib-esm/__tests__/TextInputWithTokens.test.js +142 -9
  81. package/lib-esm/stories/TextInputWithTokens.stories.js +14 -0
  82. package/lib-esm/sx.d.ts +8 -2
  83. package/lib-esm/theme.d.ts +78 -0
  84. package/lib-esm/theme.js +2 -1
  85. package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
  86. package/lib-esm/utils/types/KeyPaths.js +1 -0
  87. package/package-lock.json +37942 -41
  88. package/package.json +2 -1
  89. package/src/TextInputWithTokens.tsx +64 -8
  90. package/src/_TextInputWrapper.tsx +1 -0
  91. package/src/__tests__/KeyPaths.types.test.ts +13 -0
  92. package/src/__tests__/TextInputWithTokens.test.tsx +133 -1
  93. package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +7 -0
  94. package/src/__tests__/__snapshots__/TextInput.test.tsx.snap +6 -0
  95. package/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +463 -0
  96. package/src/stories/TextInputWithTokens.stories.tsx +9 -0
  97. package/src/sx.ts +14 -2
  98. package/src/theme.ts +86 -0
  99. package/src/utils/types/KeyPaths.ts +4 -0
  100. package/stats.html +1 -1
@@ -121,6 +121,15 @@ export const TokenRemoveButtonsHidden = () => {
121
121
  return <TextInputWithTokens hideTokenRemoveButtons tokens={tokens} onTokenRemove={onTokenRemove} />
122
122
  }
123
123
 
124
+ export const WithVisibleTokenCount = () => {
125
+ const [tokens, setTokens] = useState([...mockTokens].slice(0, 5))
126
+ const onTokenRemove: (tokenId: string | number) => void = tokenId => {
127
+ setTokens(tokens.filter(token => token.id !== tokenId))
128
+ }
129
+
130
+ return <TextInputWithTokens tokens={tokens} onTokenRemove={onTokenRemove} visibleTokenCount={2} />
131
+ }
132
+
124
133
  export const Unstyled = () => {
125
134
  const [tokens, setTokens] = useState([...mockTokens].slice(0, 2))
126
135
  const onTokenRemove: (tokenId: string | number) => void = tokenId => {
package/src/sx.ts CHANGED
@@ -1,7 +1,19 @@
1
- import css, {SystemStyleObject} from '@styled-system/css'
1
+ import css, {SystemCssProperties, SystemStyleObject} from '@styled-system/css'
2
+ import {ThemeColorPaths, ThemeShadowPaths} from './theme'
3
+ import {ColorProps, ShadowProps} from 'styled-system'
4
+
5
+ export type BetterCssProperties = {
6
+ [K in keyof SystemCssProperties]: K extends keyof ColorProps
7
+ ? ThemeColorPaths | SystemCssProperties[K]
8
+ : K extends keyof ShadowProps
9
+ ? ThemeShadowPaths | SystemCssProperties[K]
10
+ : SystemCssProperties[K]
11
+ }
12
+
13
+ export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject
2
14
 
3
15
  export interface SxProp {
4
- sx?: SystemStyleObject
16
+ sx?: BetterSystemStyleObject
5
17
  }
6
18
 
7
19
  const sx = (props: SxProp) => css(props.sx)
package/src/theme.ts CHANGED
@@ -1,3 +1,89 @@
1
1
  import {theme} from './theme-preval'
2
+ import {KeyPaths} from './utils/types/KeyPaths'
2
3
 
3
4
  export default theme
5
+
6
+ // NOTE: for now, ThemeColors and ThemeShadows are handcrafted types. It would be nice if these
7
+ // were exports from primitives (or a different shape but derived from those exports).
8
+
9
+ type ThemeColors = {
10
+ fg: {
11
+ default: string
12
+ muted: string
13
+ subtle: string
14
+ onEmphasis: string
15
+ }
16
+ canvas: {
17
+ default: string
18
+ overlay: string
19
+ inset: string
20
+ subtle: string
21
+ }
22
+ border: {
23
+ default: string
24
+ muted: string
25
+ subtle: string
26
+ }
27
+
28
+ // Roles
29
+ neutral: {
30
+ emphasisPlus: string
31
+ emphasis: string
32
+ muted: string
33
+ subtle: string
34
+ }
35
+ accent: {
36
+ fg: string
37
+ emphasis: string
38
+ muted: string
39
+ subtle: string
40
+ }
41
+ success: {
42
+ fg: string
43
+ emphasis: string
44
+ muted: string
45
+ subtle: string
46
+ }
47
+ attention: {
48
+ fg: string
49
+ emphasis: string
50
+ muted: string
51
+ subtle: string
52
+ }
53
+ severe: {
54
+ fg: string
55
+ emphasis: string
56
+ muted: string
57
+ subtle: string
58
+ }
59
+ danger: {
60
+ fg: string
61
+ emphasis: string
62
+ muted: string
63
+ subtle: string
64
+ }
65
+ done: {
66
+ fg: string
67
+ emphasis: string
68
+ muted: string
69
+ subtle: string
70
+ }
71
+ sponsors: {
72
+ fg: string
73
+ emphasis: string
74
+ muted: string
75
+ subtle: string
76
+ }
77
+ }
78
+
79
+ type ThemeShadows = {
80
+ shadow: {
81
+ small: string
82
+ medium: string
83
+ large: string
84
+ extraLarge: string
85
+ }
86
+ }
87
+
88
+ export type ThemeColorPaths = KeyPaths<ThemeColors>
89
+ export type ThemeShadowPaths = KeyPaths<ThemeShadows>
@@ -0,0 +1,4 @@
1
+ // Produces a union of dot-delimited keypaths to the string values in a nested object:
2
+ export type KeyPaths<O extends Record<string, unknown>> = {
3
+ [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never
4
+ }[keyof O]