-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.jsx
More file actions
71 lines (67 loc) · 2.82 KB
/
demo.jsx
File metadata and controls
71 lines (67 loc) · 2.82 KB
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
import React from 'react'
import TokensInput from './index'
const suggestOptions = [
{ title: 'Alice', subtitle: 'Alice Allison', value: 1 },
{ title: 'Bob', subtitle: 'Bob Robertson', value: 2 },
{ title: 'Carla', subtitle: 'Carla Carlson', value: 3 },
{ title: 'Dan', subtitle: 'Dan Dannison', value: 4 }
]
export default class TokensInputDemo extends React.Component {
constructor(props) {
super(props)
this.state = {
tokens1: [],
tokens2: [],
tokens3: []
}
}
render() {
const onAdd = listKey => t => {
console.log('add', t)
// convert to object, if an arbitrary string input
if (typeof t == 'string')
t = { title: t, value: t }
// find and add to list
var list = this.state[listKey]
if (list.filter(t2 => t.value == t2.value).length === 0)
list.push(t)
this.setState(this.state)
}
const onRemove = listKey => t => {
console.log('remove', t)
// find and remove form list
var list = this.state[listKey]
var i = list.indexOf(t)
if (i !== -1)
list.splice(i, 1)
this.setState(this.state)
}
return <div>
<h1>patchkit-tokens-input</h1>
<section className="demo-tokens-input">
<header><TokensInput label="Users:" placeholder="alice, bob, carla, dan" suggestOptions="..."></header>
<div className="content">
<TokensInput label="Users:" placeholder="alice, bob, carla, dan" suggestOptions={suggestOptions} tokens={this.state.tokens1} onAdd={onAdd('tokens1')} onRemove={onRemove('tokens1')} />
</div>
</section>
<section className="demo-tokens-input-arbitrary">
<header><TokensInput allowArbitrary label="Users:" placeholder="alice, bob, carla, dan" suggestOptions="..."></header>
<div className="content">
<TokensInput allowArbitrary label="Users:" placeholder="alice, bob, carla, dan" suggestOptions={suggestOptions} tokens={this.state.tokens2} onAdd={onAdd('tokens2')} onRemove={onRemove('tokens2')} />
</div>
</section>
<section className="demo-tokens-input">
<header><TokensInput limit=2 limitErrorMsg="Limit reached" label="Users:" placeholder="alice, bob, carla, dan" suggestOptions="..."></header>
<div className="content">
<TokensInput limit={2} limitErrorMsg="Limit reached" label="Users:" placeholder="alice, bob, carla, dan" suggestOptions={suggestOptions} tokens={this.state.tokens3} onAdd={onAdd('tokens3')} onRemove={onRemove('tokens3')} />
</div>
</section>
<section className="demo-tokens-readonly">
<header><TokensInput readOnly label="Users:" tokens="..."></header>
<div className="content">
<TokensInput readOnly label="Users:" tokens={suggestOptions} />
</div>
</section>
</div>
}
}