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,
46 focusOnOpen: PropTypes.bool,
47 onKeyDown: PropTypes.func,
50 static defaultProps = {
51 prefixCls: 'rc-time-picker-panel',
55 disabledMinutes: noop,
56 disabledSeconds: noop,
57 defaultOpenValue: moment(),
71 componentWillReceiveProps(nextProps) {
72 const value = nextProps.value;
80 onChange = (newValue) => {
81 this.setState({ value: newValue });
82 this.props.onChange(newValue);
85 onCurrentSelectPanelChange = (currentSelectPanel) => {
86 this.setState({ currentSelectPanel });
89 // https://github.com/ant-design/ant-design/issues/5829
96 prefixCls, className, placeholder, disabledHours, disabledMinutes,
97 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
98 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
99 focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
102 value, currentSelectPanel,
104 const disabledHourOptions = disabledHours();
105 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
106 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
107 value ? value.minute() : null);
108 const hourOptions = generateOptions(
109 24, disabledHourOptions, hideDisabledOptions, hourStep
111 const minuteOptions = generateOptions(
112 60, disabledMinuteOptions, hideDisabledOptions, minuteStep
114 const secondOptions = generateOptions(
115 60, disabledSecondOptions, hideDisabledOptions, secondStep
119 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>
121 clearText={clearText}
122 prefixCls={prefixCls}
123 defaultOpenValue={defaultOpenValue}
125 currentSelectPanel={currentSelectPanel}
128 placeholder={placeholder}
129 hourOptions={hourOptions}
130 minuteOptions={minuteOptions}
131 secondOptions={secondOptions}
132 disabledHours={disabledHours}
133 disabledMinutes={disabledMinutes}
134 disabledSeconds={disabledSeconds}
135 onChange={this.onChange}
137 allowEmpty={allowEmpty}
138 focusOnOpen={focusOnOpen}
139 onKeyDown={onKeyDown}
142 prefixCls={prefixCls}
144 defaultOpenValue={defaultOpenValue}
146 onChange={this.onChange}
148 showMinute={showMinute}
149 showSecond={showSecond}
150 hourOptions={hourOptions}
151 minuteOptions={minuteOptions}
152 secondOptions={secondOptions}
153 disabledHours={disabledHours}
154 disabledMinutes={disabledMinutes}
155 disabledSeconds={disabledSeconds}
156 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
157 use12Hours={use12Hours}
165 export default Panel;