1 import React, {PropTypes} from 'react';
2 import Select from './Select';
3 import GregorianCalendar from 'gregorian-calendar';
5 const formatOption = (option, disabledOptions) => {
6 let value = `${option}`;
12 if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
22 const Combobox = React.createClass({
24 formatter: PropTypes.object,
25 prefixCls: PropTypes.string,
26 value: PropTypes.object,
27 onChange: PropTypes.func,
28 showHour: PropTypes.bool,
29 gregorianCalendarLocale: PropTypes.object,
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 } = this.props;
42 let value = this.props.value;
44 value = value.clone();
46 value = this.getNow().clone();
48 if (type === 'hour') {
49 value.setHourOfDay(itemValue);
50 } else if (type === 'minute') {
51 value.setMinutes(itemValue);
53 value.setSeconds(itemValue);
58 onEnterSelectPanel(range) {
59 this.props.onCurrentSelectPanelChange(range);
63 const { prefixCls, hourOptions, disabledHours, showHour } = this.props;
67 const disabledOptions = disabledHours();
72 options={hourOptions.map(option => formatOption(option, disabledOptions))}
73 selectedIndex={hourOptions.indexOf(hour)}
75 onSelect={this.onItemChange}
76 onMouseEnter={this.onEnterSelectPanel.bind(this, 'hour')}
81 getMinuteSelect(minute) {
82 const { prefixCls, minuteOptions, disabledMinutes, value } = this.props;
83 const disabledOptions = disabledMinutes(value.getHourOfDay());
88 options={minuteOptions.map(option => formatOption(option, disabledOptions))}
89 selectedIndex={minuteOptions.indexOf(minute)}
91 onSelect={this.onItemChange}
92 onMouseEnter={this.onEnterSelectPanel.bind(this, 'minute')}
97 getSecondSelect(second) {
98 const { prefixCls, secondOptions, disabledSeconds, showSecond, value } = this.props;
102 const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes());
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')}
120 const value = new GregorianCalendar(this.props.gregorianCalendarLocale);
121 value.setTime(Date.now());
122 this.showNow = value;
127 const { prefixCls } = this.props;
128 const value = this.props.value || this.getNow();
130 <div className={`${prefixCls}-combobox`}>
131 {this.getHourSelect(value.getHourOfDay())}
132 {this.getMinuteSelect(value.getMinutes())}
133 {this.getSecondSelect(value.getSeconds())}
139 export default Combobox;