1 import React, { PropTypes } from 'react';
2 import Select from './Select';
4 const formatOption = (option, disabledOptions) => {
5 let value = `${option}`;
11 if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
21 const Combobox = React.createClass({
23 format: PropTypes.string,
24 defaultOpenValue: PropTypes.object,
25 prefixCls: PropTypes.string,
26 value: PropTypes.object,
27 onChange: PropTypes.func,
28 showHour: PropTypes.bool,
29 showMinute: PropTypes.bool,
30 showSecond: PropTypes.bool,
31 hourOptions: PropTypes.array,
32 minuteOptions: PropTypes.array,
33 secondOptions: PropTypes.array,
34 disabledHours: PropTypes.func,
35 disabledMinutes: PropTypes.func,
36 disabledSeconds: PropTypes.func,
37 onCurrentSelectPanelChange: PropTypes.func,
40 onItemChange(type, itemValue) {
41 const { onChange, defaultOpenValue } = this.props;
42 const value = (this.props.value || defaultOpenValue).clone();
43 if (type === 'hour') {
44 value.hour(itemValue);
45 } else if (type === 'minute') {
46 value.minute(itemValue);
48 value.second(itemValue);
53 onEnterSelectPanel(range) {
54 this.props.onCurrentSelectPanelChange(range);
58 const { prefixCls, hourOptions, disabledHours, showHour } = this.props;
62 const disabledOptions = disabledHours();
67 options={hourOptions.map(option => formatOption(option, disabledOptions))}
68 selectedIndex={hourOptions.indexOf(hour)}
70 onSelect={this.onItemChange}
71 onMouseEnter={this.onEnterSelectPanel.bind(this, 'hour')}
76 getMinuteSelect(minute) {
77 const { prefixCls, minuteOptions, disabledMinutes, defaultOpenValue, showMinute } = this.props;
81 const value = this.props.value || defaultOpenValue;
82 const disabledOptions = disabledMinutes(value.hour());
87 options={minuteOptions.map(option => formatOption(option, disabledOptions))}
88 selectedIndex={minuteOptions.indexOf(minute)}
90 onSelect={this.onItemChange}
91 onMouseEnter={this.onEnterSelectPanel.bind(this, 'minute')}
96 getSecondSelect(second) {
97 const { prefixCls, secondOptions, disabledSeconds, showSecond, defaultOpenValue } = this.props;
101 const value = this.props.value || defaultOpenValue;
102 const disabledOptions = disabledSeconds(value.hour(), value.minute());
106 prefixCls={prefixCls}
107 options={secondOptions.map(option => formatOption(option, disabledOptions))}
108 selectedIndex={secondOptions.indexOf(second)}
110 onSelect={this.onItemChange}
111 onMouseEnter={this.onEnterSelectPanel.bind(this, 'second')}
117 const { prefixCls, defaultOpenValue } = this.props;
118 const value = this.props.value || defaultOpenValue;
120 <div className={`${prefixCls}-combobox`}>
121 {this.getHourSelect(value.hour())}
122 {this.getMinuteSelect(value.minute())}
123 {this.getSecondSelect(value.second())}
129 export default Combobox;