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, step = 1) {
13 for (let value = 0; value < length; value += step) {
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 hourStep: PropTypes.number,
43 minuteStep: PropTypes.number,
44 secondStep: PropTypes.number,
45 addon: PropTypes.func,
48 static defaultProps = {
49 prefixCls: 'rc-time-picker-panel',
53 disabledMinutes: noop,
54 disabledSeconds: noop,
55 defaultOpenValue: moment(),
68 componentWillReceiveProps(nextProps) {
69 const value = nextProps.value;
77 onChange = (newValue) => {
78 this.setState({ value: newValue });
79 this.props.onChange(newValue);
82 onCurrentSelectPanelChange = (currentSelectPanel) => {
83 this.setState({ currentSelectPanel });
86 // https://github.com/ant-design/ant-design/issues/5829
93 prefixCls, className, placeholder, disabledHours, disabledMinutes,
94 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
95 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
96 hourStep, minuteStep, secondStep,
99 value, currentSelectPanel,
101 const disabledHourOptions = disabledHours();
102 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
103 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
104 value ? value.minute() : null);
105 const hourOptions = generateOptions(
106 24, disabledHourOptions, hideDisabledOptions, hourStep
108 const minuteOptions = generateOptions(
109 60, disabledMinuteOptions, hideDisabledOptions, minuteStep
111 const secondOptions = generateOptions(
112 60, disabledSecondOptions, hideDisabledOptions, secondStep
116 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>
118 clearText={clearText}
119 prefixCls={prefixCls}
120 defaultOpenValue={defaultOpenValue}
122 currentSelectPanel={currentSelectPanel}
125 placeholder={placeholder}
126 hourOptions={hourOptions}
127 minuteOptions={minuteOptions}
128 secondOptions={secondOptions}
129 disabledHours={disabledHours}
130 disabledMinutes={disabledMinutes}
131 disabledSeconds={disabledSeconds}
132 onChange={this.onChange}
134 allowEmpty={allowEmpty}
137 prefixCls={prefixCls}
139 defaultOpenValue={defaultOpenValue}
141 onChange={this.onChange}
143 showMinute={showMinute}
144 showSecond={showSecond}
145 hourOptions={hourOptions}
146 minuteOptions={minuteOptions}
147 secondOptions={secondOptions}
148 disabledHours={disabledHours}
149 disabledMinutes={disabledMinutes}
150 disabledSeconds={disabledSeconds}
151 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
152 use12Hours={use12Hours}
160 export default Panel;