1 import React, { Component } from 'react';
2 import PropTypes from 'prop-types';
3 import Header from './Header';
4 import Combobox from './Combobox';
5 import moment from 'moment';
6 import classNames from 'classnames';
11 function generateOptions(length, disabledOptions, hideDisabledOptions) {
13 for (let value = 0; value < length; value++) {
14 if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
21 class Panel extends Component {
23 clearText: PropTypes.string,
24 prefixCls: PropTypes.string,
25 className: PropTypes.string,
26 defaultOpenValue: PropTypes.object,
27 value: PropTypes.object,
28 placeholder: PropTypes.string,
29 format: PropTypes.string,
30 disabledHours: PropTypes.func,
31 disabledMinutes: PropTypes.func,
32 disabledSeconds: PropTypes.func,
33 hideDisabledOptions: PropTypes.bool,
34 onChange: PropTypes.func,
35 onEsc: PropTypes.func,
36 allowEmpty: PropTypes.bool,
37 showHour: PropTypes.bool,
38 showMinute: PropTypes.bool,
39 showSecond: PropTypes.bool,
40 onClear: PropTypes.func,
41 use12Hours: PropTypes.bool,
42 addon: PropTypes.func,
45 static defaultProps = {
46 prefixCls: 'rc-time-picker-panel',
50 disabledMinutes: noop,
51 disabledSeconds: noop,
52 defaultOpenValue: moment(),
65 componentWillReceiveProps(nextProps) {
66 const value = nextProps.value;
74 onChange = (newValue) => {
75 this.setState({ value: newValue });
76 this.props.onChange(newValue);
79 onCurrentSelectPanelChange = (currentSelectPanel) => {
80 this.setState({ currentSelectPanel });
85 prefixCls, className, placeholder, disabledHours, disabledMinutes,
86 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
87 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
90 value, currentSelectPanel,
92 const disabledHourOptions = disabledHours();
93 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
94 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
95 value ? value.minute() : null);
96 const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions);
97 const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions);
98 const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions);
101 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>
103 clearText={clearText}
104 prefixCls={prefixCls}
105 defaultOpenValue={defaultOpenValue}
107 currentSelectPanel={currentSelectPanel}
110 placeholder={placeholder}
111 hourOptions={hourOptions}
112 minuteOptions={minuteOptions}
113 secondOptions={secondOptions}
114 disabledHours={disabledHours}
115 disabledMinutes={disabledMinutes}
116 disabledSeconds={disabledSeconds}
117 onChange={this.onChange}
119 allowEmpty={allowEmpty}
122 prefixCls={prefixCls}
124 defaultOpenValue={defaultOpenValue}
126 onChange={this.onChange}
128 showMinute={showMinute}
129 showSecond={showSecond}
130 hourOptions={hourOptions}
131 minuteOptions={minuteOptions}
132 secondOptions={secondOptions}
133 disabledHours={disabledHours}
134 disabledMinutes={disabledMinutes}
135 disabledSeconds={disabledSeconds}
136 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
137 use12Hours={use12Hours}
145 export default Panel;