aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Panel.jsx
diff options
context:
space:
mode:
authorMarek Piechut <marek.piechut@gmail.com>2017-10-09 13:38:00 +0200
committerMarek Piechut <marek.piechut@gmail.com>2017-10-09 13:38:00 +0200
commit5827568ef882ae5a474f37ff5c843e931528ebe8 (patch)
treede49d29b22db47adcaba3dee2bdf94227fdae665 /src/Panel.jsx
parent35d5ed7815f4707c79565a45261ffadc21d604be (diff)
downloadtime-picker-5827568ef882ae5a474f37ff5c843e931528ebe8.tar.gz
time-picker-5827568ef882ae5a474f37ff5c843e931528ebe8.tar.zst
time-picker-5827568ef882ae5a474f37ff5c843e931528ebe8.zip
Add hourStep, minuteStep and secondStep props to control intervals in picker
Diffstat (limited to 'src/Panel.jsx')
-rw-r--r--src/Panel.jsx20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Panel.jsx b/src/Panel.jsx
index 1953ad4..468eb37 100644
--- a/src/Panel.jsx
+++ b/src/Panel.jsx
@@ -8,9 +8,9 @@ import classNames from 'classnames';
8function noop() { 8function noop() {
9} 9}
10 10
11function generateOptions(length, disabledOptions, hideDisabledOptions) { 11function generateOptions(length, disabledOptions, hideDisabledOptions, step = 1) {
12 const arr = []; 12 const arr = [];
13 for (let value = 0; value < length; value++) { 13 for (let value = 0; value < length; value += step) {
14 if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { 14 if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
15 arr.push(value); 15 arr.push(value);
16 } 16 }
@@ -39,6 +39,9 @@ class Panel extends Component {
39 showSecond: PropTypes.bool, 39 showSecond: PropTypes.bool,
40 onClear: PropTypes.func, 40 onClear: PropTypes.func,
41 use12Hours: PropTypes.bool, 41 use12Hours: PropTypes.bool,
42 hourStep: PropTypes.number,
43 minuteStep: PropTypes.number,
44 secondStep: PropTypes.number,
42 addon: PropTypes.func, 45 addon: PropTypes.func,
43 }; 46 };
44 47
@@ -90,6 +93,7 @@ class Panel extends Component {
90 prefixCls, className, placeholder, disabledHours, disabledMinutes, 93 prefixCls, className, placeholder, disabledHours, disabledMinutes,
91 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, 94 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
92 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, 95 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
96 hourStep, minuteStep, secondStep,
93 } = this.props; 97 } = this.props;
94 const { 98 const {
95 value, currentSelectPanel, 99 value, currentSelectPanel,
@@ -98,9 +102,15 @@ class Panel extends Component {
98 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); 102 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
99 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, 103 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
100 value ? value.minute() : null); 104 value ? value.minute() : null);
101 const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); 105 const hourOptions = generateOptions(
102 const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); 106 24, disabledHourOptions, hideDisabledOptions, hourStep
103 const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); 107 );
108 const minuteOptions = generateOptions(
109 60, disabledMinuteOptions, hideDisabledOptions, minuteStep
110 );
111 const secondOptions = generateOptions(
112 60, disabledSecondOptions, hideDisabledOptions, secondStep
113 );
104 114
105 return ( 115 return (
106 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}> 116 <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>