diff options
Diffstat (limited to 'src/module/Panel.jsx')
-rw-r--r-- | src/module/Panel.jsx | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index 63823ee..94d3842 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx | |||
@@ -6,10 +6,12 @@ import Combobox from './Combobox'; | |||
6 | function noop() { | 6 | function noop() { |
7 | } | 7 | } |
8 | 8 | ||
9 | function generateOptions(length) { | 9 | function generateOptions(length, disabledOptions, hideDisabledOptions) { |
10 | const arr = []; | 10 | const arr = []; |
11 | for (let i = 0; i < length; i++) { | 11 | for (let value = 0; value < length; value++) { |
12 | arr.push(i); | 12 | if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { |
13 | arr.push(value); | ||
14 | } | ||
13 | } | 15 | } |
14 | return arr; | 16 | return arr; |
15 | } | 17 | } |
@@ -22,9 +24,10 @@ const Panel = React.createClass({ | |||
22 | placeholder: PropTypes.string, | 24 | placeholder: PropTypes.string, |
23 | gregorianCalendarLocale: PropTypes.object, | 25 | gregorianCalendarLocale: PropTypes.object, |
24 | formatter: PropTypes.object, | 26 | formatter: PropTypes.object, |
25 | hourOptions: PropTypes.array, | 27 | disabledHours: PropTypes.func, |
26 | minuteOptions: PropTypes.array, | 28 | disabledMinutes: PropTypes.func, |
27 | secondOptions: PropTypes.array, | 29 | disabledSeconds: PropTypes.func, |
30 | hideDisabledOptions: PropTypes.bool, | ||
28 | onChange: PropTypes.func, | 31 | onChange: PropTypes.func, |
29 | onEsc: PropTypes.func, | 32 | onEsc: PropTypes.func, |
30 | allowEmpty: PropTypes.bool, | 33 | allowEmpty: PropTypes.bool, |
@@ -37,9 +40,6 @@ const Panel = React.createClass({ | |||
37 | 40 | ||
38 | getDefaultProps() { | 41 | getDefaultProps() { |
39 | return { | 42 | return { |
40 | hourOptions: generateOptions(24), | ||
41 | minuteOptions: generateOptions(60), | ||
42 | secondOptions: generateOptions(60), | ||
43 | onChange: noop, | 43 | onChange: noop, |
44 | onClear: noop, | 44 | onClear: noop, |
45 | }; | 45 | }; |
@@ -75,8 +75,15 @@ const Panel = React.createClass({ | |||
75 | }, | 75 | }, |
76 | 76 | ||
77 | render() { | 77 | render() { |
78 | const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; | 78 | const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; |
79 | const value = this.state.value; | 79 | const value = this.state.value; |
80 | const disabledHourOptions = disabledHours(); | ||
81 | const disabledMinuteOptions = disabledMinutes(value.getHourOfDay()); | ||
82 | const disabledSecondOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); | ||
83 | const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); | ||
84 | const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); | ||
85 | const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); | ||
86 | |||
80 | return ( | 87 | return ( |
81 | <div className={`${prefixCls}-inner`}> | 88 | <div className={`${prefixCls}-inner`}> |
82 | <Header | 89 | <Header |
@@ -91,6 +98,9 @@ const Panel = React.createClass({ | |||
91 | hourOptions={hourOptions} | 98 | hourOptions={hourOptions} |
92 | minuteOptions={minuteOptions} | 99 | minuteOptions={minuteOptions} |
93 | secondOptions={secondOptions} | 100 | secondOptions={secondOptions} |
101 | disabledHours={disabledHours} | ||
102 | disabledMinutes={disabledMinutes} | ||
103 | disabledSeconds={disabledSeconds} | ||
94 | onChange={this.onChange} | 104 | onChange={this.onChange} |
95 | onClear={this.onClear} | 105 | onClear={this.onClear} |
96 | allowEmpty={allowEmpty} | 106 | allowEmpty={allowEmpty} |
@@ -106,6 +116,9 @@ const Panel = React.createClass({ | |||
106 | hourOptions={hourOptions} | 116 | hourOptions={hourOptions} |
107 | minuteOptions={minuteOptions} | 117 | minuteOptions={minuteOptions} |
108 | secondOptions={secondOptions} | 118 | secondOptions={secondOptions} |
119 | disabledHours={disabledHours} | ||
120 | disabledMinutes={disabledMinutes} | ||
121 | disabledSeconds={disabledSeconds} | ||
109 | onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} | 122 | onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} |
110 | /> | 123 | /> |
111 | </div> | 124 | </div> |