forked from Cambly/syntax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichSelectList.stories.tsx
417 lines (401 loc) · 16.3 KB
/
RichSelectList.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import { type StoryObj, type Meta } from "@storybook/react";
import RichSelectList, { type RichSelectListProps } from "./RichSelectList";
import React, { useState, type ReactElement } from "react";
import Box from "../Box/Box.js";
import Typography from "../Typography/Typography";
import { type Key } from "react-aria";
export default {
title: "Components/RichSelectList",
component: RichSelectList,
parameters: {
design: {
name: "Figma",
type: "figma",
url: "https://www.figma.com/file/p7LKna9JMU0JEkcKamzs53/%F0%9F%93%90-Syntax?node-id=1007-4102&t=7xGt6S9b6zUUiflR-0",
},
},
argTypes: {
size: {
options: ["sm", "md", "lg"],
control: { type: "radio" },
},
disabled: {
control: "boolean",
},
onChange: { action: "clicked" },
},
tags: ["autodocs"],
} as Meta<typeof RichSelectList>;
const options = [
{ label: "Option 1", value: "opt1", name: "name1" },
{ label: "Option 2", value: "opt2", name: "name2" },
{ label: "Option 3", value: "opt3", name: "name3" },
];
const renderOptions = () =>
options.map(({ label, name, value }) => (
<RichSelectList.Chip key={value} value={value} label={label} name={name} />
));
export const WhatIfItLookedLikeThis = (): ReactElement => {
const [value, setValue] = useState<string[] | Set<string> | "all">();
return (
<Box display="flex" gap={2} alignItems="center" flexWrap="wrap">
<RichSelectList
label="Label"
accessibilityLabel="Label"
helperText="Helper text"
multiple
placeholderText="Placeholder"
onChange={setValue}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Section label="People">
<RichSelectList.Chip label="John" value="john" disabled />
<RichSelectList.Chip label="Jane" value="jane" />
<RichSelectList.Chip label="Joe" value="joe" disabled />
</RichSelectList.Section>
<RichSelectList.Section label="Places">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
</RichSelectList.Section>
<RichSelectList.Section label="Times">
<RichSelectList.Chip label="Morning" value="morning" />
<RichSelectList.Chip label="Afternoon" value="afternoon" />
<RichSelectList.Chip label="Evening" value="evening" disabled />
</RichSelectList.Section>
<RichSelectList.Section label="Colors">
<RichSelectList.Chip label="Red" value="red" />
<RichSelectList.Chip label="Green" value="green" />
<RichSelectList.Chip label="Blue" value="blue" />
<RichSelectList.Chip label="Yellow" value="yellow" />
<RichSelectList.Chip label="Purple" value="purple" />
<RichSelectList.Chip label="Orange" value="orange" />
<RichSelectList.Chip label="Black" value="black" />
<RichSelectList.Chip label="White" value="white" />
<RichSelectList.Chip label="Pink" value="pink" />
</RichSelectList.Section>
<RichSelectList.Section label="Planets">
<RichSelectList.Chip label="Mercury" value="mercury" />
<RichSelectList.Chip label="Venus" value="venus" />
<RichSelectList.Chip label="Earth" value="earth" />
<RichSelectList.Chip label="Mars" value="mars" />
<RichSelectList.Chip label="Jupiter" value="jupiter" />
<RichSelectList.Chip label="Saturn" value="saturn" />
<RichSelectList.Chip label="Uranus" value="uranus" />
<RichSelectList.Chip label="Neptune" value="neptune" />
</RichSelectList.Section>
<RichSelectList.Section label="Stars">
<RichSelectList.Chip label="Sun" value="sun" />
<RichSelectList.Chip label="Sirius" value="sirius" />
<RichSelectList.Chip label="Canopus" value="canopus" />
<RichSelectList.Chip label="Alpha Centauri" value="alphaCentauri" />
<RichSelectList.Chip label="Arcturus" value="arcturus" />
<RichSelectList.Chip label="Vega" value="vega" />
<RichSelectList.Chip label="Capella" value="capella" />
<RichSelectList.Chip label="Rigel" value="rigel" />
<RichSelectList.Chip label="Procyon" value="procyon" />
<RichSelectList.Chip label="Achernar" value="achernar" />
<RichSelectList.Chip label="Betelgeuse" value="betelgeuse" />
<RichSelectList.Chip label="Hadar" value="hadar" />
<RichSelectList.Chip label="Altair" value="altair" />
<RichSelectList.Chip label="Acrux" value="acrux" />
<RichSelectList.Chip label="Aldebaran" value="aldebaran" />
<RichSelectList.Chip label="Antares" value="antares" />
<RichSelectList.Chip label="Spica" value="spica" />
<RichSelectList.Chip label="Pollux" value="pollux" />
<RichSelectList.Chip label="Fomalhaut" value="fomalhaut" />
<RichSelectList.Chip label="Deneb" value="deneb" />
<RichSelectList.Chip label="Mimosa" value="mimosa" />
<RichSelectList.Chip label="Regulus" value="regulus" />
<RichSelectList.Chip label="Adhara" value="adhara" />
<RichSelectList.Chip label="Shaula" value="shaula" />
<RichSelectList.Chip label="Castor" value="castor" />
<RichSelectList.Chip label="Gacrux" value="gacrux" />
</RichSelectList.Section>
</RichSelectList>
{!value && <Typography>{`Selected: Nothing selected yet.`}</Typography>}
{value && <Typography>{`Selected: ${JSON.stringify(value)}`}</Typography>}
</Box>
);
};
export const VeryLongContent = (): ReactElement => {
return (
<Box
display="block"
maxWidth="50%"
gap={2}
alignItems="center"
flexWrap="wrap"
>
<RichSelectList
label="Label"
accessibilityLabel="Label"
helperText="Helper text"
placeholderText="Placeholder"
onChange={() => undefined}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Chip label="John" value="john" disabled />
<RichSelectList.Chip label="Jane" value="jane" />
<RichSelectList.Chip label="Joe" value="joe" />
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
<RichSelectList.Chip label="Morning" value="morning" />
<RichSelectList.Chip label="Afternoon" value="afternoon" />
<RichSelectList.Chip label="Evening" value="evening" disabled />
<RichSelectList.Chip label="Red" value="red" />
<RichSelectList.Chip label="Green" value="green" />
<RichSelectList.Chip label="Blue" value="blue" />
<RichSelectList.Chip label="Yellow" value="yellow" />
<RichSelectList.Chip label="Purple" value="purple" />
<RichSelectList.Chip label="Orange" value="orange" />
<RichSelectList.Chip label="Black" value="black" />
<RichSelectList.Chip label="White" value="white" />
<RichSelectList.Chip label="Pink" value="pink" />
<RichSelectList.Chip label="Mercury" value="mercury" />
<RichSelectList.Chip label="Venus" value="venus" />
<RichSelectList.Chip label="Earth" value="earth" />
<RichSelectList.Chip label="Mars" value="mars" />
<RichSelectList.Chip label="Jupiter" value="jupiter" />
<RichSelectList.Chip label="Saturn" value="saturn" />
<RichSelectList.Chip label="Uranus" value="uranus" />
<RichSelectList.Chip label="Neptune" value="neptune" />
<RichSelectList.Chip label="Sun" value="sun" />
<RichSelectList.Chip label="Sirius" value="sirius" />
<RichSelectList.Chip label="Canopus" value="canopus" />
<RichSelectList.Chip label="Alpha Centauri" value="alphaCentauri" />
<RichSelectList.Chip label="Arcturus" value="arcturus" />
<RichSelectList.Chip label="Vega" value="vega" />
<RichSelectList.Chip label="Capella" value="capella" />
<RichSelectList.Chip label="Rigel" value="rigel" />
<RichSelectList.Chip label="Procyon" value="procyon" />
<RichSelectList.Chip label="Achernar" value="achernar" />
<RichSelectList.Chip label="Betelgeuse" value="betelgeuse" />
<RichSelectList.Chip label="Hadar" value="hadar" />
<RichSelectList.Chip label="Altair" value="altair" />
<RichSelectList.Chip label="Acrux" value="acrux" />
<RichSelectList.Chip label="Aldebaran" value="aldebaran" />
<RichSelectList.Chip label="Antares" value="antares" />
<RichSelectList.Chip label="Spica" value="spica" />
<RichSelectList.Chip label="Pollux" value="pollux" />
<RichSelectList.Chip label="Fomalhaut" value="fomalhaut" />
<RichSelectList.Chip label="Deneb" value="deneb" />
<RichSelectList.Chip label="Mimosa" value="mimosa" />
<RichSelectList.Chip label="Regulus" value="regulus" />
<RichSelectList.Chip label="Adhara" value="adhara" />
<RichSelectList.Chip label="Shaula" value="shaula" />
<RichSelectList.Chip label="Castor" value="castor" />
<RichSelectList.Chip label="Gacrux" value="gacrux" />
</RichSelectList>
</Box>
);
};
export const Default: StoryObj<typeof RichSelectList> = {
args: {
children: renderOptions(),
helperText: "Helper text",
accessibilityLabel: "Label",
placeholderText: "Placeholder",
selectedValues: ["opt1"],
},
};
export const Error: StoryObj<typeof RichSelectList> = {
args: {
children: renderOptions(),
errorText: "Select dropdown error message",
helperText: "Helper text",
label: "Label",
placeholderText: "Placeholder",
},
};
const RichSelectListInteractive = (): ReactElement => {
const [selectionValue, setSelectionValue] = useState<string[] | "all">();
return (
<RichSelectList
label="Label"
accessibilityLabel="Label"
helperText="Helper text"
multiple
selectedValues={selectionValue}
placeholderText="Placeholder"
onChange={setSelectionValue}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Section label="People">
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Los Angeles" value="la" disabled />
<RichSelectList.Chip label="Morning" value="morning" />
<RichSelectList.Chip label="Afternoon" value="afternoon" />
</RichSelectList.Section>
</RichSelectList>
);
};
export const Interactive: StoryObj<typeof RichSelectList> = {
render: () => <RichSelectListInteractive />,
};
export const RadioButtons: StoryObj<typeof RichSelectList> = {
render: () => (
<RichSelectList
multiple={false}
label="Label"
accessibilityLabel="Label"
selectedValues={["opt1"]}
placeholderText="Placeholder"
onChange={() => undefined}
helperText="When radio buttons are used, `multiple` prop should be false"
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.RadioButton name="name1" label="Option 1" value="opt1" />
<RichSelectList.RadioButton name="name1" label="Option 2" value="opt2" />
<RichSelectList.RadioButton name="name1" label="Option 3" value="opt3" />
</RichSelectList>
),
};
export const NoAutosaveControlled: StoryObj<typeof RichSelectList> = {
render: () => {
return (
<RichSelectList
multiple
label="Label"
accessibilityLabel="Label"
selectedValues={["sf"]}
placeholderText="Placeholder"
helperText="When `autosave` is false, the user must click the button to save their changes"
autosave={false}
onChange={() => undefined}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Section label="People">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
</RichSelectList.Section>
</RichSelectList>
);
},
};
const ControlledRichSelectList = ({
selectedValues = [],
...props
}: Omit<
RichSelectListProps,
| "onChange"
| "primaryButtonText"
| "primaryButtonAccessibilityLabel"
| "secondaryButtonText"
| "secondaryButtonAccessibilityLabel"
>) => {
const [value, setValue] = useState<Set<Key> | string[] | "all" | undefined>(
selectedValues,
);
return (
<Box display="flex" direction="column" gap={2}>
<RichSelectList
{...props}
selectedValues={value}
onChange={(v) => setValue(v)}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
/>
{!value && <Typography>{`Selected: Nothing selected yet.`}</Typography>}
{value && <Typography>{`Selected: ${JSON.stringify(value)}`}</Typography>}
</Box>
);
};
export const NoAutosaveControlledMultipleSelect: StoryObj<
typeof RichSelectList
> = {
render: () => {
return (
<Box display="flex" direction="column" gap={2}>
<ControlledRichSelectList
multiple
label="Multiple select"
accessibilityLabel="Label"
helperText="When `autosave` is false, the user must click the button to save their changes"
autosave={false}
>
<RichSelectList.Section label="Cities">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
</RichSelectList.Section>
</ControlledRichSelectList>
<ControlledRichSelectList
accessibilityLabel="Label"
multiple={false}
label="Single select"
helperText="When `autosave` is false, the user must click the button to save their changes"
autosave={false}
>
<RichSelectList.Section label="Cities">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
</RichSelectList.Section>
</ControlledRichSelectList>
</Box>
);
},
};
export const Autosave: StoryObj<typeof RichSelectList> = {
render: () => (
<RichSelectList
label="Label"
accessibilityLabel="Label"
helperText="When `autosave` is true, the user's changes are automatically saveted"
autosave
onChange={() => undefined}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Section label="Cities">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" />
</RichSelectList.Section>
</RichSelectList>
),
};
export const ItemAttributeComposition: StoryObj<typeof RichSelectList> = {
render: () => (
<RichSelectList
label="Label"
accessibilityLabel="Label"
multiple
autosave
onChange={() => undefined}
primaryButtonText="Save"
primaryButtonAccessibilityLabel="Save"
secondaryButtonText="Clear"
secondaryButtonAccessibilityLabel="Clear"
>
<RichSelectList.Section label="Cities">
<RichSelectList.Chip label="San Francisco" value="sf" />
<RichSelectList.Chip label="New York" value="ny" disabled />
<RichSelectList.Chip label="Tulsa" value="tulsa" disabled />
<RichSelectList.Chip label="Chicago" value="chicago" />
</RichSelectList.Section>
</RichSelectList>
),
};