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 inputReadOnly: PropTypes.bool,
31 disabledHours: PropTypes.func,
32 disabledMinutes: PropTypes.func,
33 disabledSeconds: PropTypes.func,
34 hideDisabledOptions: PropTypes.bool,
35 onChange: PropTypes.func,
36 onEsc: PropTypes.func,
37 allowEmpty: PropTypes.bool,
38 showHour: PropTypes.bool,
39 showMinute: PropTypes.bool,
40 showSecond: PropTypes.bool,
41 onClear: PropTypes.func,
42 use12Hours: PropTypes.bool,
43 hourStep: PropTypes.number,
44 minuteStep: PropTypes.number,
45 secondStep: PropTypes.number,
46 addon: PropTypes.func,
47 focusOnOpen: PropTypes.bool,
48 onKeyDown: PropTypes.func,
51 static defaultProps = {
52 prefixCls: 'rc-time-picker-panel',
56 disabledMinutes: noop,
57 disabledSeconds: noop,
58 defaultOpenValue: moment(),
73 componentWillReceiveProps(nextProps) {
74 const value = nextProps.value;
82 onChange = (newValue) => {
83 this.setState({ value: newValue });
84 this.props.onChange(newValue);
87 onCurrentSelectPanelChange = (currentSelectPanel) => {
88 this.setState({ currentSelectPanel });
91 // https://github.com/ant-design/ant-design/issues/5829
98 prefixCls, className, placeholder, disabledHours, disabledMinutes,
99 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
100 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
101 focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly,
104 value, currentSelectPanel,
106 const disabledHourOptions = disabledHours();
107 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
108 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
109 value ? value.minute() : null);
110 const hourOptions = generateOptions(
111 24, disabledHourOptions, hideDisabledOptions, hourStep
113 const minuteOptions = generateOptions(
114 60, disabledMinuteOptions, hideDisabledOptions, minuteStep
116 const secondOptions = generateOptions(
117 60, disabledSecondOptions, hideDisabledOptions, secondStep
121 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>
123 clearText={clearText}
124 prefixCls={prefixCls}
125 defaultOpenValue={defaultOpenValue}
127 currentSelectPanel={currentSelectPanel}
130 placeholder={placeholder}
131 hourOptions={hourOptions}
132 minuteOptions={minuteOptions}
133 secondOptions={secondOptions}
134 disabledHours={disabledHours}
135 disabledMinutes={disabledMinutes}
136 disabledSeconds={disabledSeconds}
137 onChange={this.onChange}
139 allowEmpty={allowEmpty}
140 focusOnOpen={focusOnOpen}
141 onKeyDown={onKeyDown}
142 inputReadOnly={inputReadOnly}
145 prefixCls={prefixCls}
147 defaultOpenValue={defaultOpenValue}
149 onChange={this.onChange}
151 showMinute={showMinute}
152 showSecond={showSecond}
153 hourOptions={hourOptions}
154 minuteOptions={minuteOptions}
155 secondOptions={secondOptions}
156 disabledHours={disabledHours}
157 disabledMinutes={disabledMinutes}
158 disabledSeconds={disabledSeconds}
159 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
160 use12Hours={use12Hours}
168 export default Panel;