forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdown.js
More file actions
80 lines (70 loc) · 2.08 KB
/
dropdown.js
File metadata and controls
80 lines (70 loc) · 2.08 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
72
73
74
75
76
77
78
79
80
import React from 'react';
import Dropdown from '../../components/dropdown';
import style from '../style';
const countries = [
{ value: 'EN-gb', label: 'England', img: 'http://' },
{ value: 'ES-es', label: 'Spain', img: 'http://' },
{ value: 'TH-th', label: 'Thailand', img: 'http://' },
{ value: 'EN-en', label: 'USA', img: 'http://' },
{ value: 'FR-fr', label: 'France', img: 'http://' }
];
class DropdownTest extends React.Component {
state = {
dropdown4: 'TH-th'
};
handleChange = (dropdown, value) => {
const newState = {};
newState[dropdown] = value;
this.setState(newState);
};
customDropdownItem (data) {
return (
<div className={style.dropdownTemplate}>
<img className={style.dropdownTemplateImage} src={data.img} />
<div className={style.dropdownTemplateContent}>
<strong>{data.label}</strong>
<small>{data.value}</small>
</div>
</div>
);
}
handleFocus = (dropdowns) => {
dropdowns.forEach((dropdown) => {
this.refs[dropdown].close();
});
}
render () {
return (
<section>
<h5>Dropdown</h5>
<p>lorem ipsum...</p>
<Dropdown
label="Country"
ref="dropdown1"
onFocus={this.handleFocus.bind(this, ['dropdown3', 'dropdown4'])}
onChange={this.handleChange.bind(this, 'dropdown1')}
source={countries}
template={this.customDropdownItem}
value={this.state.dropdown1}
/>
<Dropdown
label="Country"
ref="dropdown4"
onFocus={this.handleFocus.bind(this, ['dropdown1', 'dropdown4'])}
onChange={this.handleChange.bind(this, 'dropdown4')}
source={countries}
value={this.state.dropdown4}
/>
<Dropdown
disabled
ref="dropdown3"
label="Country"
onFocus={this.handleFocus.bind(this, ['dropdown1', 'dropdown4'])}
onChange={this.handleChange.bind(this, 'dropdown3')}
source={countries}
/>
</section>
);
}
}
export default DropdownTest;