-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.js
73 lines (69 loc) · 1.89 KB
/
async.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
import React from 'react'
import PropTypes from 'prop-types'
import {storiesOf} from '@storybook/react'
import 'whatwg-fetch'
import {Clear, Select, Item, Label, Search, List, TagList, Tag} from '../src'
import {
rendering,
renderingList,
renderingItem,
renderingSearch,
renderingTag,
onChange,
} from './utils/dummy'
const createQuery = query =>
query === ''
? 'https://swapi.co/api/people'
: `https://swapi.co/api/people/?search=${query}`
const fakeApiCb = (query, cb) => fakeApi(query).then(r => cb(null, r))
const fakeApi = query =>
fetch(createQuery(query))
.then(response => response.json())
.then(r => r.results)
const Container = props => <Select.Async {...props} />
storiesOf('Async', module)
.add('With callback', () =>
<Container
name="context"
onChange={onChange}
loadOptions={fakeApiCb}
transform={data => ({label: data.name, value: data.name})}>
<Label />
<List renderItem={Item} />
</Container>
)
.add('With promise', () =>
<Container
name="context"
onChange={onChange}
loadOptions={fakeApi}
style={{display: 'flex'}}
transform={data => ({label: data.name, value: data.name})}>
<div style={{width: 250}}>
<div style={{flex: 1}}>
<Search />
</div>
<div style={{flex: 1}}>
<Label />
<List renderItem={<Item render={renderingItem} />} />
</div>
</div>
</Container>
)
.add('With custom debounce', () =>
<Container
debounce={1000}
loadOptions={fakeApi}
multi
name="context"
onChange={onChange}
transform={data => ({label: data.name, value: data.name})}>
<div style={{width: 250}}>
<div style={{flex: 1}}>
<Search />
</div>
<TagList renderTag={Tag} />
<List renderItem={<Item render={renderingItem} />} />
</div>
</Container>
)