@primer/components 31.0.2-rc.c7dafefb → 31.2.0-rc.25d7c83f

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 (230) hide show
  1. package/.storybook/main.js +7 -9
  2. package/.storybook/preview.js +5 -1
  3. package/CHANGELOG.md +23 -1
  4. package/dist/browser.esm.js +623 -620
  5. package/dist/browser.esm.js.map +1 -1
  6. package/dist/browser.umd.js +164 -161
  7. package/dist/browser.umd.js.map +1 -1
  8. package/docs/content/ActionList2.mdx +354 -0
  9. package/docs/content/FilterList.md +2 -2
  10. package/docs/content/TextInputWithTokens.mdx +114 -0
  11. package/docs/content/getting-started.md +1 -1
  12. package/docs/content/theming.md +23 -0
  13. package/docs/src/@primer/gatsby-theme-doctocat/components/hero.js +1 -3
  14. package/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js +1 -1
  15. package/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js +17 -0
  16. package/lib/ActionList/Header.js +1 -1
  17. package/lib/ActionList2/Description.d.ts +12 -0
  18. package/lib/ActionList2/Description.js +53 -0
  19. package/lib/ActionList2/Divider.d.ts +5 -0
  20. package/lib/ActionList2/Divider.js +35 -0
  21. package/lib/ActionList2/Group.d.ts +11 -0
  22. package/lib/ActionList2/Group.js +57 -0
  23. package/lib/ActionList2/Header.d.ts +26 -0
  24. package/lib/ActionList2/Header.js +55 -0
  25. package/lib/ActionList2/Item.d.ts +63 -0
  26. package/lib/ActionList2/Item.js +234 -0
  27. package/lib/ActionList2/LinkItem.d.ts +17 -0
  28. package/lib/ActionList2/LinkItem.js +57 -0
  29. package/lib/ActionList2/List.d.ts +26 -0
  30. package/lib/ActionList2/List.js +59 -0
  31. package/lib/ActionList2/Selection.d.ts +5 -0
  32. package/lib/ActionList2/Selection.js +70 -0
  33. package/lib/ActionList2/Visuals.d.ts +9 -0
  34. package/lib/ActionList2/Visuals.js +90 -0
  35. package/lib/ActionList2/index.d.ts +36 -0
  36. package/lib/ActionList2/index.js +47 -0
  37. package/lib/Autocomplete/Autocomplete.d.ts +4 -4
  38. package/lib/Autocomplete/AutocompleteInput.d.ts +4 -4
  39. package/lib/Button/Button.d.ts +5 -5
  40. package/lib/Button/ButtonBase.d.ts +1 -1
  41. package/lib/Button/ButtonClose.d.ts +3 -3
  42. package/lib/Button/ButtonDanger.d.ts +5 -5
  43. package/lib/Button/ButtonInvisible.d.ts +5 -5
  44. package/lib/Button/ButtonOutline.d.ts +5 -5
  45. package/lib/Button/ButtonPrimary.d.ts +5 -5
  46. package/lib/CircleBadge.d.ts +2 -2
  47. package/lib/CircleOcticon.d.ts +4 -4
  48. package/lib/Dialog.d.ts +4 -4
  49. package/lib/Dropdown.d.ts +16 -16
  50. package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
  51. package/lib/FilterList.d.ts +3 -3
  52. package/lib/Flash.d.ts +1 -1
  53. package/lib/Label.d.ts +1 -1
  54. package/lib/Overlay.js +3 -1
  55. package/lib/Portal/Portal.js +3 -2
  56. package/lib/Position.d.ts +4 -4
  57. package/lib/ProgressBar.d.ts +1 -1
  58. package/lib/SelectMenu/SelectMenu.d.ts +24 -24
  59. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  60. package/lib/TextInputWithTokens.d.ts +8 -4
  61. package/lib/TextInputWithTokens.js +61 -8
  62. package/lib/Timeline.d.ts +4 -4
  63. package/lib/Token/AvatarToken.d.ts +1 -1
  64. package/lib/Token/IssueLabelToken.d.ts +1 -1
  65. package/lib/Token/Token.d.ts +1 -1
  66. package/lib/_TextInputWrapper.d.ts +1 -1
  67. package/lib/_TextInputWrapper.js +2 -2
  68. package/lib/__tests__/ActionList2.test.d.ts +1 -0
  69. package/lib/__tests__/ActionList2.test.js +53 -0
  70. package/lib/__tests__/AnchoredOverlay.test.js +4 -2
  71. package/lib/__tests__/KeyPaths.types.test.d.ts +11 -0
  72. package/lib/__tests__/KeyPaths.types.test.js +10 -0
  73. package/lib/__tests__/TextInputWithTokens.test.js +138 -7
  74. package/lib/__tests__/utils/createSlots.test.d.ts +1 -0
  75. package/lib/__tests__/utils/createSlots.test.js +75 -0
  76. package/lib/hooks/useAnchoredPosition.js +3 -2
  77. package/lib/hooks/useCombinedRefs.d.ts +2 -2
  78. package/lib/hooks/useCombinedRefs.js +4 -6
  79. package/lib/hooks/useResizeObserver.js +2 -2
  80. package/lib/stories/ActionList2.stories.js +907 -0
  81. package/lib/stories/TextInput.stories.js +144 -0
  82. package/lib/stories/TextInputWithTokens.stories.js +18 -1
  83. package/lib/stories/Token.stories.js +19 -2
  84. package/lib/sx.d.ts +10 -2
  85. package/lib/sx.js +8 -0
  86. package/lib/theme-preval.js +81 -2
  87. package/lib/theme.d.ts +78 -0
  88. package/lib/theme.js +3 -1
  89. package/lib/unreleased.d.ts +7 -0
  90. package/lib/unreleased.js +18 -0
  91. package/lib/utils/create-slots.d.ts +17 -0
  92. package/lib/utils/create-slots.js +105 -0
  93. package/lib/utils/testing.d.ts +14 -1
  94. package/lib/utils/types/KeyPaths.d.ts +3 -0
  95. package/lib/utils/types/KeyPaths.js +1 -0
  96. package/lib/utils/use-force-update.d.ts +1 -0
  97. package/lib/utils/use-force-update.js +19 -0
  98. package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  99. package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
  100. package/lib-esm/ActionList/Header.js +1 -1
  101. package/lib-esm/ActionList2/Description.d.ts +12 -0
  102. package/lib-esm/ActionList2/Description.js +37 -0
  103. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  104. package/lib-esm/ActionList2/Divider.js +23 -0
  105. package/lib-esm/ActionList2/Group.d.ts +11 -0
  106. package/lib-esm/ActionList2/Group.js +40 -0
  107. package/lib-esm/ActionList2/Header.d.ts +26 -0
  108. package/lib-esm/ActionList2/Header.js +44 -0
  109. package/lib-esm/ActionList2/Item.d.ts +63 -0
  110. package/lib-esm/ActionList2/Item.js +201 -0
  111. package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
  112. package/lib-esm/ActionList2/LinkItem.js +43 -0
  113. package/lib-esm/ActionList2/List.d.ts +26 -0
  114. package/lib-esm/ActionList2/List.js +37 -0
  115. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  116. package/lib-esm/ActionList2/Selection.js +52 -0
  117. package/lib-esm/ActionList2/Visuals.d.ts +9 -0
  118. package/lib-esm/ActionList2/Visuals.js +68 -0
  119. package/lib-esm/ActionList2/index.d.ts +36 -0
  120. package/lib-esm/ActionList2/index.js +33 -0
  121. package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -4
  122. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -4
  123. package/lib-esm/Button/Button.d.ts +5 -5
  124. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  125. package/lib-esm/Button/ButtonClose.d.ts +3 -3
  126. package/lib-esm/Button/ButtonDanger.d.ts +5 -5
  127. package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
  128. package/lib-esm/Button/ButtonOutline.d.ts +5 -5
  129. package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
  130. package/lib-esm/CircleBadge.d.ts +2 -2
  131. package/lib-esm/CircleOcticon.d.ts +4 -4
  132. package/lib-esm/Dialog.d.ts +4 -4
  133. package/lib-esm/Dropdown.d.ts +16 -16
  134. package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
  135. package/lib-esm/FilterList.d.ts +3 -3
  136. package/lib-esm/Flash.d.ts +1 -1
  137. package/lib-esm/Label.d.ts +1 -1
  138. package/lib-esm/Overlay.js +2 -1
  139. package/lib-esm/Portal/Portal.js +2 -1
  140. package/lib-esm/Position.d.ts +4 -4
  141. package/lib-esm/ProgressBar.d.ts +1 -1
  142. package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
  143. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  144. package/lib-esm/TextInputWithTokens.d.ts +8 -4
  145. package/lib-esm/TextInputWithTokens.js +60 -8
  146. package/lib-esm/Timeline.d.ts +4 -4
  147. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  148. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  149. package/lib-esm/Token/Token.d.ts +1 -1
  150. package/lib-esm/_TextInputWrapper.d.ts +1 -1
  151. package/lib-esm/_TextInputWrapper.js +2 -2
  152. package/lib-esm/__tests__/ActionList2.test.d.ts +1 -0
  153. package/lib-esm/__tests__/ActionList2.test.js +41 -0
  154. package/lib-esm/__tests__/AnchoredOverlay.test.js +4 -2
  155. package/lib-esm/__tests__/KeyPaths.types.test.d.ts +11 -0
  156. package/lib-esm/__tests__/KeyPaths.types.test.js +3 -0
  157. package/lib-esm/__tests__/TextInputWithTokens.test.js +132 -8
  158. package/lib-esm/__tests__/utils/createSlots.test.d.ts +1 -0
  159. package/lib-esm/__tests__/utils/createSlots.test.js +67 -0
  160. package/lib-esm/hooks/useAnchoredPosition.js +2 -1
  161. package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
  162. package/lib-esm/hooks/useCombinedRefs.js +3 -2
  163. package/lib-esm/hooks/useResizeObserver.js +2 -2
  164. package/lib-esm/stories/ActionList2.stories.js +796 -0
  165. package/lib-esm/stories/TextInput.stories.js +117 -0
  166. package/lib-esm/stories/TextInputWithTokens.stories.js +14 -0
  167. package/lib-esm/stories/Token.stories.js +14 -1
  168. package/lib-esm/sx.d.ts +10 -2
  169. package/lib-esm/sx.js +3 -1
  170. package/lib-esm/theme-preval.js +81 -2
  171. package/lib-esm/theme.d.ts +78 -0
  172. package/lib-esm/theme.js +2 -1
  173. package/lib-esm/unreleased.d.ts +7 -0
  174. package/lib-esm/unreleased.js +8 -0
  175. package/lib-esm/utils/create-slots.d.ts +17 -0
  176. package/lib-esm/utils/create-slots.js +84 -0
  177. package/lib-esm/utils/testing.d.ts +14 -1
  178. package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
  179. package/lib-esm/utils/types/KeyPaths.js +1 -0
  180. package/lib-esm/utils/use-force-update.d.ts +1 -0
  181. package/lib-esm/utils/use-force-update.js +6 -0
  182. package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  183. package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
  184. package/migrating.md +1 -1
  185. package/package-lock.json +38098 -45
  186. package/package.json +7 -3
  187. package/script/build +2 -0
  188. package/src/ActionList/Header.tsx +1 -1
  189. package/src/ActionList2/Description.tsx +49 -0
  190. package/src/ActionList2/Divider.tsx +24 -0
  191. package/src/ActionList2/Group.tsx +34 -0
  192. package/src/ActionList2/Header.tsx +58 -0
  193. package/src/ActionList2/Item.tsx +223 -0
  194. package/src/ActionList2/LinkItem.tsx +49 -0
  195. package/src/ActionList2/List.tsx +55 -0
  196. package/src/ActionList2/Selection.tsx +40 -0
  197. package/src/ActionList2/Visuals.tsx +76 -0
  198. package/src/ActionList2/index.ts +39 -0
  199. package/src/Overlay.tsx +2 -1
  200. package/src/Portal/Portal.tsx +2 -1
  201. package/src/TextInputWithTokens.tsx +64 -8
  202. package/src/_TextInputWrapper.tsx +8 -0
  203. package/src/__tests__/ActionList2.test.tsx +47 -0
  204. package/src/__tests__/AnchoredOverlay.test.tsx +2 -2
  205. package/src/__tests__/KeyPaths.types.test.ts +14 -0
  206. package/src/__tests__/TextInputWithTokens.test.tsx +123 -1
  207. package/src/__tests__/__snapshots__/ActionList2.test.tsx.snap +14 -0
  208. package/src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap +35 -135
  209. package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +7 -0
  210. package/src/__tests__/__snapshots__/TextInput.test.tsx.snap +6 -0
  211. package/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +463 -0
  212. package/src/__tests__/utils/__snapshots__/createSlots.test.tsx.snap +55 -0
  213. package/src/__tests__/utils/createSlots.test.tsx +74 -0
  214. package/src/hooks/useAnchoredPosition.ts +2 -1
  215. package/src/hooks/useCombinedRefs.ts +3 -3
  216. package/src/hooks/useResizeObserver.ts +2 -2
  217. package/src/stories/ActionList2.stories.tsx +1290 -0
  218. package/src/stories/Button.stories.tsx +1 -1
  219. package/src/stories/TextInput.stories.tsx +113 -0
  220. package/src/stories/TextInputWithTokens.stories.tsx +9 -0
  221. package/src/stories/Token.stories.tsx +12 -1
  222. package/src/sx.ts +17 -2
  223. package/src/theme-preval.js +1 -0
  224. package/src/theme.ts +86 -0
  225. package/src/unreleased.ts +9 -0
  226. package/src/utils/create-slots.tsx +96 -0
  227. package/src/utils/types/KeyPaths.ts +10 -0
  228. package/src/utils/use-force-update.ts +7 -0
  229. package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
  230. package/stats.html +1 -1
@@ -0,0 +1,1290 @@
1
+ import {
2
+ ServerIcon,
3
+ PlusCircleIcon,
4
+ TypographyIcon,
5
+ VersionsIcon,
6
+ SearchIcon,
7
+ NoteIcon,
8
+ ProjectIcon,
9
+ FilterIcon,
10
+ GearIcon,
11
+ ArrowRightIcon,
12
+ ArrowLeftIcon,
13
+ LinkIcon,
14
+ LawIcon,
15
+ StarIcon,
16
+ GitForkIcon,
17
+ AlertIcon,
18
+ TableIcon,
19
+ PeopleIcon,
20
+ CalendarIcon,
21
+ IssueOpenedIcon,
22
+ NumberIcon,
23
+ XIcon,
24
+ RepoIcon
25
+ } from '@primer/octicons-react'
26
+ import {Meta} from '@storybook/react'
27
+ import React, {forwardRef} from 'react'
28
+ import styled from 'styled-components'
29
+ import {DndProvider, useDrag, useDrop} from 'react-dnd'
30
+ import {HTML5Backend} from 'react-dnd-html5-backend'
31
+ import {Label, ThemeProvider} from '..'
32
+ import {ActionList as _ActionList, ItemProps} from '../ActionList2'
33
+ import {Header} from '../ActionList/Header'
34
+ import BaseStyles from '../BaseStyles'
35
+ import Avatar from '../Avatar'
36
+ import {ButtonInvisible} from '../Button'
37
+ import TextInput from '../TextInput'
38
+ import Spinner from '../Spinner'
39
+ import Box from '../Box'
40
+ import {AnchoredOverlay} from '../AnchoredOverlay'
41
+
42
+ const ActionList = Object.assign(_ActionList, {
43
+ Header
44
+ })
45
+
46
+ const meta: Meta = {
47
+ title: 'Composite components/ActionList2',
48
+ component: ActionList,
49
+ decorators: [
50
+ (Story: React.ComponentType): JSX.Element => (
51
+ <ThemeProvider>
52
+ <BaseStyles>
53
+ <Story />
54
+ </BaseStyles>
55
+ </ThemeProvider>
56
+ )
57
+ ],
58
+ parameters: {
59
+ controls: {
60
+ disable: true
61
+ }
62
+ }
63
+ }
64
+ export default meta
65
+
66
+ const ErsatzOverlay = styled.div<{maxWidth?: string}>`
67
+ border-radius: 12px;
68
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(149, 157, 165, 0.2);
69
+ overflow: hidden;
70
+ max-width: ${({maxWidth}) => maxWidth || 'none'};
71
+ `
72
+ export function SimpleListStory(): JSX.Element {
73
+ return (
74
+ <>
75
+ <h1>Simple List</h1>
76
+ <ErsatzOverlay>
77
+ <ActionList>
78
+ <ActionList.Item>Copy link</ActionList.Item>
79
+ <ActionList.Item>Quote reply</ActionList.Item>
80
+ <ActionList.Item>Edit comment</ActionList.Item>
81
+ <ActionList.Divider />
82
+ <ActionList.Item variant="danger">Delete file</ActionList.Item>
83
+ </ActionList>
84
+ </ErsatzOverlay>
85
+ </>
86
+ )
87
+ }
88
+ SimpleListStory.storyName = 'Simple List'
89
+
90
+ export function WithIcon(): JSX.Element {
91
+ return (
92
+ <>
93
+ <h1>With Icon</h1>
94
+ <ErsatzOverlay>
95
+ <ActionList>
96
+ <ActionList.Item>
97
+ <ActionList.LeadingVisual>
98
+ <LinkIcon />
99
+ </ActionList.LeadingVisual>
100
+ github.com/primer
101
+ </ActionList.Item>
102
+ <ActionList.Item>
103
+ <ActionList.LeadingVisual>
104
+ <LawIcon />
105
+ </ActionList.LeadingVisual>
106
+ MIT License
107
+ </ActionList.Item>
108
+ <ActionList.Item>
109
+ <ActionList.LeadingVisual>
110
+ <StarIcon />
111
+ </ActionList.LeadingVisual>
112
+ 256 stars
113
+ </ActionList.Item>
114
+ <ActionList.Item>
115
+ <ActionList.LeadingVisual>
116
+ <GitForkIcon />
117
+ </ActionList.LeadingVisual>
118
+ 3 forks
119
+ </ActionList.Item>
120
+ <ActionList.Item variant="danger">
121
+ <ActionList.LeadingVisual>
122
+ <AlertIcon />
123
+ </ActionList.LeadingVisual>
124
+ 4 vulnerabilities
125
+ </ActionList.Item>
126
+ </ActionList>
127
+ </ErsatzOverlay>
128
+ </>
129
+ )
130
+ }
131
+ WithIcon.storyName = 'With Icon'
132
+
133
+ const users = [
134
+ {login: 'pksjce', name: 'Pavithra Kodmad'},
135
+ {login: 'jfuchs', name: 'Jonathan Fuchs'},
136
+ {login: 'colebemis', name: 'Cole Bemis'},
137
+ {login: 'mperrotti', name: 'Mike Perrotti'},
138
+ {login: 'dgreif', name: 'Dusty Greif'},
139
+ {login: 'smockle', name: 'Clay Miller'},
140
+ {login: 'siddharthkp', name: 'Siddharth Kshetrapal'}
141
+ ]
142
+
143
+ export function WithAvatar(): JSX.Element {
144
+ return (
145
+ <>
146
+ <h1>With Avatar</h1>
147
+ <ErsatzOverlay>
148
+ <ActionList>
149
+ {users.map(user => (
150
+ <ActionList.Item key={user.login}>
151
+ <ActionList.LeadingVisual>
152
+ <Avatar src={`https://github.com/${user.login}.png`} />
153
+ </ActionList.LeadingVisual>
154
+ {user.login}
155
+ </ActionList.Item>
156
+ ))}
157
+ </ActionList>
158
+ </ErsatzOverlay>
159
+ </>
160
+ )
161
+ }
162
+ WithAvatar.storyName = 'With Avatar'
163
+
164
+ const labels = [
165
+ {name: 'blocked', color: '#86181d', description: 'Someone or something is preventing this from moving forward'},
166
+ {name: 'dependencies', color: '#0366d6', description: 'Pull requests that update a dependency file'},
167
+ {name: 'duplicate', color: '#cfd3d7', description: 'This issue or pull request already exists'},
168
+ {name: 'good first issue', color: '#7057ff', description: 'Good for newcomers'}
169
+ ]
170
+
171
+ const LabelColor: React.FC<{color: string}> = ({color}) => (
172
+ <Box sx={{backgroundColor: color, width: '14px', height: '14px', borderRadius: 3}} />
173
+ )
174
+
175
+ export function WithDescription(): JSX.Element {
176
+ return (
177
+ <>
178
+ <h1>With Description & Dividers</h1>
179
+ <ErsatzOverlay>
180
+ <ActionList showDividers>
181
+ {users.map(user => (
182
+ <ActionList.Item key={user.login}>
183
+ <ActionList.LeadingVisual>
184
+ <Avatar src={`https://github.com/${user.login}.png`} />
185
+ </ActionList.LeadingVisual>
186
+ {user.login}
187
+ <ActionList.Description>{user.name}</ActionList.Description>
188
+ </ActionList.Item>
189
+ ))}
190
+ <ActionList.Divider />
191
+ {labels.map((label, index) => (
192
+ <ActionList.Item key={index}>
193
+ <ActionList.LeadingVisual>
194
+ <LabelColor color={label.color} />
195
+ </ActionList.LeadingVisual>
196
+ {label.name}
197
+ <ActionList.Description variant="block">{label.description}</ActionList.Description>
198
+ </ActionList.Item>
199
+ ))}
200
+ </ActionList>
201
+ </ErsatzOverlay>
202
+ </>
203
+ )
204
+ }
205
+ WithDescription.storyName = 'With Description & Dividers'
206
+
207
+ const projects = [
208
+ {name: 'Primer Backlog', scope: 'GitHub'},
209
+ {name: 'Accessibility', scope: 'GitHub'},
210
+ {name: 'Octicons', scope: 'github/primer'},
211
+ {name: 'Primer React', scope: 'github/primer'}
212
+ ]
213
+
214
+ export function SingleSelectListStory(): JSX.Element {
215
+ const [selectedIndex, setSelectedIndex] = React.useState(1)
216
+
217
+ return (
218
+ <>
219
+ <h1>Single Select List</h1>
220
+ <ErsatzOverlay>
221
+ <ActionList selectionVariant="single" showDividers role="listbox" aria-label="Select a project">
222
+ {projects.map((project, index) => (
223
+ <ActionList.Item
224
+ key={index}
225
+ role="option"
226
+ selected={index === selectedIndex}
227
+ onSelect={() => setSelectedIndex(index)}
228
+ >
229
+ <ActionList.LeadingVisual>
230
+ <TableIcon />
231
+ </ActionList.LeadingVisual>
232
+ {project.name}
233
+ <ActionList.Description variant="block">{project.scope}</ActionList.Description>
234
+ </ActionList.Item>
235
+ ))}
236
+ </ActionList>
237
+ </ErsatzOverlay>
238
+ </>
239
+ )
240
+ }
241
+ SingleSelectListStory.storyName = 'Single Select'
242
+
243
+ export function MultiSelectListStory(): JSX.Element {
244
+ const [assignees, setAssignees] = React.useState(users.slice(0, 2))
245
+
246
+ const toggleAssignee = assignee => {
247
+ const assigneeIndex = assignees.findIndex(a => a.login === assignee.login)
248
+
249
+ if (assigneeIndex === -1) setAssignees([...assignees, assignee])
250
+ else setAssignees(assignees.filter((_, index) => index !== assigneeIndex))
251
+ }
252
+
253
+ return (
254
+ <>
255
+ <h1>Multi Select List</h1>
256
+ <ErsatzOverlay>
257
+ <ActionList selectionVariant="multiple" showDividers role="listbox" aria-label="Select assignees">
258
+ {users.map(user => (
259
+ <ActionList.Item
260
+ role="option"
261
+ key={user.login}
262
+ selected={Boolean(assignees.find(assignee => assignee.login === user.login))}
263
+ onSelect={() => toggleAssignee(user)}
264
+ >
265
+ <ActionList.LeadingVisual>
266
+ <Avatar src={`https://github.com/${user.login}.png`} />
267
+ </ActionList.LeadingVisual>
268
+ {user.login}
269
+ <ActionList.Description>{user.name}</ActionList.Description>
270
+ </ActionList.Item>
271
+ ))}
272
+ </ActionList>
273
+ </ErsatzOverlay>
274
+ </>
275
+ )
276
+ }
277
+ MultiSelectListStory.storyName = 'Multi Select'
278
+
279
+ export function DisabledStory(): JSX.Element {
280
+ const [selectedIndex, setSelectedIndex] = React.useState(0)
281
+
282
+ return (
283
+ <>
284
+ <h1>Disabled Items</h1>
285
+ <ErsatzOverlay>
286
+ <ActionList selectionVariant="single" showDividers role="listbox" aria-label="Select a project">
287
+ {projects.map((project, index) => (
288
+ <ActionList.Item
289
+ key={index}
290
+ role="option"
291
+ selected={index === selectedIndex}
292
+ onSelect={() => setSelectedIndex(index)}
293
+ disabled={index === 1}
294
+ >
295
+ <ActionList.LeadingVisual>
296
+ <TableIcon />
297
+ </ActionList.LeadingVisual>
298
+ {project.name}
299
+ <ActionList.Description variant="block">{project.scope}</ActionList.Description>
300
+ </ActionList.Item>
301
+ ))}
302
+ </ActionList>
303
+ </ErsatzOverlay>
304
+ </>
305
+ )
306
+ }
307
+ DisabledStory.storyName = 'Disabled Items'
308
+
309
+ export function GroupsStory(): JSX.Element {
310
+ const [assignees, setAssignees] = React.useState(users.slice(0, 1))
311
+
312
+ const toggleAssignee = assignee => {
313
+ const assigneeIndex = assignees.findIndex(a => a.login === assignee.login)
314
+
315
+ if (assigneeIndex === -1) setAssignees([...assignees, assignee])
316
+ else setAssignees(assignees.filter((_, index) => index !== assigneeIndex))
317
+ }
318
+
319
+ return (
320
+ <>
321
+ <h1>Groups</h1>
322
+ <ErsatzOverlay>
323
+ <ActionList selectionVariant="multiple" showDividers role="listbox" aria-label="Select reviewers">
324
+ <ActionList.Group title="Suggestions" variant="filled">
325
+ {users.slice(0, 2).map(user => (
326
+ <ActionList.Item
327
+ key={user.login}
328
+ role="option"
329
+ selected={Boolean(assignees.find(assignee => assignee.login === user.login))}
330
+ onSelect={() => toggleAssignee(user)}
331
+ >
332
+ <ActionList.LeadingVisual>
333
+ <Avatar src={`https://github.com/${user.login}.png`} />
334
+ </ActionList.LeadingVisual>
335
+ {user.login}
336
+ <ActionList.Description>{user.name}</ActionList.Description>
337
+ <ActionList.Description variant="block">Recently edited these files</ActionList.Description>
338
+ </ActionList.Item>
339
+ ))}
340
+ </ActionList.Group>
341
+ <ActionList.Group title="Everyone" variant="filled">
342
+ {users.slice(2).map(user => (
343
+ <ActionList.Item
344
+ role="option"
345
+ key={user.login}
346
+ selected={Boolean(assignees.find(assignee => assignee.login === user.login))}
347
+ onSelect={() => toggleAssignee(user)}
348
+ >
349
+ <ActionList.LeadingVisual>
350
+ <Avatar src={`https://github.com/${user.login}.png`} />
351
+ </ActionList.LeadingVisual>
352
+ {user.login}
353
+ <ActionList.Description>{user.name}</ActionList.Description>
354
+ </ActionList.Item>
355
+ ))}
356
+ </ActionList.Group>
357
+ </ActionList>
358
+ </ErsatzOverlay>
359
+ </>
360
+ )
361
+ }
362
+ GroupsStory.storyName = 'Groups'
363
+
364
+ export function ActionsStory(): JSX.Element {
365
+ return (
366
+ <>
367
+ <h1>Actions</h1>
368
+ <ErsatzOverlay>
369
+ <ActionList showDividers>
370
+ <ActionList.Item>
371
+ <ActionList.LeadingVisual>
372
+ <ServerIcon />
373
+ </ActionList.LeadingVisual>
374
+ Open current Codespace
375
+ <ActionList.Description variant="block">
376
+ Your existing Codespace will be opened to its previous state, and you&apos;ll be asked to manually switch
377
+ to new-branch.
378
+ </ActionList.Description>
379
+ </ActionList.Item>
380
+ <ActionList.Item>
381
+ <ActionList.LeadingVisual>
382
+ <PlusCircleIcon />
383
+ </ActionList.LeadingVisual>
384
+ Create new Codespace
385
+ <ActionList.Description variant="block">
386
+ Create a brand new Codespace with a fresh image and checkout this branch.
387
+ </ActionList.Description>
388
+ </ActionList.Item>
389
+ </ActionList>
390
+ </ErsatzOverlay>
391
+ </>
392
+ )
393
+ }
394
+ ActionsStory.storyName = 'Actions'
395
+
396
+ export function ComplexListInsetVariantStory(): JSX.Element {
397
+ return (
398
+ <>
399
+ <h1>Complex List</h1>
400
+ <h2>Inset Variant</h2>
401
+ <ErsatzOverlay>
402
+ <ActionList showDividers>
403
+ <ActionList.Item>
404
+ <ActionList.LeadingVisual>
405
+ <TypographyIcon />
406
+ </ActionList.LeadingVisual>
407
+ Rename
408
+ </ActionList.Item>
409
+ <ActionList.Item>
410
+ <ActionList.LeadingVisual>
411
+ <VersionsIcon />
412
+ </ActionList.LeadingVisual>
413
+ Duplicate
414
+ <ActionList.Description>Create a copy</ActionList.Description>
415
+ </ActionList.Item>
416
+
417
+ <ActionList.Group title="Live query" variant="filled">
418
+ <ActionList.Item style={{color: 'rebeccapurple'}}>
419
+ <ActionList.LeadingVisual>
420
+ <SearchIcon />
421
+ </ActionList.LeadingVisual>
422
+ repo:github/memex,github/github
423
+ </ActionList.Item>
424
+ </ActionList.Group>
425
+ <ActionList.Divider />
426
+ <ActionList.Group title="Layout" variant="subtle">
427
+ <ActionList.Item>
428
+ <ActionList.LeadingVisual>
429
+ <NoteIcon />
430
+ </ActionList.LeadingVisual>
431
+ Table
432
+ <ActionList.Description variant="block">
433
+ Information-dense table optimized for operations across teams
434
+ </ActionList.Description>
435
+ </ActionList.Item>
436
+ <ActionList.Item role="listitem">
437
+ <ActionList.LeadingVisual>
438
+ <ProjectIcon />
439
+ </ActionList.LeadingVisual>
440
+ Board
441
+ <ActionList.Description variant="block">
442
+ Kanban-style board focused on visual states
443
+ </ActionList.Description>
444
+ </ActionList.Item>
445
+ </ActionList.Group>
446
+ <ActionList.Divider />
447
+ <ActionList.Group>
448
+ <ActionList.Item style={{fontWeight: 'bold'}}>
449
+ <ActionList.LeadingVisual>
450
+ <FilterIcon />
451
+ </ActionList.LeadingVisual>
452
+ Save sort and filters to current view
453
+ </ActionList.Item>
454
+ <ActionList.Item style={{fontWeight: 'bold'}}>
455
+ <ActionList.LeadingVisual>
456
+ <FilterIcon />
457
+ </ActionList.LeadingVisual>
458
+ Save sort and filters to new view
459
+ </ActionList.Item>
460
+ </ActionList.Group>
461
+ <ActionList.Divider />
462
+ <ActionList.Group sx={{backgroundColor: 'accent.emphasis'}}>
463
+ <ActionList.Item sx={{color: 'white'}}>
464
+ <ActionList.LeadingVisual sx={{color: 'white'}}>
465
+ <GearIcon />
466
+ </ActionList.LeadingVisual>
467
+ View settings
468
+ </ActionList.Item>
469
+ </ActionList.Group>
470
+ </ActionList>
471
+ </ErsatzOverlay>
472
+ </>
473
+ )
474
+ }
475
+ ComplexListInsetVariantStory.storyName = 'Complex List — Inset Variant'
476
+
477
+ export function ComplexListFullVariantStory(): JSX.Element {
478
+ return (
479
+ <>
480
+ <h1>Complex List</h1>
481
+ <h2>Full Variant</h2>
482
+ <ErsatzOverlay>
483
+ <ActionList variant="full">
484
+ <ActionList.Item>
485
+ <ActionList.LeadingVisual>
486
+ <TypographyIcon />
487
+ </ActionList.LeadingVisual>
488
+ Rename
489
+ </ActionList.Item>
490
+ <ActionList.Item>
491
+ <ActionList.LeadingVisual>
492
+ <VersionsIcon />
493
+ </ActionList.LeadingVisual>
494
+ Duplicate
495
+ <ActionList.Description>Create a copy</ActionList.Description>
496
+ </ActionList.Item>
497
+
498
+ <ActionList.Group title="Live query" variant="filled">
499
+ <ActionList.Item style={{color: 'rebeccapurple'}}>
500
+ <ActionList.LeadingVisual>
501
+ <SearchIcon />
502
+ </ActionList.LeadingVisual>
503
+ repo:github/memex,github/github
504
+ </ActionList.Item>
505
+ </ActionList.Group>
506
+ <ActionList.Divider />
507
+ <ActionList.Group title="Layout" variant="subtle">
508
+ <ActionList.Item>
509
+ <ActionList.LeadingVisual>
510
+ <NoteIcon />
511
+ </ActionList.LeadingVisual>
512
+ Table
513
+ <ActionList.Description variant="block">
514
+ Information-dense table optimized for operations across teams
515
+ </ActionList.Description>
516
+ </ActionList.Item>
517
+ <ActionList.Item>
518
+ <ActionList.LeadingVisual>
519
+ <ProjectIcon />
520
+ </ActionList.LeadingVisual>
521
+ Board
522
+ <ActionList.Description variant="block">
523
+ Kanban-style board focused on visual states
524
+ </ActionList.Description>
525
+ </ActionList.Item>
526
+ </ActionList.Group>
527
+ <ActionList.Divider />
528
+ <ActionList.Group>
529
+ <ActionList.Item style={{fontWeight: 'bold'}}>
530
+ <ActionList.LeadingVisual>
531
+ <FilterIcon />
532
+ </ActionList.LeadingVisual>
533
+ Save sort and filters to current view
534
+ </ActionList.Item>
535
+ <ActionList.Item style={{fontWeight: 'bold'}}>
536
+ <ActionList.LeadingVisual>
537
+ <FilterIcon />
538
+ </ActionList.LeadingVisual>
539
+ Save sort and filters to new view
540
+ </ActionList.Item>
541
+ </ActionList.Group>
542
+ <ActionList.Divider />
543
+ <ActionList.Group sx={{backgroundColor: 'accent.emphasis'}}>
544
+ <ActionList.Item sx={{color: 'white'}}>
545
+ <ActionList.LeadingVisual sx={{color: 'white'}}>
546
+ <GearIcon />
547
+ </ActionList.LeadingVisual>
548
+ View settings
549
+ </ActionList.Item>
550
+ </ActionList.Group>
551
+ </ActionList>
552
+ </ErsatzOverlay>
553
+ </>
554
+ )
555
+ }
556
+ ComplexListFullVariantStory.storyName = 'Complex List — Full Variant'
557
+
558
+ type ReactRouterLikeLinkProps = {to: string; children: React.ReactNode}
559
+ const ReactRouterLikeLink = forwardRef<HTMLAnchorElement, ReactRouterLikeLinkProps>(
560
+ ({to, ...props}: {to: string; children: React.ReactNode}, ref) => {
561
+ // eslint-disable-next-line jsx-a11y/anchor-has-content
562
+ return <a ref={ref} href={to} {...props} />
563
+ }
564
+ )
565
+
566
+ const NextJSLikeLink = forwardRef(
567
+ ({href, children}: {href: string; children: React.ReactNode}, ref): React.ReactElement => {
568
+ const child = React.Children.only(children)
569
+ const childProps = {
570
+ ref,
571
+ href
572
+ }
573
+ return <>{React.isValidElement(child) ? React.cloneElement(child, childProps) : null}</>
574
+ }
575
+ )
576
+
577
+ export function LinkItemStory(): JSX.Element {
578
+ return (
579
+ <>
580
+ <h1>List with LinkItem</h1>
581
+ <ErsatzOverlay>
582
+ <ActionList showDividers>
583
+ <ActionList.Item>
584
+ <ActionList.LeadingVisual>
585
+ <XIcon />
586
+ </ActionList.LeadingVisual>
587
+ not a link, just an Item for comparison
588
+ </ActionList.Item>
589
+ <ActionList.LinkItem href="https://github.com/primer">
590
+ <ActionList.LeadingVisual>
591
+ <LinkIcon />
592
+ </ActionList.LeadingVisual>
593
+ ActionList.LinkItem
594
+ </ActionList.LinkItem>
595
+ <ActionList.LinkItem href="https://github.com/primer" target="_blank" rel="noopener noreferrer">
596
+ <ActionList.LeadingVisual>
597
+ <LinkIcon />
598
+ </ActionList.LeadingVisual>
599
+ ActionList.LinkItem with anchor attributes
600
+ </ActionList.LinkItem>
601
+ <ActionList.LinkItem
602
+ as={ReactRouterLikeLink}
603
+ to="?path=/story/composite-components-actionlist2--simple-list-story"
604
+ >
605
+ <ActionList.LeadingVisual>
606
+ <LinkIcon />
607
+ </ActionList.LeadingVisual>
608
+ as ReactRouterLink
609
+ </ActionList.LinkItem>
610
+ <NextJSLikeLink href="?path=/story/composite-components-actionlist2--simple-list-story">
611
+ <ActionList.LinkItem>
612
+ <ActionList.LeadingVisual>
613
+ <LinkIcon />
614
+ </ActionList.LeadingVisual>
615
+ NextJS style Link
616
+ </ActionList.LinkItem>
617
+ </NextJSLikeLink>
618
+ <ActionList.LinkItem href="?path=/story/composite-components-actionlist2--simple-list-story">
619
+ <ActionList.LeadingVisual>
620
+ <LinkIcon />
621
+ </ActionList.LeadingVisual>
622
+ ActionList.LinkItem with everything
623
+ <ActionList.Description variant="inline">inline description</ActionList.Description>
624
+ <ActionList.Description variant="block">Block description</ActionList.Description>
625
+ <ActionList.TrailingVisual>⌘ + L</ActionList.TrailingVisual>
626
+ </ActionList.LinkItem>
627
+ </ActionList>
628
+ </ErsatzOverlay>
629
+ </>
630
+ )
631
+ }
632
+ LinkItemStory.storyName = 'List with LinkItem'
633
+
634
+ export function DOMPropsStory(): JSX.Element {
635
+ return (
636
+ <>
637
+ <h1>Simple List</h1>
638
+ <ErsatzOverlay>
639
+ <ActionList>
640
+ <ActionList.Item id="something" onClick={event => alert(`Id is '${event.currentTarget.getAttribute('id')}'`)}>
641
+ Has an id
642
+ </ActionList.Item>
643
+ </ActionList>
644
+ </ErsatzOverlay>
645
+ </>
646
+ )
647
+ }
648
+ DOMPropsStory.storyName = 'List an item input including DOM props'
649
+
650
+ export function CustomItemChildren(): JSX.Element {
651
+ return (
652
+ <>
653
+ <h1>Custom Item Children</h1>
654
+ <ErsatzOverlay>
655
+ <ActionList>
656
+ <ActionList.Item>
657
+ <ActionList.LeadingVisual>
658
+ <ArrowRightIcon />
659
+ </ActionList.LeadingVisual>
660
+ <Label outline borderColor="success.emphasis">
661
+ Choose this one
662
+ </Label>
663
+ <ActionList.TrailingVisual>
664
+ <ArrowLeftIcon />
665
+ </ActionList.TrailingVisual>
666
+ </ActionList.Item>
667
+ </ActionList>
668
+ </ErsatzOverlay>
669
+ </>
670
+ )
671
+ }
672
+ CustomItemChildren.storyName = 'Custom Item Children'
673
+
674
+ export function SizeStressTestingStory(): JSX.Element {
675
+ return (
676
+ <>
677
+ <h1>Size Stress Testing</h1>
678
+ <ErsatzOverlay maxWidth="300px">
679
+ <ActionList showDividers>
680
+ <ActionList.Item>
681
+ <ActionList.LeadingVisual>
682
+ <ArrowRightIcon />
683
+ </ActionList.LeadingVisual>
684
+ Block Description. Long text should wrap
685
+ <ActionList.Description variant="block">
686
+ This description is long, but it is block so it wraps
687
+ </ActionList.Description>
688
+ <ActionList.TrailingVisual>
689
+ <ArrowLeftIcon />
690
+ </ActionList.TrailingVisual>
691
+ </ActionList.Item>
692
+ <ActionList.Item>
693
+ <ActionList.LeadingVisual>
694
+ <ArrowRightIcon />
695
+ </ActionList.LeadingVisual>
696
+ Inline Description
697
+ <ActionList.Description>This description gets truncated because it is inline</ActionList.Description>
698
+ <ActionList.TrailingVisual>
699
+ <ArrowLeftIcon />
700
+ </ActionList.TrailingVisual>
701
+ </ActionList.Item>
702
+ <ActionList.Item>
703
+ <ActionList.LeadingVisual>
704
+ <ArrowRightIcon />
705
+ </ActionList.LeadingVisual>
706
+ Really long text without a description should wrap so it wraps
707
+ <ActionList.TrailingVisual>
708
+ <ArrowLeftIcon />
709
+ </ActionList.TrailingVisual>
710
+ </ActionList.Item>
711
+ </ActionList>
712
+ </ErsatzOverlay>
713
+ </>
714
+ )
715
+ }
716
+ SizeStressTestingStory.storyName = 'Size Stress Testing'
717
+
718
+ export function AllCombinations(): JSX.Element {
719
+ return (
720
+ <>
721
+ <h1>All Possible Combinations</h1>
722
+ <code>
723
+ dynamic features: L = Leading Visual, I = Inline Description, B = Block Description, T = Trailing Visual
724
+ </code>
725
+ <br />
726
+ <code>16 possible combinations</code>
727
+ <br />
728
+ <br />
729
+ <ErsatzOverlay maxWidth="300px">
730
+ <ActionList showDividers>
731
+ <ActionList.Item>
732
+ <ActionList.LeadingVisual>
733
+ <StarIcon />
734
+ </ActionList.LeadingVisual>
735
+ The everything bagel
736
+ <ActionList.Description variant="inline">inline description</ActionList.Description>
737
+ <ActionList.Description variant="block">Block description</ActionList.Description>
738
+ <ActionList.TrailingVisual>
739
+ <StarIcon />
740
+ </ActionList.TrailingVisual>
741
+ </ActionList.Item>
742
+ <ActionList.Item>none of them, only text</ActionList.Item>
743
+ <ActionList.Item>
744
+ <ActionList.LeadingVisual>
745
+ <StarIcon />
746
+ </ActionList.LeadingVisual>
747
+ only L
748
+ </ActionList.Item>
749
+ <ActionList.Item>
750
+ only I<ActionList.Description variant="inline">inline description</ActionList.Description>
751
+ </ActionList.Item>
752
+ <ActionList.Item>
753
+ only B<ActionList.Description variant="block">Block description</ActionList.Description>
754
+ </ActionList.Item>
755
+ <ActionList.Item>
756
+ only T
757
+ <ActionList.TrailingVisual>
758
+ <StarIcon />
759
+ </ActionList.TrailingVisual>
760
+ </ActionList.Item>
761
+ <ActionList.Item>
762
+ <ActionList.LeadingVisual>
763
+ <StarIcon />
764
+ </ActionList.LeadingVisual>
765
+ L + I<ActionList.Description variant="inline">inline description</ActionList.Description>
766
+ </ActionList.Item>
767
+ <ActionList.Item>
768
+ <ActionList.LeadingVisual>
769
+ <StarIcon />
770
+ </ActionList.LeadingVisual>
771
+ L + B<ActionList.Description variant="block">Block description</ActionList.Description>
772
+ </ActionList.Item>
773
+ <ActionList.Item>
774
+ <ActionList.LeadingVisual>
775
+ <StarIcon />
776
+ </ActionList.LeadingVisual>
777
+ L + T
778
+ <ActionList.TrailingVisual>
779
+ <StarIcon />
780
+ </ActionList.TrailingVisual>
781
+ </ActionList.Item>
782
+ <ActionList.Item>
783
+ I + B<ActionList.Description variant="inline">inline description</ActionList.Description>
784
+ <ActionList.Description variant="block">Block description</ActionList.Description>
785
+ </ActionList.Item>
786
+ <ActionList.Item>
787
+ I + T<ActionList.Description variant="inline">inline description</ActionList.Description>
788
+ <ActionList.TrailingVisual>
789
+ <StarIcon />
790
+ </ActionList.TrailingVisual>
791
+ </ActionList.Item>
792
+ <ActionList.Item>
793
+ B + T<ActionList.Description variant="block">Block description</ActionList.Description>
794
+ <ActionList.TrailingVisual>
795
+ <StarIcon />
796
+ </ActionList.TrailingVisual>
797
+ </ActionList.Item>
798
+ <ActionList.Item>
799
+ <ActionList.LeadingVisual>
800
+ <StarIcon />
801
+ </ActionList.LeadingVisual>
802
+ L + I + B<ActionList.Description variant="inline">inline description</ActionList.Description>
803
+ <ActionList.Description variant="block">Block description</ActionList.Description>
804
+ </ActionList.Item>
805
+ <ActionList.Item>
806
+ <ActionList.LeadingVisual>
807
+ <StarIcon />
808
+ </ActionList.LeadingVisual>
809
+ L + I + T<ActionList.Description variant="inline">inline description</ActionList.Description>
810
+ <ActionList.TrailingVisual>
811
+ <StarIcon />
812
+ </ActionList.TrailingVisual>
813
+ </ActionList.Item>
814
+ <ActionList.Item>
815
+ <ActionList.LeadingVisual>
816
+ <StarIcon />
817
+ </ActionList.LeadingVisual>
818
+ L + B + T<ActionList.Description variant="block">Block description</ActionList.Description>
819
+ <ActionList.TrailingVisual>
820
+ <StarIcon />
821
+ </ActionList.TrailingVisual>
822
+ </ActionList.Item>
823
+ <ActionList.Item>
824
+ I + B + T<ActionList.Description variant="inline">inline description</ActionList.Description>
825
+ <ActionList.Description variant="block">Block description</ActionList.Description>
826
+ <ActionList.TrailingVisual>
827
+ <StarIcon />
828
+ </ActionList.TrailingVisual>
829
+ </ActionList.Item>
830
+ </ActionList>
831
+ </ErsatzOverlay>
832
+ </>
833
+ )
834
+ }
835
+ AllCombinations.storyName = 'All Combinations'
836
+
837
+ const teams = [
838
+ {id: '5025661', type: 'team', slug: 'github/primer-reviewers', name: 'Primer Reviewers', members: 20},
839
+ {id: '1929972', type: 'team', slug: 'github/design-infrastructure', name: 'Design Infrastructure', members: 20}
840
+ ]
841
+
842
+ export function ConditionalChildren(): JSX.Element {
843
+ type reviewerType = {name: string; id?: string; type?: string; login?: string; slug?: string; members?: number}
844
+ const potentialReviewers: reviewerType[] = [...teams, ...users]
845
+ return (
846
+ <>
847
+ <h1>Conditional Children</h1>
848
+ <ErsatzOverlay>
849
+ <ActionList showDividers>
850
+ {potentialReviewers.map((reviewer, index) => (
851
+ <ActionList.Item key={index}>
852
+ <ActionList.LeadingVisual>
853
+ {reviewer.type === 'team' ? (
854
+ <Avatar src={`https://avatars.githubusercontent.com/t/${reviewer.id}`} />
855
+ ) : (
856
+ <Avatar src={`https://avatars.githubusercontent.com/${reviewer.login}`} />
857
+ )}
858
+ </ActionList.LeadingVisual>
859
+ {reviewer.login || reviewer.slug}
860
+ {reviewer.type === 'team' ? (
861
+ <ActionList.Description variant="block">{reviewer.name}</ActionList.Description>
862
+ ) : (
863
+ <ActionList.Description>{reviewer.name}</ActionList.Description>
864
+ )}
865
+ {reviewer.type === 'team' && (
866
+ <ActionList.TrailingVisual>
867
+ <PeopleIcon />
868
+ {reviewer.members}
869
+ </ActionList.TrailingVisual>
870
+ )}
871
+ </ActionList.Item>
872
+ ))}
873
+ </ActionList>
874
+ </ErsatzOverlay>
875
+ </>
876
+ )
877
+ }
878
+ ConditionalChildren.storyName = 'Conditional Children'
879
+
880
+ export function NestedChildren(): JSX.Element {
881
+ return (
882
+ <>
883
+ <h1>Nested Children</h1>
884
+ <ErsatzOverlay>
885
+ <ActionList showDividers>
886
+ <li>
887
+ <ul id="i like extra lists" style={{paddingInlineStart: 0}}>
888
+ {users.map(user => (
889
+ <ActionList.Item key={user.login}>
890
+ <ActionList.LeadingVisual>
891
+ <Avatar src={`https://avatars.githubusercontent.com/${user.login}`} />
892
+ </ActionList.LeadingVisual>
893
+ {user.login}
894
+ <ReviewerDescription user={user} />
895
+ </ActionList.Item>
896
+ ))}
897
+ </ul>
898
+ </li>
899
+ </ActionList>
900
+ </ErsatzOverlay>
901
+ </>
902
+ )
903
+ }
904
+ NestedChildren.storyName = 'Nested Children'
905
+
906
+ const ReviewerDescription = ({user}) => {
907
+ const usersRecentlyEditedFile = users.slice(0, 2)
908
+
909
+ if (usersRecentlyEditedFile.find(u => u.login === user.login)) {
910
+ return (
911
+ <span>
912
+ <ActionList.Description>{user.name}</ActionList.Description>
913
+ <ActionList.Description variant="block">Recently edited this file</ActionList.Description>
914
+ </span>
915
+ )
916
+ } else {
917
+ return <ActionList.Description>{user.name}</ActionList.Description>
918
+ }
919
+ }
920
+
921
+ export function ChildWithInternalState(): JSX.Element {
922
+ return (
923
+ <>
924
+ <h1>Child with internal state - broken</h1>
925
+ <ErsatzOverlay>
926
+ <ActionList showDividers>
927
+ {users.map(user => (
928
+ <ActionList.Item key={user.login}>
929
+ <ActionList.LeadingVisual>
930
+ <Avatar src={`https://avatars.githubusercontent.com/${user.login}`} />
931
+ </ActionList.LeadingVisual>
932
+ {user.login}
933
+ <StatefulChild>{user.name}</StatefulChild>
934
+ </ActionList.Item>
935
+ ))}
936
+ </ActionList>
937
+ </ErsatzOverlay>
938
+ </>
939
+ )
940
+ }
941
+ ChildWithInternalState.storyName = 'Child with internal state'
942
+
943
+ const StatefulChild = props => {
944
+ const [nameVisible, setNameVisibility] = React.useState(false)
945
+ const toggle = () => {
946
+ setNameVisibility(!nameVisible)
947
+ }
948
+
949
+ /** once description is registered, it cannot be unregistered, only updated. */
950
+
951
+ return (
952
+ <>
953
+ <ButtonInvisible onClick={toggle} sx={{fontSize: 0, paddingY: 0}}>
954
+ {nameVisible ? 'Hide name' : 'Show name'}
955
+ </ButtonInvisible>
956
+ {nameVisible && <ActionList.Description>{props.children}</ActionList.Description>}
957
+ </>
958
+ )
959
+ }
960
+
961
+ export function ChildWithSideEffects(): JSX.Element {
962
+ const user = users[0]
963
+ const [selected, setSelected] = React.useState(true)
964
+
965
+ return (
966
+ <>
967
+ <h1>Child with side effects</h1>
968
+ <ErsatzOverlay>
969
+ <ActionList selectionVariant="multiple" role="listbox" aria-label="Select assignees">
970
+ <ActionList.Item selected={selected} onSelect={() => setSelected(!selected)} role="option">
971
+ <ActionList.LeadingVisual>
972
+ <Avatar src={`https://avatars.githubusercontent.com/${user.login}`} />
973
+ </ActionList.LeadingVisual>
974
+ {user.login}
975
+ <SideEffectDescription />
976
+ </ActionList.Item>
977
+ </ActionList>
978
+ </ErsatzOverlay>
979
+ </>
980
+ )
981
+ }
982
+ ChildWithSideEffects.storyName = 'Child with side effects'
983
+
984
+ const SideEffectDescription = () => {
985
+ const [seconds, setSeconds] = React.useState(0)
986
+
987
+ React.useEffect(() => {
988
+ const fn = () => setSeconds(s => s + 1)
989
+ const interval = window.setInterval(fn, 1000)
990
+ return () => window.clearInterval(interval)
991
+ }, [])
992
+
993
+ return <ActionList.Description>{seconds} seconds passed</ActionList.Description>
994
+ }
995
+
996
+ export function WithSx(): JSX.Element {
997
+ return (
998
+ <>
999
+ <h1>With sx prop</h1>
1000
+ <ErsatzOverlay>
1001
+ <ActionList sx={{paddingTop: 4}}>
1002
+ <ActionList.Item sx={{backgroundColor: 'accent.subtle'}}>
1003
+ <ActionList.LeadingVisual sx={{color: 'accent.emphasis'}}>
1004
+ <LinkIcon />
1005
+ </ActionList.LeadingVisual>
1006
+ github.com/primer
1007
+ <ActionList.Description sx={{paddingLeft: 4, color: 'accent.emphasis'}}>
1008
+ all items support sx prop
1009
+ </ActionList.Description>
1010
+ </ActionList.Item>
1011
+ <ActionList.Item>
1012
+ <ActionList.LeadingVisual>
1013
+ <LawIcon />
1014
+ </ActionList.LeadingVisual>
1015
+ MIT License
1016
+ </ActionList.Item>
1017
+ <ActionList.Item
1018
+ variant="danger"
1019
+ sx={{
1020
+ borderLeft: '2px solid',
1021
+ borderColor: 'danger.emphasis',
1022
+ borderTopLeftRadius: 0,
1023
+ borderBottomLeftRadius: 0
1024
+ }}
1025
+ >
1026
+ <ActionList.LeadingVisual>
1027
+ <AlertIcon />
1028
+ </ActionList.LeadingVisual>
1029
+ 4 vulnerabilities
1030
+ </ActionList.Item>
1031
+ </ActionList>
1032
+ </ErsatzOverlay>
1033
+ </>
1034
+ )
1035
+ }
1036
+ WithSx.storyName = 'With sx'
1037
+
1038
+ export function MemexGroupBy(): JSX.Element {
1039
+ const [selectedIndex, setSelectedIndex] = React.useState<number | null>(1)
1040
+
1041
+ const options = [
1042
+ {text: 'Status', icon: <IssueOpenedIcon />},
1043
+ {text: 'Stage', icon: <TableIcon />},
1044
+ {text: 'Assignee', icon: <PeopleIcon />},
1045
+ {text: 'Team', icon: <TypographyIcon />},
1046
+ {text: 'Estimate', icon: <NumberIcon />},
1047
+ {text: 'Due Date', icon: <CalendarIcon />}
1048
+ ]
1049
+
1050
+ return (
1051
+ <>
1052
+ <h1>Memex GroupBy List</h1>
1053
+ <ErsatzOverlay>
1054
+ <ActionList>
1055
+ <ActionList.Group title="Group by" selectionVariant="single">
1056
+ {options.map((option, index) => (
1057
+ <ActionList.Item key={index} selected={index === selectedIndex} onSelect={() => setSelectedIndex(index)}>
1058
+ <ActionList.LeadingVisual>{option.icon}</ActionList.LeadingVisual>
1059
+ {option.text}
1060
+ </ActionList.Item>
1061
+ ))}
1062
+ </ActionList.Group>
1063
+ {typeof selectedIndex === 'number' && (
1064
+ <>
1065
+ <ActionList.Divider />
1066
+ <ActionList.Item onSelect={() => setSelectedIndex(null)}>
1067
+ <ActionList.LeadingVisual>
1068
+ <XIcon />
1069
+ </ActionList.LeadingVisual>
1070
+ Clear Group by
1071
+ </ActionList.Item>
1072
+ </>
1073
+ )}
1074
+ </ActionList>
1075
+ </ErsatzOverlay>
1076
+ </>
1077
+ )
1078
+ }
1079
+ MemexGroupBy.storyName = 'Memex GroupBy List'
1080
+
1081
+ type Option = {text: string; icon: React.ReactNode; selected: boolean}
1082
+ export function MemexSortable(): JSX.Element {
1083
+ const [options, setOptions] = React.useState<Option[]>([
1084
+ {text: 'Status', icon: <IssueOpenedIcon />, selected: true},
1085
+ {text: 'Stage', icon: <TableIcon />, selected: true},
1086
+ {text: 'Assignee', icon: <PeopleIcon />, selected: true},
1087
+ {text: 'Team', icon: <TypographyIcon />, selected: true},
1088
+ {text: 'Estimate', icon: <NumberIcon />, selected: false},
1089
+ {text: 'Due Date', icon: <CalendarIcon />, selected: false}
1090
+ ])
1091
+
1092
+ const toggle = (text: string) => {
1093
+ setOptions(
1094
+ options.map(option => {
1095
+ if (option.text === text) option.selected = !option.selected
1096
+ return option
1097
+ })
1098
+ )
1099
+ }
1100
+
1101
+ const reorder = ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => {
1102
+ setOptions(currentOptions => {
1103
+ const newOptions = [...currentOptions]
1104
+ // remove option to move
1105
+ const currentPosition = newOptions.findIndex(o => o.text === optionToMove.text)
1106
+ newOptions.splice(currentPosition, 1)
1107
+ // add it after the provided element
1108
+ const newPosition = newOptions.findIndex(o => o.text === moveAfterOption.text) + 1
1109
+ newOptions.splice(newPosition, 0, optionToMove)
1110
+ return newOptions
1111
+ })
1112
+ }
1113
+
1114
+ const visibleOptions = options.filter(option => option.selected)
1115
+ const hiddenOptions = options.filter(option => !option.selected)
1116
+
1117
+ return (
1118
+ <>
1119
+ <h1>Memex Sortable List</h1>
1120
+ <ErsatzOverlay>
1121
+ <DndProvider backend={HTML5Backend}>
1122
+ <ActionList selectionVariant="multiple">
1123
+ <ActionList.Group title="Visible fields (can be reordered)">
1124
+ {visibleOptions.map(option => (
1125
+ <SortableItem
1126
+ key={option.text}
1127
+ option={option}
1128
+ onSelect={() => toggle(option.text)}
1129
+ reorder={reorder}
1130
+ />
1131
+ ))}
1132
+ </ActionList.Group>
1133
+ <ActionList.Group
1134
+ title="Hidden fields"
1135
+ selectionVariant={
1136
+ /** selectionVariant override on Group: disable selection if there are no options */
1137
+ hiddenOptions.length ? 'multiple' : false
1138
+ }
1139
+ >
1140
+ {hiddenOptions.map((option, index) => (
1141
+ <ActionList.Item key={index} selected={option.selected} onSelect={() => toggle(option.text)}>
1142
+ <ActionList.LeadingVisual>{option.icon}</ActionList.LeadingVisual>
1143
+ {option.text}
1144
+ </ActionList.Item>
1145
+ ))}
1146
+ {hiddenOptions.length === 0 && <ActionList.Item disabled>No hidden fields</ActionList.Item>}
1147
+ </ActionList.Group>
1148
+ </ActionList>
1149
+ </DndProvider>
1150
+ </ErsatzOverlay>
1151
+ </>
1152
+ )
1153
+ }
1154
+ MemexSortable.storyName = 'Memex Sortable List'
1155
+
1156
+ type SortableItemProps = {
1157
+ option: Option
1158
+ onSelect: ItemProps['onSelect']
1159
+ reorder: ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => void
1160
+ }
1161
+ const SortableItem: React.FC<SortableItemProps> = ({option, onSelect, reorder}) => {
1162
+ const [{isDragging}, dragRef] = useDrag(() => ({
1163
+ type: 'ITEM',
1164
+ item: option,
1165
+ collect: monitor => {
1166
+ return {isDragging: monitor.isDragging()}
1167
+ }
1168
+ }))
1169
+
1170
+ const [{isOver}, dropRef] = useDrop(() => ({
1171
+ accept: 'ITEM',
1172
+ collect: monitor => {
1173
+ return {isOver: monitor.isOver()}
1174
+ },
1175
+ drop: (optionDropped: Option) => {
1176
+ reorder({optionToMove: optionDropped, moveAfterOption: option})
1177
+ }
1178
+ }))
1179
+
1180
+ return (
1181
+ <ActionList.Item
1182
+ ref={element => dragRef(element) && dropRef(element)} // merge refs
1183
+ selected={option.selected}
1184
+ onSelect={onSelect}
1185
+ sx={{
1186
+ opacity: isDragging ? 0.5 : 1,
1187
+ boxShadow: isOver ? theme => `0px 2px 0 0px ${theme.colors.accent.emphasis}` : undefined,
1188
+ borderRadius: isOver ? 0 : undefined
1189
+ }}
1190
+ >
1191
+ <ActionList.LeadingVisual>{option.icon}</ActionList.LeadingVisual>
1192
+ {option.text}
1193
+ </ActionList.Item>
1194
+ )
1195
+ }
1196
+
1197
+ const repos = [
1198
+ 'primer/primer-markdown',
1199
+ 'primer/octicons',
1200
+ 'primer/css',
1201
+ 'primer/primer-layout',
1202
+ 'primer/primer-alerts',
1203
+ 'primer/primer-avatars',
1204
+ 'primer/react',
1205
+ 'primer/primitives'
1206
+ ]
1207
+
1208
+ export function AsyncListStory(): JSX.Element {
1209
+ const [results, setResults] = React.useState(repos.slice(0, 6))
1210
+ const [loading, setLoading] = React.useState(false)
1211
+ const filter = async event => {
1212
+ setLoading(true)
1213
+ const filteredResults = await filterSlowly(event.target.value)
1214
+ setResults(filteredResults)
1215
+ setLoading(false)
1216
+ }
1217
+
1218
+ return (
1219
+ <>
1220
+ <h1>Async List Items</h1>
1221
+ <ErsatzOverlay>
1222
+ <TextInput
1223
+ onChange={filter}
1224
+ placeholder="Search repositories, showing 6 by default"
1225
+ sx={{m: 2, mb: 0, width: 'calc(100% - 16px)'}}
1226
+ />
1227
+ <ActionList sx={{height: 208, overflow: 'auto'}}>
1228
+ {loading ? (
1229
+ <Box sx={{display: 'flex', justifyContent: 'center', pt: 2}}>
1230
+ <Spinner />
1231
+ </Box>
1232
+ ) : (
1233
+ results.map(name => (
1234
+ <ActionList.Item key={name}>
1235
+ <ActionList.LeadingVisual>
1236
+ <RepoIcon />
1237
+ </ActionList.LeadingVisual>
1238
+ {name}
1239
+ </ActionList.Item>
1240
+ ))
1241
+ )}
1242
+ </ActionList>
1243
+ </ErsatzOverlay>
1244
+ </>
1245
+ )
1246
+ }
1247
+ AsyncListStory.storyName = 'Async List Options'
1248
+
1249
+ const filterSlowly = async query => {
1250
+ // sleep for 1s before returning results
1251
+ await new Promise(resolve => setTimeout(resolve, 1000))
1252
+ return await repos.filter(name => name.includes(query))
1253
+ }
1254
+
1255
+ export function InsideOverlay(): JSX.Element {
1256
+ const [open, setOpen] = React.useState(false)
1257
+ const toggle = () => setOpen(!open)
1258
+ return (
1259
+ <>
1260
+ <h1>Inside Overlay</h1>
1261
+ <AnchoredOverlay
1262
+ open={open}
1263
+ onOpen={toggle}
1264
+ onClose={toggle}
1265
+ renderAnchor={props => <button {...props}>toggle overlay</button>}
1266
+ >
1267
+ <ActionList>
1268
+ <ActionList.Item>
1269
+ Use your arrow keys
1270
+ <ActionList.TrailingVisual>↓</ActionList.TrailingVisual>
1271
+ </ActionList.Item>
1272
+ <ActionList.Item>
1273
+ keep going
1274
+ <ActionList.TrailingVisual>↓</ActionList.TrailingVisual>
1275
+ </ActionList.Item>
1276
+ <ActionList.Item>
1277
+ more more
1278
+ <ActionList.TrailingVisual>↓</ActionList.TrailingVisual>
1279
+ </ActionList.Item>
1280
+ <ActionList.Divider />
1281
+ <ActionList.Item variant="danger">
1282
+ now go up!
1283
+ <ActionList.TrailingVisual>↑</ActionList.TrailingVisual>
1284
+ </ActionList.Item>
1285
+ </ActionList>
1286
+ </AnchoredOverlay>
1287
+ </>
1288
+ )
1289
+ }
1290
+ InsideOverlay.storyName = 'Inside Overlay'