@primer/components 31.2.0-rc.c285489d → 31.2.0-rc.c53cfd9e

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