react-toolbox/spec/components/dropdown.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
2015-09-21 11:01:52 +03:00
import Dropdown from '../../components/dropdown';
2015-11-28 17:49:05 +03:00
import style from '../style';
2015-09-21 11:01:52 +03:00
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://' }
];
2015-10-22 02:31:17 +03:00
class DropdownTest extends React.Component {
state = {
dropdown4: 'TH-th'
};
2015-09-21 11:01:52 +03:00
handleChange = (dropdown, value) => {
const newState = {};
newState[dropdown] = value;
this.setState(newState);
2015-10-22 02:31:17 +03:00
};
2015-09-21 11:01:52 +03:00
customDropdownItem (data) {
return (
2015-11-28 17:49:05 +03:00
<div className={style.dropdownTemplate}>
<img className={style.dropdownTemplateImage} src={data.img} />
<div className={style.dropdownTemplateContent}>
2015-09-21 11:01:52 +03:00
<strong>{data.label}</strong>
<small>{data.value}</small>
</div>
</div>
);
}
2015-09-21 11:01:52 +03:00
render () {
return (
<section>
2015-10-08 17:35:34 +03:00
<h5>Dropdown</h5>
2015-09-21 11:01:52 +03:00
<p>lorem ipsum...</p>
<Dropdown
label="Country"
2016-03-23 14:35:24 +03:00
ref="dropdown1"
onChange={this.handleChange.bind(this, 'dropdown1')}
source={countries}
template={this.customDropdownItem}
value={this.state.dropdown1}
/>
<Dropdown
label="Country"
2016-03-23 14:35:24 +03:00
ref="dropdown4"
onChange={this.handleChange.bind(this, 'dropdown4')}
source={countries}
value={this.state.dropdown4}
/>
<Dropdown
disabled
2016-03-23 14:35:24 +03:00
ref="dropdown3"
label="Country"
onChange={this.handleChange.bind(this, 'dropdown3')}
source={countries}
/>
2016-10-11 23:12:12 +03:00
<Dropdown
label="Country"
ref="dropdown5"
onChange={this.handleChange.bind(this, 'dropdown5')}
source={countries}
required
/>
2015-09-21 11:01:52 +03:00
</section>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
export default DropdownTest;