@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.
- package/.storybook/main.js +7 -9
- package/.storybook/preview.js +5 -1
- package/CHANGELOG.md +23 -1
- package/dist/browser.esm.js +623 -620
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +164 -161
- package/dist/browser.umd.js.map +1 -1
- package/docs/content/ActionList2.mdx +354 -0
- package/docs/content/FilterList.md +2 -2
- package/docs/content/TextInputWithTokens.mdx +114 -0
- package/docs/content/getting-started.md +1 -1
- package/docs/content/theming.md +23 -0
- package/docs/src/@primer/gatsby-theme-doctocat/components/hero.js +1 -3
- package/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js +1 -1
- package/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js +17 -0
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList2/Description.d.ts +12 -0
- package/lib/ActionList2/Description.js +53 -0
- package/lib/ActionList2/Divider.d.ts +5 -0
- package/lib/ActionList2/Divider.js +35 -0
- package/lib/ActionList2/Group.d.ts +11 -0
- package/lib/ActionList2/Group.js +57 -0
- package/lib/ActionList2/Header.d.ts +26 -0
- package/lib/ActionList2/Header.js +55 -0
- package/lib/ActionList2/Item.d.ts +63 -0
- package/lib/ActionList2/Item.js +234 -0
- package/lib/ActionList2/LinkItem.d.ts +17 -0
- package/lib/ActionList2/LinkItem.js +57 -0
- package/lib/ActionList2/List.d.ts +26 -0
- package/lib/ActionList2/List.js +59 -0
- package/lib/ActionList2/Selection.d.ts +5 -0
- package/lib/ActionList2/Selection.js +70 -0
- package/lib/ActionList2/Visuals.d.ts +9 -0
- package/lib/ActionList2/Visuals.js +90 -0
- package/lib/ActionList2/index.d.ts +36 -0
- package/lib/ActionList2/index.js +47 -0
- package/lib/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib/Button/Button.d.ts +5 -5
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +3 -3
- package/lib/Button/ButtonDanger.d.ts +5 -5
- package/lib/Button/ButtonInvisible.d.ts +5 -5
- package/lib/Button/ButtonOutline.d.ts +5 -5
- package/lib/Button/ButtonPrimary.d.ts +5 -5
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +16 -16
- package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib/FilterList.d.ts +3 -3
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Overlay.js +3 -1
- package/lib/Portal/Portal.js +3 -2
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +8 -4
- package/lib/TextInputWithTokens.js +61 -8
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +2 -2
- package/lib/__tests__/ActionList2.test.d.ts +1 -0
- package/lib/__tests__/ActionList2.test.js +53 -0
- package/lib/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib/__tests__/KeyPaths.types.test.d.ts +11 -0
- package/lib/__tests__/KeyPaths.types.test.js +10 -0
- package/lib/__tests__/TextInputWithTokens.test.js +138 -7
- package/lib/__tests__/utils/createSlots.test.d.ts +1 -0
- package/lib/__tests__/utils/createSlots.test.js +75 -0
- package/lib/hooks/useAnchoredPosition.js +3 -2
- package/lib/hooks/useCombinedRefs.d.ts +2 -2
- package/lib/hooks/useCombinedRefs.js +4 -6
- package/lib/hooks/useResizeObserver.js +2 -2
- package/lib/stories/ActionList2.stories.js +907 -0
- package/lib/stories/TextInput.stories.js +144 -0
- package/lib/stories/TextInputWithTokens.stories.js +18 -1
- package/lib/stories/Token.stories.js +19 -2
- package/lib/sx.d.ts +10 -2
- package/lib/sx.js +8 -0
- package/lib/theme-preval.js +81 -2
- package/lib/theme.d.ts +78 -0
- package/lib/theme.js +3 -1
- package/lib/unreleased.d.ts +7 -0
- package/lib/unreleased.js +18 -0
- package/lib/utils/create-slots.d.ts +17 -0
- package/lib/utils/create-slots.js +105 -0
- package/lib/utils/testing.d.ts +14 -1
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -0
- package/lib/utils/use-force-update.d.ts +1 -0
- package/lib/utils/use-force-update.js +19 -0
- package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList2/Description.d.ts +12 -0
- package/lib-esm/ActionList2/Description.js +37 -0
- package/lib-esm/ActionList2/Divider.d.ts +5 -0
- package/lib-esm/ActionList2/Divider.js +23 -0
- package/lib-esm/ActionList2/Group.d.ts +11 -0
- package/lib-esm/ActionList2/Group.js +40 -0
- package/lib-esm/ActionList2/Header.d.ts +26 -0
- package/lib-esm/ActionList2/Header.js +44 -0
- package/lib-esm/ActionList2/Item.d.ts +63 -0
- package/lib-esm/ActionList2/Item.js +201 -0
- package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
- package/lib-esm/ActionList2/LinkItem.js +43 -0
- package/lib-esm/ActionList2/List.d.ts +26 -0
- package/lib-esm/ActionList2/List.js +37 -0
- package/lib-esm/ActionList2/Selection.d.ts +5 -0
- package/lib-esm/ActionList2/Selection.js +52 -0
- package/lib-esm/ActionList2/Visuals.d.ts +9 -0
- package/lib-esm/ActionList2/Visuals.js +68 -0
- package/lib-esm/ActionList2/index.d.ts +36 -0
- package/lib-esm/ActionList2/index.js +33 -0
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib-esm/Button/Button.d.ts +5 -5
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +3 -3
- package/lib-esm/Button/ButtonDanger.d.ts +5 -5
- package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
- package/lib-esm/Button/ButtonOutline.d.ts +5 -5
- package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +16 -16
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib-esm/FilterList.d.ts +3 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Overlay.js +2 -1
- package/lib-esm/Portal/Portal.js +2 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +8 -4
- package/lib-esm/TextInputWithTokens.js +60 -8
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +2 -2
- package/lib-esm/__tests__/ActionList2.test.d.ts +1 -0
- package/lib-esm/__tests__/ActionList2.test.js +41 -0
- package/lib-esm/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib-esm/__tests__/KeyPaths.types.test.d.ts +11 -0
- package/lib-esm/__tests__/KeyPaths.types.test.js +3 -0
- package/lib-esm/__tests__/TextInputWithTokens.test.js +132 -8
- package/lib-esm/__tests__/utils/createSlots.test.d.ts +1 -0
- package/lib-esm/__tests__/utils/createSlots.test.js +67 -0
- package/lib-esm/hooks/useAnchoredPosition.js +2 -1
- package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
- package/lib-esm/hooks/useCombinedRefs.js +3 -2
- package/lib-esm/hooks/useResizeObserver.js +2 -2
- package/lib-esm/stories/ActionList2.stories.js +796 -0
- package/lib-esm/stories/TextInput.stories.js +117 -0
- package/lib-esm/stories/TextInputWithTokens.stories.js +14 -0
- package/lib-esm/stories/Token.stories.js +14 -1
- package/lib-esm/sx.d.ts +10 -2
- package/lib-esm/sx.js +3 -1
- package/lib-esm/theme-preval.js +81 -2
- package/lib-esm/theme.d.ts +78 -0
- package/lib-esm/theme.js +2 -1
- package/lib-esm/unreleased.d.ts +7 -0
- package/lib-esm/unreleased.js +8 -0
- package/lib-esm/utils/create-slots.d.ts +17 -0
- package/lib-esm/utils/create-slots.js +84 -0
- package/lib-esm/utils/testing.d.ts +14 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -0
- package/lib-esm/utils/use-force-update.d.ts +1 -0
- package/lib-esm/utils/use-force-update.js +6 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/migrating.md +1 -1
- package/package-lock.json +38098 -45
- package/package.json +7 -3
- package/script/build +2 -0
- package/src/ActionList/Header.tsx +1 -1
- package/src/ActionList2/Description.tsx +49 -0
- package/src/ActionList2/Divider.tsx +24 -0
- package/src/ActionList2/Group.tsx +34 -0
- package/src/ActionList2/Header.tsx +58 -0
- package/src/ActionList2/Item.tsx +223 -0
- package/src/ActionList2/LinkItem.tsx +49 -0
- package/src/ActionList2/List.tsx +55 -0
- package/src/ActionList2/Selection.tsx +40 -0
- package/src/ActionList2/Visuals.tsx +76 -0
- package/src/ActionList2/index.ts +39 -0
- package/src/Overlay.tsx +2 -1
- package/src/Portal/Portal.tsx +2 -1
- package/src/TextInputWithTokens.tsx +64 -8
- package/src/_TextInputWrapper.tsx +8 -0
- package/src/__tests__/ActionList2.test.tsx +47 -0
- package/src/__tests__/AnchoredOverlay.test.tsx +2 -2
- package/src/__tests__/KeyPaths.types.test.ts +14 -0
- package/src/__tests__/TextInputWithTokens.test.tsx +123 -1
- package/src/__tests__/__snapshots__/ActionList2.test.tsx.snap +14 -0
- package/src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap +35 -135
- package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +7 -0
- package/src/__tests__/__snapshots__/TextInput.test.tsx.snap +6 -0
- package/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +463 -0
- package/src/__tests__/utils/__snapshots__/createSlots.test.tsx.snap +55 -0
- package/src/__tests__/utils/createSlots.test.tsx +74 -0
- package/src/hooks/useAnchoredPosition.ts +2 -1
- package/src/hooks/useCombinedRefs.ts +3 -3
- package/src/hooks/useResizeObserver.ts +2 -2
- package/src/stories/ActionList2.stories.tsx +1290 -0
- package/src/stories/Button.stories.tsx +1 -1
- package/src/stories/TextInput.stories.tsx +113 -0
- package/src/stories/TextInputWithTokens.stories.tsx +9 -0
- package/src/stories/Token.stories.tsx +12 -1
- package/src/sx.ts +17 -2
- package/src/theme-preval.js +1 -0
- package/src/theme.ts +86 -0
- package/src/unreleased.ts +9 -0
- package/src/utils/create-slots.tsx +96 -0
- package/src/utils/types/KeyPaths.ts +10 -0
- package/src/utils/use-force-update.ts +7 -0
- package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
- package/stats.html +1 -1
@@ -0,0 +1,354 @@
|
|
1
|
+
---
|
2
|
+
title: ActionList
|
3
|
+
status: Alpha
|
4
|
+
source: https://github.com/primer/react/tree/main/src/ActionList2
|
5
|
+
storybook: '/react/storybook?path=/story/composite-components-actionlist2'
|
6
|
+
description: An ActionList is a list of items which can be activated or selected. ActionList is the base component for many of our menu-type components, including DropdownMenu and ActionMenu.
|
7
|
+
---
|
8
|
+
|
9
|
+
import {BorderBox, Avatar} from '@primer/components'
|
10
|
+
import {ActionList} from '@primer/components/unreleased'
|
11
|
+
import {Props} from '../src/props'
|
12
|
+
|
13
|
+
import {ImageContainer} from '@primer/gatsby-theme-doctocat'
|
14
|
+
import {LinkIcon, AlertIcon, ArrowRightIcon} from '@primer/octicons-react'
|
15
|
+
|
16
|
+
<br />
|
17
|
+
|
18
|
+
<BorderBox sx={{padding: 6}}>
|
19
|
+
<ActionList sx={{width: 320}}>
|
20
|
+
<ActionList.Item>
|
21
|
+
<ActionList.LeadingVisual>
|
22
|
+
<LinkIcon />
|
23
|
+
</ActionList.LeadingVisual>
|
24
|
+
github.com/primer
|
25
|
+
<ActionList.Description variant="block">
|
26
|
+
A React implementation of GitHub's Primer Design System
|
27
|
+
</ActionList.Description>
|
28
|
+
</ActionList.Item>
|
29
|
+
<ActionList.Item>
|
30
|
+
<ActionList.LeadingVisual>
|
31
|
+
<Avatar src="https://github.com/mona.png" />
|
32
|
+
</ActionList.LeadingVisual>
|
33
|
+
mona
|
34
|
+
<ActionList.Description>Monalisa Octocat</ActionList.Description>
|
35
|
+
</ActionList.Item>
|
36
|
+
<ActionList.Item variant="danger">
|
37
|
+
<ActionList.LeadingVisual>
|
38
|
+
<AlertIcon />
|
39
|
+
</ActionList.LeadingVisual>
|
40
|
+
4 vulnerabilities
|
41
|
+
<ActionList.TrailingVisual>
|
42
|
+
<ArrowRightIcon />
|
43
|
+
</ActionList.TrailingVisual>
|
44
|
+
</ActionList.Item>
|
45
|
+
</ActionList>
|
46
|
+
</BorderBox>
|
47
|
+
|
48
|
+
<br />
|
49
|
+
|
50
|
+
```js
|
51
|
+
import {ActionList} from '@primer/components/unreleased'
|
52
|
+
```
|
53
|
+
|
54
|
+
<br />
|
55
|
+
|
56
|
+
## Examples
|
57
|
+
|
58
|
+
## Minimal example
|
59
|
+
|
60
|
+
```javascript live noinline
|
61
|
+
const {ActionList} = unreleased
|
62
|
+
|
63
|
+
render(
|
64
|
+
<ActionList>
|
65
|
+
<ActionList.Item>New file</ActionList.Item>
|
66
|
+
<ActionList.Item>Copy link</ActionList.Item>
|
67
|
+
<ActionList.Item>Edit file</ActionList.Item>
|
68
|
+
<ActionList.Divider />
|
69
|
+
<ActionList.Item variant="danger">Delete file</ActionList.Item>
|
70
|
+
</ActionList>
|
71
|
+
)
|
72
|
+
```
|
73
|
+
|
74
|
+
<br />
|
75
|
+
|
76
|
+
## With Leading Visual
|
77
|
+
|
78
|
+
Leading visuals are optional and appear at the start of an item. They can be octicons, avatars, and other custom visuals that fit a small area.
|
79
|
+
|
80
|
+
<!-- prettier-ignore -->
|
81
|
+
```javascript live noinline
|
82
|
+
const {ActionList} = unreleased
|
83
|
+
|
84
|
+
render(
|
85
|
+
<ActionList>
|
86
|
+
<ActionList.Item>
|
87
|
+
<ActionList.LeadingVisual><LinkIcon /></ActionList.LeadingVisual>
|
88
|
+
github.com/primer
|
89
|
+
</ActionList.Item>
|
90
|
+
<ActionList.Item variant="danger">
|
91
|
+
<ActionList.LeadingVisual><AlertIcon /></ActionList.LeadingVisual>
|
92
|
+
4 vulnerabilities
|
93
|
+
</ActionList.Item>
|
94
|
+
<ActionList.Item>
|
95
|
+
<ActionList.LeadingVisual><Avatar src="https://github.com/mona.png" /></ActionList.LeadingVisual>
|
96
|
+
mona
|
97
|
+
</ActionList.Item>
|
98
|
+
</ActionList>
|
99
|
+
)
|
100
|
+
```
|
101
|
+
|
102
|
+
<br />
|
103
|
+
|
104
|
+
## With Trailing Visual
|
105
|
+
|
106
|
+
Trailing visual and trailing text can display auxiliary information. They're placed at the right of the item, and can denote status, keyboard shortcuts, or be used to set expectations about what the action does.
|
107
|
+
|
108
|
+
```javascript live noinline
|
109
|
+
const {ActionList} = unreleased
|
110
|
+
|
111
|
+
render(
|
112
|
+
<ActionList>
|
113
|
+
<ActionList.Item>
|
114
|
+
New file
|
115
|
+
<ActionList.TrailingVisual>⌘ + N</ActionList.TrailingVisual>
|
116
|
+
</ActionList.Item>
|
117
|
+
<ActionList.Item>
|
118
|
+
Copy link
|
119
|
+
<ActionList.TrailingVisual>⌘ + C</ActionList.TrailingVisual>
|
120
|
+
</ActionList.Item>
|
121
|
+
<ActionList.Item>
|
122
|
+
Edit file
|
123
|
+
<ActionList.TrailingVisual>⌘ + E</ActionList.TrailingVisual>
|
124
|
+
</ActionList.Item>
|
125
|
+
<ActionList.Item variant="danger">
|
126
|
+
Delete file
|
127
|
+
<ActionList.TrailingVisual>⌫</ActionList.TrailingVisual>
|
128
|
+
</ActionList.Item>
|
129
|
+
</ActionList>
|
130
|
+
)
|
131
|
+
```
|
132
|
+
|
133
|
+
<br />
|
134
|
+
|
135
|
+
## With Description and Dividers
|
136
|
+
|
137
|
+
Item dividers allow users to parse heavier amounts of information. They're placed between items and are useful in complex lists, particularly when descriptions or multi-line text is present.
|
138
|
+
|
139
|
+
```javascript live noinline
|
140
|
+
const {ActionList} = unreleased
|
141
|
+
|
142
|
+
render(
|
143
|
+
<ActionList showDividers>
|
144
|
+
<ActionList.Item>
|
145
|
+
<ActionList.LeadingVisual>
|
146
|
+
<Avatar src="https://github.com/mona.png" />
|
147
|
+
</ActionList.LeadingVisual>
|
148
|
+
mona
|
149
|
+
<ActionList.Description>Monalisa Octocat</ActionList.Description>
|
150
|
+
</ActionList.Item>
|
151
|
+
<ActionList.Item>
|
152
|
+
<ActionList.LeadingVisual>
|
153
|
+
<Avatar src="https://github.com/hubot.png" />
|
154
|
+
</ActionList.LeadingVisual>
|
155
|
+
hubot
|
156
|
+
<ActionList.Description>Hubot</ActionList.Description>
|
157
|
+
</ActionList.Item>
|
158
|
+
<ActionList.Item>
|
159
|
+
<ActionList.LeadingVisual>
|
160
|
+
<Avatar src="https://github.com/primer-css.png" />
|
161
|
+
</ActionList.LeadingVisual>
|
162
|
+
primer-css
|
163
|
+
<ActionList.Description>GitHub Design Systems Bot</ActionList.Description>
|
164
|
+
</ActionList.Item>
|
165
|
+
</ActionList>
|
166
|
+
)
|
167
|
+
```
|
168
|
+
|
169
|
+
## With Links
|
170
|
+
|
171
|
+
When you want to add links to the List instead of actions, use `ActionList.LinkItem`
|
172
|
+
|
173
|
+
<!-- prettier-ignore -->
|
174
|
+
```javascript live noinline
|
175
|
+
const {ActionList} = unreleased
|
176
|
+
|
177
|
+
render(
|
178
|
+
<ActionList>
|
179
|
+
<ActionList.LinkItem href="https://github.com/primer">
|
180
|
+
<ActionList.LeadingVisual>
|
181
|
+
<LinkIcon />
|
182
|
+
</ActionList.LeadingVisual>
|
183
|
+
github/primer
|
184
|
+
</ActionList.LinkItem>
|
185
|
+
<ActionList.LinkItem as={ReactRouterLink} to="/">
|
186
|
+
<ActionList.LeadingVisual>
|
187
|
+
<LawIcon />
|
188
|
+
</ActionList.LeadingVisual>
|
189
|
+
MIT License
|
190
|
+
</ActionList.LinkItem>
|
191
|
+
<ActionList.LinkItem
|
192
|
+
href="https://github.com/primer/react/stargazers"
|
193
|
+
target="_blank"
|
194
|
+
rel="noopener noreferrer"
|
195
|
+
>
|
196
|
+
<ActionList.LeadingVisual>
|
197
|
+
<StarIcon />
|
198
|
+
</ActionList.LeadingVisual>
|
199
|
+
1.4k stars
|
200
|
+
</ActionList.LinkItem>
|
201
|
+
</ActionList>
|
202
|
+
)
|
203
|
+
```
|
204
|
+
|
205
|
+
<br />
|
206
|
+
|
207
|
+
## With Groups
|
208
|
+
|
209
|
+
```javascript live noinline
|
210
|
+
const {ActionList} = unreleased
|
211
|
+
|
212
|
+
const SelectFields = () => {
|
213
|
+
const [options, setOptions] = React.useState([
|
214
|
+
{text: 'Status', selected: true},
|
215
|
+
{text: 'Stage', selected: true},
|
216
|
+
{text: 'Assignee', selected: true},
|
217
|
+
{text: 'Team', selected: true},
|
218
|
+
{text: 'Estimate', selected: false},
|
219
|
+
{text: 'Due Date', selected: false}
|
220
|
+
])
|
221
|
+
|
222
|
+
const visibleOptions = options.filter(option => option.selected)
|
223
|
+
const hiddenOptions = options.filter(option => !option.selected)
|
224
|
+
|
225
|
+
const toggle = text => {
|
226
|
+
setOptions(
|
227
|
+
options.map(option => {
|
228
|
+
if (option.text === text) option.selected = !option.selected
|
229
|
+
return option
|
230
|
+
})
|
231
|
+
)
|
232
|
+
}
|
233
|
+
|
234
|
+
return (
|
235
|
+
<ActionList selectionVariant="multiple">
|
236
|
+
<ActionList.Group title="Visible fields (can be reordered)">
|
237
|
+
{visibleOptions.map(option => (
|
238
|
+
<ActionList.Item key={option.text} selected={true} onSelect={() => toggle(option.text)}>
|
239
|
+
{option.text}
|
240
|
+
</ActionList.Item>
|
241
|
+
))}
|
242
|
+
</ActionList.Group>
|
243
|
+
<ActionList.Group
|
244
|
+
title="Hidden fields"
|
245
|
+
selectionVariant={
|
246
|
+
/** selectionVariant override on Group: disable selection if there are no options */
|
247
|
+
hiddenOptions.length ? 'multiple' : false
|
248
|
+
}
|
249
|
+
>
|
250
|
+
{hiddenOptions.map((option, index) => (
|
251
|
+
<ActionList.Item key={option.text} selected={false} onSelect={() => toggle(option.text)}>
|
252
|
+
{option.text}
|
253
|
+
</ActionList.Item>
|
254
|
+
))}
|
255
|
+
{hiddenOptions.length === 0 && <ActionList.Item disabled>No hidden fields</ActionList.Item>}
|
256
|
+
</ActionList.Group>
|
257
|
+
</ActionList>
|
258
|
+
)
|
259
|
+
}
|
260
|
+
|
261
|
+
render(<SelectFields />)
|
262
|
+
```
|
263
|
+
|
264
|
+
<br />
|
265
|
+
|
266
|
+
## Props / API reference
|
267
|
+
|
268
|
+
## ActionList
|
269
|
+
|
270
|
+
| Name | Type | Default | Description |
|
271
|
+
| :--------------- | :------------------------------------------------------------------------------------------------ | :-----: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
272
|
+
| children\* | `ActionList.Item[]` or ActionList.LinkItem[] or `ActionList.Group[]` | - | Required. |
|
273
|
+
| variant | `'inset'` or `'full'` | 'inset' | Optional. Usage is discretionary, `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges |
|
274
|
+
| selectionVariant | `'single'` or `'multiple'` | - | Optional. Whether multiple Items or a single Item can be selected. |
|
275
|
+
| showDivider | boolean | false | Optional. Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`. |
|
276
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
277
|
+
| role | [AriaRole](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) | - | Optional. The ARIA role describing the function of `List` component. `listbox` or `menu` are a common values. |
|
278
|
+
|
279
|
+
<br />
|
280
|
+
|
281
|
+
## ActionList.Item
|
282
|
+
|
283
|
+
| Name | Type | Default | Description |
|
284
|
+
| :--------- | :------------------------------------------------------------------------------------------------------------ | :---------: | :----------------------------------------------------------------------------------------------- |
|
285
|
+
| children\* | one of [`React.ReactNode`, `ActionList.LeadingVisual`, `ActionList.Description`, `ActionList.TrailingVisual`] | - | Required. |
|
286
|
+
| variant | `'default'` or `'danger'` | `'default'` | Optional. variant="danger" creates a destructive action `Item`. |
|
287
|
+
| onSelect | Function | - | Optional. Callback that will trigger both on click selection and keyboard selection. |
|
288
|
+
| selected | boolean | false | Optional. For `Item`s which can be selected, whether the `Item` is currently selected. |
|
289
|
+
| disabled | boolean | false | Optional. Items that are disabled can not be clicked, selected, or navigated through. |
|
290
|
+
| role | [AriaRole](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) | - | Optional. The ARIA role describing the function of `Item` component. `option` is a common value. |
|
291
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
292
|
+
|
293
|
+
<br />
|
294
|
+
|
295
|
+
## ActionList.LinkItem
|
296
|
+
|
297
|
+
| Name | Type | Default | Description |
|
298
|
+
| :-------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ | :-----: | :------------------------------------------------------------- |
|
299
|
+
| children\* | one of [`React.ReactNode`, `ActionList.LeadingVisual`, `ActionList.Description`, `ActionList.TrailingVisual`] | - | Required. |
|
300
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
301
|
+
| + AnchorHTMLAttributes like href, target, rel, etc. | | | |
|
302
|
+
|
303
|
+
<br />
|
304
|
+
|
305
|
+
## ActionList.LeadingVisual
|
306
|
+
|
307
|
+
| Name | Type | Default | Description |
|
308
|
+
| :--------- | :------------------ | :-----: | :------------------------------------------------------------- |
|
309
|
+
| children\* | `React.ReactNode` - | - | Required. Icon (or similar) positioned before `Item` text. |
|
310
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
311
|
+
|
312
|
+
## ActionList.TrailingVisual
|
313
|
+
|
314
|
+
| Name | Type | Default | Description |
|
315
|
+
| :--------- | :------------------ | :-----: | :------------------------------------------------------------- |
|
316
|
+
| children\* | `React.ReactNode` - | - | Required. Visual positioned after `Item` text. |
|
317
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
318
|
+
|
319
|
+
<br />
|
320
|
+
|
321
|
+
## ActionList.Description
|
322
|
+
|
323
|
+
| Name | Type | Default | Description |
|
324
|
+
| :--------- | :---------------------- | :--------: | :-------------------------------------------------------------------------------------------------------------------------------- |
|
325
|
+
| children\* | `React.ReactNode` - | - | Required. Visual positioned after `Item` text. |
|
326
|
+
| variant | `'inline'` or `'block'` | `'inline'` | Optional. `"inline"` secondary text is positioned beside primary text. `"block"` secondary text is positioned below primary text. |
|
327
|
+
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
|
328
|
+
|
329
|
+
<br />
|
330
|
+
|
331
|
+
## ActionList.Group
|
332
|
+
|
333
|
+
| Name | Type | Default | Description |
|
334
|
+
| :--------------- | :------------------------------------------- | :--------: | :--------------------------------------------------------------------------------------------------------------------------------------- |
|
335
|
+
| children\* | `ActionList.Item[] or ActionList.LinkItem[]` | - | Required. |
|
336
|
+
| title | string | - | Optional. Primary text which names a `Group` |
|
337
|
+
| auxiliaryText | string | - | Optional. Secondary text which provides additional information about a `Group`. |
|
338
|
+
| variant | `'filled'` or `'subtle'` | `'subtle'` | Optional. `"filled"` - Superimposed on a background, offset from nearby content, `"subtle"` - Relatively less offset from nearby content |
|
339
|
+
| selectionVariant | `'single'` or `'multiple'` or `false` | - | Optional. Set `selectionVariant` at the group level |
|
340
|
+
|
341
|
+
<br />
|
342
|
+
|
343
|
+
## Further reading
|
344
|
+
|
345
|
+
[Interface guidelines: Action List](https://primer.style/design/components/action-list)
|
346
|
+
|
347
|
+
<br />
|
348
|
+
|
349
|
+
## Related components
|
350
|
+
|
351
|
+
- [ActionMenu](/ActionMenu)
|
352
|
+
- [SelectPanel](/SelectPanel)
|
353
|
+
|
354
|
+
<br />
|
@@ -8,10 +8,10 @@ The FilterList component is a menu with filter options that filter the main cont
|
|
8
8
|
|
9
9
|
```jsx live
|
10
10
|
<FilterList>
|
11
|
-
<FilterList.Item selected count=
|
11
|
+
<FilterList.Item selected count={32} href="#foo">
|
12
12
|
First Filter
|
13
13
|
</FilterList.Item>
|
14
|
-
<FilterList.Item count=
|
14
|
+
<FilterList.Item count={2} href="#bar">
|
15
15
|
Second Filter
|
16
16
|
</FilterList.Item>
|
17
17
|
<FilterList.Item href="#baz">Third Filter</FilterList.Item>
|
@@ -48,6 +48,7 @@ render(BasicExample)
|
|
48
48
|
| preventTokenWrapping | `boolean` | `false` | Optional. Whether tokens should render inline horizontally. By default, tokens wrap to new lines. |
|
49
49
|
| size | `TokenSizeKeys` | `extralarge` | Optional. The size of the tokens |
|
50
50
|
| hideTokenRemoveButtons | `boolean` | `false` | Optional. Whether the remove buttons should be rendered in the tokens |
|
51
|
+
| visibleTokenCount | `number` | `undefined` | Optional. The number of tokens to display before truncating |
|
51
52
|
|
52
53
|
## Adding and removing tokens
|
53
54
|
|
@@ -95,3 +96,116 @@ const UsingIssueLabelTokens = () => {
|
|
95
96
|
|
96
97
|
render(<UsingIssueLabelTokens />)
|
97
98
|
```
|
99
|
+
|
100
|
+
## Dealing with long lists of tokens
|
101
|
+
|
102
|
+
By default, all tokens will be visible when the component is rendered.
|
103
|
+
|
104
|
+
If the component is being used in an area where it's height needs to be constrained, there are options to limit the height of the input.
|
105
|
+
|
106
|
+
### Hide and show tokens
|
107
|
+
|
108
|
+
```javascript live noinline
|
109
|
+
const VisibleTokenCountExample = () => {
|
110
|
+
const [tokens, setTokens] = React.useState([
|
111
|
+
{text: 'zero', id: 0},
|
112
|
+
{text: 'one', id: 1},
|
113
|
+
{text: 'two', id: 2},
|
114
|
+
{text: 'three', id: 3}
|
115
|
+
])
|
116
|
+
const onTokenRemove = tokenId => {
|
117
|
+
setTokens(tokens.filter(token => token.id !== tokenId))
|
118
|
+
}
|
119
|
+
|
120
|
+
return (
|
121
|
+
<Box maxWidth="500px">
|
122
|
+
<Box as="label" display="block" htmlFor="inputWithTokens-basic">
|
123
|
+
Tokens truncated after 2
|
124
|
+
</Box>
|
125
|
+
<TextInputWithTokens
|
126
|
+
visibleTokenCount={2}
|
127
|
+
block
|
128
|
+
tokens={tokens}
|
129
|
+
onTokenRemove={onTokenRemove}
|
130
|
+
id="inputWithTokens-basic"
|
131
|
+
/>
|
132
|
+
</Box>
|
133
|
+
)
|
134
|
+
}
|
135
|
+
|
136
|
+
render(VisibleTokenCountExample)
|
137
|
+
```
|
138
|
+
|
139
|
+
### Render tokens on a single line
|
140
|
+
|
141
|
+
```javascript live noinline
|
142
|
+
const PreventTokenWrappingExample = () => {
|
143
|
+
const [tokens, setTokens] = React.useState([
|
144
|
+
{text: 'zero', id: 0},
|
145
|
+
{text: 'one', id: 1},
|
146
|
+
{text: 'two', id: 2},
|
147
|
+
{text: 'three', id: 3},
|
148
|
+
{text: 'four', id: 4},
|
149
|
+
{text: 'five', id: 5},
|
150
|
+
{text: 'six', id: 6},
|
151
|
+
{text: 'seven', id: 7}
|
152
|
+
])
|
153
|
+
const onTokenRemove = tokenId => {
|
154
|
+
setTokens(tokens.filter(token => token.id !== tokenId))
|
155
|
+
}
|
156
|
+
|
157
|
+
return (
|
158
|
+
<Box maxWidth="500px">
|
159
|
+
<Box as="label" display="block" htmlFor="inputWithTokens-basic">
|
160
|
+
Tokens on one line
|
161
|
+
</Box>
|
162
|
+
<TextInputWithTokens
|
163
|
+
preventTokenWrapping
|
164
|
+
block
|
165
|
+
tokens={tokens}
|
166
|
+
onTokenRemove={onTokenRemove}
|
167
|
+
id="inputWithTokens-basic"
|
168
|
+
/>
|
169
|
+
</Box>
|
170
|
+
)
|
171
|
+
}
|
172
|
+
|
173
|
+
render(PreventTokenWrappingExample)
|
174
|
+
```
|
175
|
+
|
176
|
+
### Set a maximum height for the input
|
177
|
+
|
178
|
+
```javascript live noinline
|
179
|
+
const MaxHeightExample = () => {
|
180
|
+
const [tokens, setTokens] = React.useState([
|
181
|
+
{text: 'zero', id: 0},
|
182
|
+
{text: 'one', id: 1},
|
183
|
+
{text: 'two', id: 2},
|
184
|
+
{text: 'three', id: 3},
|
185
|
+
{text: 'four', id: 4},
|
186
|
+
{text: 'five', id: 5},
|
187
|
+
{text: 'six', id: 6},
|
188
|
+
{text: 'seven', id: 7}
|
189
|
+
])
|
190
|
+
const onTokenRemove = tokenId => {
|
191
|
+
setTokens(tokens.filter(token => token.id !== tokenId))
|
192
|
+
}
|
193
|
+
|
194
|
+
return (
|
195
|
+
<Box maxWidth="500px">
|
196
|
+
<Box as="label" display="block" htmlFor="inputWithTokens-basic">
|
197
|
+
Tokens restricted to a max height
|
198
|
+
</Box>
|
199
|
+
<TextInputWithTokens
|
200
|
+
maxHeight="50px"
|
201
|
+
block
|
202
|
+
tokens={tokens}
|
203
|
+
onTokenRemove={onTokenRemove}
|
204
|
+
id="inputWithTokens-basic"
|
205
|
+
/>
|
206
|
+
</Box>
|
207
|
+
)
|
208
|
+
}
|
209
|
+
|
210
|
+
render(MaxHeightExample)
|
211
|
+
```
|
@@ -105,7 +105,7 @@ If you're rendering React components both server- and client-side, we suggest fo
|
|
105
105
|
|
106
106
|
## TypeScript
|
107
107
|
|
108
|
-
Primer React includes TypeScript support and ships with its own typings. You will
|
108
|
+
Primer React includes TypeScript support and ships with its own typings. You will still need to install type definitions for the peer dependencies if you import those in your own application code.
|
109
109
|
|
110
110
|
Once installed, you can import components and their prop type interfaces from the `@primer/components` package:
|
111
111
|
|
package/docs/content/theming.md
CHANGED
@@ -3,6 +3,8 @@ title: Theming
|
|
3
3
|
description: Theming in Primer React is made possible by a theme object that defines your application's colors, spacing, fonts, and more.
|
4
4
|
---
|
5
5
|
|
6
|
+
import Code from '@primer/gatsby-theme-doctocat/src/components/code'
|
7
|
+
|
6
8
|
## ThemeProvider
|
7
9
|
|
8
10
|
To give components access to the theme object, you must add `ThemeProvider` to the root of your application:
|
@@ -50,6 +52,27 @@ Some components may break if your custom theme does not include all the same key
|
|
50
52
|
|
51
53
|
You can reference theme values in your application using [system props](/system-props), the [`sx` prop](/overriding-styles), the `themeGet` function, or the `useTheme` hook.
|
52
54
|
|
55
|
+
<Note variant="warning">
|
56
|
+
|
57
|
+
Only use `theme` objects accessed via Primer's theme context to ensure your application’s styling draws from the same theme as Primer components’ internal styling. The `sx` prop, styled system props, `themeGet`, and `useTheme` all use the theme from context.
|
58
|
+
|
59
|
+
<DoDontContainer>
|
60
|
+
<Do>
|
61
|
+
<Code className="language-jsx">
|
62
|
+
{`<Box textShadow="shadow.medium">`}
|
63
|
+
</Code>
|
64
|
+
<Caption>Use the theme from the same context as Primer.</Caption>
|
65
|
+
</Do>
|
66
|
+
<Dont>
|
67
|
+
<Code className="language-jsx">
|
68
|
+
{`import {theme} from '@primer/components'\n\n<Box textShadow={theme.shadows.shadow.medium}>`}
|
69
|
+
</Code>
|
70
|
+
<Caption>Don't style components with any other instance of theme</Caption>
|
71
|
+
</Dont>
|
72
|
+
</DoDontContainer>
|
73
|
+
|
74
|
+
</Note>
|
75
|
+
|
53
76
|
### System props and the `sx` prop
|
54
77
|
|
55
78
|
Some [system props](/system-props) and [`sx` prop](/overriding-styles) keys are theme-aware. For example, the `bg` prop maps to the `colors` theme key which means you can use the `bg` prop to reference values in the `colors` object:
|
@@ -9,9 +9,7 @@ export default function Hero() {
|
|
9
9
|
<ThemeProvider colorMode="night" nightScheme="dark_dimmed">
|
10
10
|
<Box bg="canvas.default" py={6}>
|
11
11
|
<Container>
|
12
|
-
<Heading color
|
13
|
-
Primer React
|
14
|
-
</Heading>
|
12
|
+
<Heading sx={{color: 'accent.fg', fontSize: 7, lineHeight: 'condensed', pb: 3, m: 0}}>Primer React</Heading>
|
15
13
|
<Text as="p" fontFamily="mono" mt={0} mb={2} color="fg.default" fontSize={2}>
|
16
14
|
v{version}
|
17
15
|
</Text>
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import React from 'react'
|
1
2
|
import * as primerComponents from '@primer/components'
|
3
|
+
import * as unreleased from '@primer/components/unreleased'
|
2
4
|
import * as doctocatComponents from '@primer/gatsby-theme-doctocat'
|
3
5
|
import {
|
4
6
|
CheckIcon,
|
@@ -18,6 +20,10 @@ import {
|
|
18
20
|
GearIcon,
|
19
21
|
TypographyIcon,
|
20
22
|
VersionsIcon,
|
23
|
+
LinkIcon,
|
24
|
+
LawIcon,
|
25
|
+
StarIcon,
|
26
|
+
AlertIcon,
|
21
27
|
ArrowRightIcon
|
22
28
|
} from '@primer/octicons-react'
|
23
29
|
import State from '../../../components/State'
|
@@ -26,9 +32,16 @@ import {AnchoredOverlay} from '../../../../src/AnchoredOverlay'
|
|
26
32
|
import {ConfirmationDialog, useConfirm} from '../../../../src/Dialog/ConfirmationDialog'
|
27
33
|
import {SelectPanel} from '../../../../src/SelectPanel/SelectPanel'
|
28
34
|
|
35
|
+
const ReactRouterLink = ({to, ...props}) => {
|
36
|
+
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
37
|
+
return <a href={to} {...props} />
|
38
|
+
}
|
39
|
+
|
29
40
|
export default {
|
30
41
|
...doctocatComponents,
|
31
42
|
...primerComponents,
|
43
|
+
unreleased,
|
44
|
+
ReactRouterLink,
|
32
45
|
State,
|
33
46
|
CheckIcon,
|
34
47
|
SearchIcon,
|
@@ -47,6 +60,10 @@ export default {
|
|
47
60
|
GearIcon,
|
48
61
|
TypographyIcon,
|
49
62
|
VersionsIcon,
|
63
|
+
LinkIcon,
|
64
|
+
LawIcon,
|
65
|
+
StarIcon,
|
66
|
+
AlertIcon,
|
50
67
|
ArrowRightIcon,
|
51
68
|
Dialog2,
|
52
69
|
ConfirmationDialog,
|
package/lib/ActionList/Header.js
CHANGED
@@ -45,7 +45,7 @@ function Header({
|
|
45
45
|
return /*#__PURE__*/_react.default.createElement(StyledHeader, _extends({
|
46
46
|
role: "heading",
|
47
47
|
variant: variant
|
48
|
-
}, props), title, auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null,
|
48
|
+
}, props), title, auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null, auxiliaryText));
|
49
49
|
}
|
50
50
|
|
51
51
|
Header.displayName = "Header";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { SxProp } from '../sx';
|
3
|
+
export declare type DescriptionProps = {
|
4
|
+
/**
|
5
|
+
* Secondary text style variations.
|
6
|
+
*
|
7
|
+
* - `"inline"` - Secondary text is positioned beside primary text.
|
8
|
+
* - `"block"` - Secondary text is positioned below primary text.
|
9
|
+
*/
|
10
|
+
variant?: 'inline' | 'block';
|
11
|
+
} & SxProp;
|
12
|
+
export declare const Description: React.FC<DescriptionProps>;
|