-
Notifications
You must be signed in to change notification settings - Fork 63
/
SelectPage.tsx
326 lines (300 loc) · 9.57 KB
/
SelectPage.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
import { Form, Grid, H0, H1, Link, Select, Text } from '@bigcommerce/big-design';
import { DeleteIcon } from '@bigcommerce/big-design-icons';
import React from 'react';
import { Code, CodePreview } from '../../components';
import { SelectActionPropTable, SelectOptionPropTable, SelectPropTable } from '../../PropTables';
export default () => (
<>
<H0>Selects</H0>
<Text>
Select are typeable inputs with selectable dropdown items.{' '}
<Link href="https://design.bigcommerce.com/components/selects" target="_blank">
Selects Design Guidelines
</Link>
.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [value, setValue] = React.useState(undefined);
const handleChange = val => setValue(val);
return (
<Form>
<Form.Group>
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
filterable={true}
label="Countries"
maxHeight={300}
onItemChange={handleChange}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
{ value: 'fr', content: 'France' },
{ value: 'gr', content: 'Germany' },
{ value: 'ar', content: 'Argentina' },
{ value: 'ru', content: 'Russia', disabled: true },
{ value: 'ch', content: 'Chile' },
{ value: 'bo', content: 'Bolivia' },
{ value: 'jp', content: 'Japan' },
{ value: 'cn', content: 'China' },
{ value: 'sk', content: 'South Korea' },
{ value: 'au', content: 'Australia' },
{ value: 'ug', content: 'Uganda' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
<H1>API</H1>
<SelectPropTable />
<SelectOptionPropTable />
<SelectActionPropTable />
<H1>Multiselect</H1>
<Text>
Select has the ability to render a list of items as multiselectable. Select will return an <Code>array</Code> of
the select options.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [value, setValue] = React.useState([]);
const handleChange = val => setValue(val);
return (
<Form>
<Form.Group>
<Select
label="States"
maxHeight={300}
multi={true}
onItemChange={handleChange}
options={[
{ value: 'tx', content: 'Texas' },
{ value: 'ca', content: 'California' },
{ value: 'or', content: 'Oregon' },
{ value: 'ar', content: 'Arkansas' },
{ value: 'nv', content: 'Nevada', disabled: true },
]}
placeholder={'Choose states'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
<H1>Position</H1>
<Text>
Select can be anchored in different directions with the <Code primary>position</Code> property. It will
automatically find a position if there's not enough space in the chosen direction.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
<Grid gridColumns="repeat(4, 1fr)">
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Choose from above"
placement="top"
required
/>
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Choose from below"
placement="bottom-start"
required
/>
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Choose from the right"
placement="right-start"
required
/>
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Choose from the left"
placement="left-end"
required
/>
</Grid>
{/* jsx-to-string:end */}
</CodePreview>
<H1>Max Height</H1>
<Text>
Once the content is longer than the max-height, the Dropdown will be scrollable. It is possible to modify the
dimension by passing a <Code primary>maxHeight</Code> property.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
<Grid gridColumns="repeat(3, 1fr)">
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Default"
required
/>
<Select
label="Select"
maxHeight={150}
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Smaller"
required
/>
<Select
label="Select"
maxHeight={350}
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Larger"
required
/>
</Grid>
{/* jsx-to-string:end */}
</CodePreview>
<H1>Disabled</H1>
<Text>
It is possible to disable the entire select component, similar to how you would disable a native HTML select
element, by using the <Code primary>disabled</Code> property.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
<Form>
<Form.Group>
<Select
disabled
label="Select"
maxHeight={350}
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Larger"
required
/>
</Form.Group>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
<H1>Action</H1>
<Text>
Accepts an <Code>action</Code> object to display at the end of the list.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
<Form>
<Form.Group>
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
label="Countries"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
</Form.Group>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
<H1>Error</H1>
<Text>
An <Code>error</Code> prop receives a <Code>string</Code> to display.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
<Form>
<Form.Group>
<Select
label="Countries"
error="Need to choose a country before proceeding"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
</Form.Group>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
</>
);