This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathindex.js
308 lines (305 loc) · 9.16 KB
/
index.js
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
import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import Avatar from '@material-ui/core/Avatar'
import Chip from '@material-ui/core/Chip'
// import AutoComplete from '@material-ui/core/AutoComplete'
import { green } from '@material-ui/core/colors'
import ChipInput from '../src/ChipInput'
import CustomizedChipInput from './examples/CustomizedChipInput'
import CustomInputFormatting from './examples/CustomInputFormatting'
import ControlledChipInput from './examples/ControlledChipInput'
import AsynchronousDefaultValue from './examples/AsynchronousDefaultValue'
// import ClipboardExample from './examples/ClipboardExample'
import {
ReactAutosuggestExample,
ReactAutosuggestRemoteExample
} from './examples/react-autosuggest'
storiesOf('ChipInput', module)
.addDecorator(story => (
<div style={{ fontFamily: 'Roboto, sans-serif' }}>{story()}</div>
))
.add('with some chips', () => (
<ChipInput
defaultValue={['foo', 'bar']}
fullWidth
onChange={action('onChange')}
/>
))
.add('with many chips', () => (
<ChipInput
defaultValue={[...Array(25).keys()].map(c => `Chip ${c}`)}
onChange={action('onChange')}
fullWidth
/>
))
.add('with custom styles', () => <CustomizedChipInput />)
.add('with placeholder', () => (
<ChipInput placeholder='Placeholder' fullWidth />
))
.add('with floating label', () => (
<ChipInput label='Floating label' fullWidth />
))
.add('with label and placeholder', () => (
<ChipInput label='Floating label' placeholder='Placeholder' fullWidth />
))
.add('with non-shrinking floating label and placeholder', () => (
<ChipInput
label='Floating label'
placeholder='Placeholder'
InputLabelProps={{ shrink: true }}
/>
))
.add('disabled', () => (
<ChipInput
defaultValue={['foo', 'bar']}
label='Disabled input'
disabled
fullWidth
/>
))
.add('readOnly', () => (
<ChipInput
defaultValue={['foo', 'bar']}
label='Readonly input'
readOnly
fullWidth
/>
))
.add('with custom width', () => (
<ChipInput
defaultValue={['foo', 'bar']}
label='A chip input with a width of 321px'
style={{ width: 321 }}
/>
))
.add('with custom chips', () => (
<ChipInput
defaultValue={['foo', 'bar']}
fullWidth
chipRenderer={(
{
value,
isFocused,
isDisabled,
isReadOnly,
handleClick,
handleDelete,
className
},
key
) => (
<Chip
key={key}
className={className}
style={{
pointerEvents: isDisabled || isReadOnly ? 'none' : undefined,
backgroundColor: isFocused ? green[800] : green[300]
}}
onClick={handleClick}
onDelete={handleDelete}
label={value}
avatar={<Avatar size={32}>{value[0].toUpperCase()}</Avatar>}
/>
)}
/>
))
.add('with helperText', () => (
<ChipInput helperText='This text is here to help you.' />
))
.add('with error style', () => (
<ChipInput
value={['One', 'Two']}
helperText='At least three chips required.'
error
/>
))
.add('without underline', () => (
<ChipInput defaultValue={['foo', 'bar']} fullWidth disableUnderline />
))
.add('with different margins', () => (
<div>
<ChipInput label='normal' margin='normal' style={{ float: 'left' }} />
<ChipInput label='dense' margin='dense' style={{ float: 'left' }} />
<ChipInput label='none' margin='none' style={{ float: 'left' }} />
</div>
))
.add('with asynchronous default value', () =>
<AsynchronousDefaultValue />
)
.add('controlled input', () =>
<ControlledChipInput />
)
.add('with controlled text input', () => <CustomInputFormatting />)
/*
.add('create tags with comma, space and enter', () =>
<ChipInput
newChipKeyCodes={[13, 188, 32]}
/>
)
.add('uncontrolled verbose log', () =>
<ChipInput
defaultValue={['foo', 'bar']}
onChange={action('onChange')}
onUpdateInput={action('onUpdateInput')}
onDelete={action('onDelete')}
onAdd={action('onAdd')}
onClick={action('onClick')}
/>
)
.add('controlled verbose log', () =>
<ChipInput
value={['foo', 'bar']}
onChange={action('onChange')}
onUpdateInput={action('onUpdateInput')}
onDelete={action('onDelete')}
onAdd={action('onAdd')}
onClick={action('onClick')}
/>
)
.add('objects as chips, uncontrolled', () =>
<ChipInput
dataSource={[{ label: 'Chip 1', id: 'one' }, { label: 'Chip 2', id: 'two' }]}
dataSourceConfig={{ text: 'label', value: 'id' }}
defaultValue={[{ label: 'Chip 1', id: 'one' }]}
onChange={action('onChange')}
onUpdateInput={action('onUpdateInput')}
onDelete={action('onDelete')}
onAdd={action('onAdd')}
onClick={action('onClick')}
/>
)
.add('objects as chips, controlled', () =>
<ChipInput
dataSource={[{ label: 'Chip 1', id: 'one' }, { label: 'Chip 2', id: 'two' }]}
dataSourceConfig={{ text: 'label', value: 'id' }}
value={[{ label: 'Chip 1', id: 'one' }]}
onChange={action('onChange')}
onUpdateInput={action('onUpdateInput')}
onDelete={action('onDelete')}
onAdd={action('onAdd')}
onClick={action('onClick')}
/>
)
.add('controlled input with auto complete', () =>
<ControlledChipInput
openOnFocus
dataSource={['foo', 'bar']}
inputProps={{ fullWidth: true }}
/>
)
*/
.add('with fullWidthInput', () => (
<ChipInput
label='The input is always full-width here'
fullWidth
fullWidthInput
/>
))
/*
.add('with clipboard manipulation', () =>
<ClipboardExample
onPaste={action('onPaste')}
onChange={action('onChange')}
onUpdateInput={action('onUpdateInput')}
onDelete={action('onDelete')}
onAdd={action('onAdd')}
onClick={action('onClick')}
/>
)
*/
.add('add text input value on blur', () => <ChipInput blurBehavior='add' />)
.add('add number input value on blur, or clear input if not a number', () =>
<ChipInput
blurBehavior='add-or-clear'
onBeforeAdd={(value) => !Number.isNaN(parseFloat(value))}
/>
)
.add('clear text input value on blur ', () => (
<ChipInput blurBehavior='clear' />
))
.add('keep text input value on blur ', () => (
<ChipInput blurBehavior='none' />
))
/*
.add('in a form', () =>
<form onSubmit={e => { e.preventDefault(); action('onSubmit')() }}>
<ChipInput
onChange={action('onChange')}
floatingLabelText='This is a single chip input inside a form. Note that pressing Enter does not submit the form if a chip is being added.'
fullWidth
/>
</form>
)
*/
.add('with duplicates allowed', () => (
<ChipInput defaultValue={['foo', 'bar', 'foo', 'bar']} allowDuplicates />
))
/*
.add('with onBeforeAdd returning false', () =>
<ChipInput
defaultValue={['foo', 'bar', 'foo', 'bar']}
onBeforeAdd={() => false}
/>
)
.add('tabbing between fields', () =>
<form>
<ChipInput
floatingLabelText='"Tab" key selects the next field when there is no active chip.'
newChipKeyCodes={[9, 13]}
fullWidth
/>
<br />
<input type='text' />
</form>
)
*/
.add('with react-autosuggest', () => (
<ReactAutosuggestExample
label='Country search'
placeholder='Search a country'
fullWidth
/>
))
.add('with react-autosuggest and remote data', () => (
<ReactAutosuggestRemoteExample
label='Remote country search.'
placeholder='Search a country'
fullWidth
/>
))
.add('with react-autosuggest and add on blur', () => (
<ReactAutosuggestRemoteExample
label='Remote country search.'
placeholder='Search a country'
blurBehavior='add'
fullWidth
/>
))
.add('with "outlined" variant', () => (
<div>
<ChipInput variant='outlined' label='Add Tags' />
<h2>Different Margins</h2>
<div>
<ChipInput variant='outlined' label='normal' margin='normal' style={{ float: 'left' }} />
<ChipInput variant='outlined' label='dense' margin='dense' style={{ float: 'left' }} />
<ChipInput variant='outlined' label='none' margin='none' style={{ float: 'left' }} />
</div>
</div>
))
.add('with "outlined" variant fullWidth', () => (
<ChipInput defaultValue={['foo', 'bar']} variant='outlined' label='Add Tags' fullWidth fullWidthInput />
))
.add('with "filled" variant', () => (
<div><ChipInput variant='filled' label='Add Tags' />
<h2>Different Margins</h2>
<div>
<ChipInput variant='filled' label='normal' margin='normal' style={{ float: 'left' }} />
<ChipInput variant='filled' label='dense' margin='dense' style={{ float: 'left' }} />
<ChipInput variant='filled' label='none' margin='none' style={{ float: 'left' }} />
</div>
</div>
))
.add('with "filled" variant full width', () => (
<ChipInput defaultValue={['foo', 'bar']} variant='filled' label='Add Tags' fullWidth fullWidthInput />
))