-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-search-fuse.story.js
57 lines (51 loc) · 1.38 KB
/
react-search-fuse.story.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
import React from 'react'
import { storiesOf } from '@storybook/react'
import { create } from 'reworm'
import ReactSearchFuse from './react-search-fuse'
const documents = [
{ id: 'a', character: 'Wolverine', name: 'Logan', team: 'X-Men' },
{ id: 'b', character: 'Hulk', name: 'Bruce Banner', team: 'Avengers' },
{
id: 'c',
character: 'Black Widow',
name: 'Natasha Romanoff',
team: 'Avengers'
},
{ id: 'd', character: 'Rogue', name: 'Anna Marie', team: 'X-Men' }
]
const { get, set } = create({ filter: '' })
const renderResults = results =>
results.map(result => (
<p key={result.id}>
<strong>{result.name}</strong> - {result.character} - {result.team}
</p>
))
const options = { keys: ['name', 'character', 'team'] }
storiesOf('ReactSearchFuse', module)
.add('interactive', () =>
get(s => (
<div>
<input
onChange={e => set({ filter: e.target.value })}
value={s.filter}
/>
<ReactSearchFuse
options={options}
filter={s.filter}
documents={documents}>
{renderResults}
</ReactSearchFuse>
</div>
))
)
.add('initial filter', () => (
<div>
Initial Filter: Wolverine
<ReactSearchFuse
options={options}
filter="Wolverine"
documents={documents}>
{renderResults}
</ReactSearchFuse>
</div>
))