forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelect.stories.tsx
326 lines (315 loc) · 8.24 KB
/
Select.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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { StoryObj } from '@storybook/react';
import ControlHeader from 'src/explore/components/ControlHeader';
import { SelectOptionsType, SelectProps } from './types';
import Select from './Select';
export default {
title: 'Select',
component: Select,
};
const DEFAULT_WIDTH = 200;
const options: SelectOptionsType = [
{
label: 'Such an incredibly awesome long long label',
value: 'Such an incredibly awesome long long label',
custom: 'Secret custom prop',
},
{
label: 'Another incredibly awesome long long label',
value: 'Another incredibly awesome long long label',
},
{
label: 'JSX Label',
customLabel: <div style={{ color: 'red' }}>JSX Label</div>,
value: 'JSX Label',
},
{ label: 'A', value: 'A' },
{ label: 'B', value: 'B' },
{ label: 'C', value: 'C' },
{ label: 'D', value: 'D' },
{ label: 'E', value: 'E' },
{ label: 'F', value: 'F' },
{ label: 'G', value: 'G' },
{ label: 'H', value: 'H' },
{ label: 'I', value: 'I' },
];
const selectPositions = [
{
id: 'topLeft',
style: { top: '0', left: '0' },
},
{
id: 'topRight',
style: { top: '0', right: '0' },
},
{
id: 'bottomLeft',
style: { bottom: '0', left: '0' },
},
{
id: 'bottomRight',
style: { bottom: '0', right: '0' },
},
];
const mountHeader = (type: String) => {
let header;
if (type === 'text') {
header = 'Text header';
} else if (type === 'control') {
header = (
<ControlHeader
label="Control header"
warning="Example of warning message"
/>
);
}
return header;
};
const generateOptions = (opts: SelectOptionsType, count: number) => {
let generated = opts.slice();
let iteration = 0;
while (generated.length < count) {
iteration += 1;
generated = generated.concat(
// eslint-disable-next-line no-loop-func
generated.map(({ label, value }) => ({
label: `${label} ${iteration}`,
value: `${value} ${iteration}`,
})),
);
}
return generated.slice(0, count);
};
export const InteractiveSelect: StoryObj = {
render: ({
header,
options,
optionsCount,
...args
}: SelectProps & { header: string; optionsCount: number }) => (
<div
style={{
width: DEFAULT_WIDTH,
}}
>
<Select
{...args}
options={
Array.isArray(options)
? generateOptions(options, optionsCount)
: options
}
header={mountHeader(header)}
mode="multiple"
/>
</div>
),
args: {
autoFocus: true,
allowNewOptions: false,
allowClear: false,
autoClearSearchValue: false,
allowSelectAll: true,
disabled: false,
header: 'none',
invertSelection: false,
labelInValue: true,
maxTagCount: 4,
mode: 'single',
oneLine: false,
options,
optionsCount: options.length,
optionFilterProps: ['value', 'label', 'custom'],
placeholder: 'Select ...',
showSearch: true,
},
argTypes: {
options: {
description: `It defines the options of the Select.
The options can be static, an array of options.
The options can also be async, a promise that returns an array of options.
`,
},
ariaLabel: {
description: `It adds the aria-label tag for accessibility standards.
Must be plain English and localized.
`,
},
labelInValue: {
table: {
disable: true,
},
},
name: {
table: {
disable: true,
},
},
notFoundContent: {
table: {
disable: true,
},
},
mappedMode: {
table: {
disable: true,
},
},
mode: {
description: `It defines whether the Select should allow for
the selection of multiple options or single. Single by default.
`,
control: {
type: 'inline-radio',
options: ['single', 'multiple'],
},
},
allowNewOptions: {
description: `It enables the user to create new options.
Can be used with standard or async select types.
Can be used with any mode, single or multiple. False by default.
`,
},
invertSelection: {
description: `It shows a stop-outlined icon at the far right of a selected
option instead of the default checkmark.
Useful to better indicate to the user that by clicking on a selected
option it will be de-selected. False by default.
`,
},
optionFilterProps: {
description: `It allows to define which properties of the option object
should be looked for when searching.
By default label and value.
`,
},
oneLine: {
description: `Sets maxTagCount to 1. The overflow tag is always displayed in
the same line, line wrapping is disabled.
When the dropdown is open, sets maxTagCount to 0,
displays only the overflow tag.
Requires '"mode=multiple"'.
`,
},
maxTagCount: {
description: `Sets maxTagCount attribute. The overflow tag is displayed in
place of the remaining items.
Requires '"mode=multiple"'.
`,
},
optionsCount: {
control: {
type: 'number',
},
},
header: {
description: `It adds a header on top of the Select. Can be any ReactNode.`,
control: { type: 'inline-radio', options: ['none', 'text', 'control'] },
},
pageSize: {
description: `It defines how many results should be included in the query response.
Works in async mode only (See the options property).
`,
},
fetchOnlyOnSearch: {
description: `It fires a request against the server only after searching.
Works in async mode only (See the options property).
Undefined by default.
`,
},
},
};
export const AtEveryCorner = () => (
<>
{selectPositions.map(position => (
<div
key={position.id}
style={{
...position.style,
margin: 30,
width: DEFAULT_WIDTH,
position: 'absolute',
}}
>
<Select
ariaLabel={`gallery-${position.id}`}
options={options}
labelInValue
/>
</div>
))}
<p style={{ position: 'absolute', top: '40%', left: '33%', width: 500 }}>
The objective of this panel is to show how the Select behaves when in
touch with the viewport extremities. In particular, how the drop-down is
displayed and if the tooltips of truncated items are correctly positioned.
</p>
</>
);
AtEveryCorner.parameters = {
actions: {
disable: true,
},
controls: {
disable: true,
},
};
export const PageScroll = () => (
<div style={{ height: 2000, overflowY: 'auto' }}>
<div
style={{
width: DEFAULT_WIDTH,
position: 'absolute',
top: 30,
right: 30,
}}
>
<Select ariaLabel="page-scroll-select-1" options={options} labelInValue />
</div>
<div
style={{
width: DEFAULT_WIDTH,
position: 'absolute',
bottom: 30,
right: 30,
}}
>
<Select ariaLabel="page-scroll-select-2" options={options} />
</div>
<p
style={{
position: 'absolute',
top: '40%',
left: 30,
width: 500,
}}
>
The objective of this panel is to show how the Select behaves when there's
a scroll on the page. In particular, how the drop-down is displayed.
</p>
</div>
);
PageScroll.parameters = {
actions: {
disable: true,
},
controls: {
disable: true,
},
};