diff options
author | 偏右 <afc163@gmail.com> | 2017-10-22 16:53:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-22 16:53:32 +0800 |
commit | 81cdb7024e669b0c2c8cc1911776d47683e3500d (patch) | |
tree | eb9bf3c0b111087cbf868ec434baba96b539be5d /src/Panel.jsx | |
parent | 8c22015207c1927b27c90b4bf0f40dc9c56d2fe5 (diff) | |
parent | f0ac29c61df164ab3e867ef86137faa13d85a87f (diff) | |
download | time-picker-81cdb7024e669b0c2c8cc1911776d47683e3500d.tar.gz time-picker-81cdb7024e669b0c2c8cc1911776d47683e3500d.tar.zst time-picker-81cdb7024e669b0c2c8cc1911776d47683e3500d.zip |
Merge pull request #72 from marekpiechut/picker-step
Add hourStep, minuteStep and secondStep props to control intervals in picker
Diffstat (limited to 'src/Panel.jsx')
-rw-r--r-- | src/Panel.jsx | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/Panel.jsx b/src/Panel.jsx index 957c021..a1b7c77 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx | |||
@@ -8,9 +8,9 @@ import classNames from 'classnames'; | |||
8 | function noop() { | 8 | function noop() { |
9 | } | 9 | } |
10 | 10 | ||
11 | function generateOptions(length, disabledOptions, hideDisabledOptions) { | 11 | function 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 | focusOnOpen: PropTypes.bool, | 46 | focusOnOpen: PropTypes.bool, |
44 | onKeyDown: PropTypes.func, | 47 | onKeyDown: PropTypes.func, |
@@ -92,7 +95,8 @@ class Panel extends Component { | |||
92 | const { | 95 | const { |
93 | prefixCls, className, placeholder, disabledHours, disabledMinutes, | 96 | prefixCls, className, placeholder, disabledHours, disabledMinutes, |
94 | disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, | 97 | disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, |
95 | format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, focusOnOpen, onKeyDown, | 98 | format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, |
99 | focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, | ||
96 | } = this.props; | 100 | } = this.props; |
97 | const { | 101 | const { |
98 | value, currentSelectPanel, | 102 | value, currentSelectPanel, |
@@ -101,9 +105,15 @@ class Panel extends Component { | |||
101 | const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); | 105 | const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); |
102 | const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, | 106 | const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, |
103 | value ? value.minute() : null); | 107 | value ? value.minute() : null); |
104 | const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); | 108 | const hourOptions = generateOptions( |
105 | const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); | 109 | 24, disabledHourOptions, hideDisabledOptions, hourStep |
106 | const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); | 110 | ); |
111 | const minuteOptions = generateOptions( | ||
112 | 60, disabledMinuteOptions, hideDisabledOptions, minuteStep | ||
113 | ); | ||
114 | const secondOptions = generateOptions( | ||
115 | 60, disabledSecondOptions, hideDisabledOptions, secondStep | ||
116 | ); | ||
107 | 117 | ||
108 | return ( | 118 | return ( |
109 | <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}> | 119 | <div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}> |