1 import React, {PropTypes} from 'react';
2 import Select from './Select';
4 const formatOption = (option) => {
11 const Combobox = React.createClass({
13 formatter: PropTypes.object,
14 prefixCls: PropTypes.string,
15 value: PropTypes.object,
16 onChange: PropTypes.func,
17 showHour: PropTypes.bool,
18 showSecond: PropTypes.bool,
19 hourOptions: PropTypes.array,
20 minuteOptions: PropTypes.array,
21 secondOptions: PropTypes.array,
24 onItemChange(type, itemValue) {
25 const { value, onChange } = this.props;
26 if (type === 'hour') {
27 value.setHourOfDay(itemValue);
28 } else if (type === 'minute') {
29 value.setMinutes(itemValue);
31 value.setSeconds(itemValue);
37 const { prefixCls, hourOptions, showHour } = this.props;
44 options={hourOptions.map(option => formatOption(option))}
45 selectedIndex={hourOptions.indexOf(hour)}
47 onSelect={this.onItemChange}
52 getMinuteSelect(minute) {
53 const { prefixCls, minuteOptions } = this.props;
57 options={minuteOptions.map(option => formatOption(option))}
58 selectedIndex={minuteOptions.indexOf(minute)}
60 onSelect={this.onItemChange}
65 getSectionSelect(second) {
66 const { prefixCls, secondOptions, showSecond } = this.props;
73 options={secondOptions.map(option => formatOption(option))}
74 selectedIndex={secondOptions.indexOf(second)}
76 onSelect={this.onItemChange}
82 const { prefixCls, value } = this.props;
85 <div className={`${prefixCls}-combobox`}>
86 {this.getHourSelect(value.getHourOfDay())}
87 {this.getMinuteSelect(value.getMinutes())}
88 {this.getSectionSelect(value.getSeconds())}
94 export default Combobox;