aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/module/Panel.jsx
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-12 20:34:00 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-12 20:34:00 +0800
commit518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 (patch)
tree664ef5377589dc3c4def7e732dfaa76e89da1fb1 /src/module/Panel.jsx
parent182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff)
downloadtime-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.gz
time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.zst
time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.zip
add new options about disabled time
Diffstat (limited to 'src/module/Panel.jsx')
-rw-r--r--src/module/Panel.jsx34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx
index 63823ee..72934e5 100644
--- a/src/module/Panel.jsx
+++ b/src/module/Panel.jsx
@@ -6,10 +6,12 @@ import Combobox from './Combobox';
6function noop() { 6function noop() {
7} 7}
8 8
9function generateOptions(length) { 9function 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.array,
26 minuteOptions: PropTypes.array, 28 disabledMinutes: PropTypes.array,
27 secondOptions: PropTypes.array, 29 disabledSeconds: PropTypes.array,
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,10 @@ const Panel = React.createClass({
37 40
38 getDefaultProps() { 41 getDefaultProps() {
39 return { 42 return {
40 hourOptions: generateOptions(24), 43 disabledHours: null,
41 minuteOptions: generateOptions(60), 44 disabledMinutes: null,
42 secondOptions: generateOptions(60), 45 disabledSeconds: null,
46 hideDisabledOptions: false,
43 onChange: noop, 47 onChange: noop,
44 onClear: noop, 48 onClear: noop,
45 }; 49 };
@@ -75,8 +79,12 @@ const Panel = React.createClass({
75 }, 79 },
76 80
77 render() { 81 render() {
78 const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; 82 const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props;
79 const value = this.state.value; 83 const value = this.state.value;
84 const hourOptions = generateOptions(24, disabledHours, hideDisabledOptions);
85 const minuteOptions = generateOptions(60, disabledMinutes, hideDisabledOptions);
86 const secondOptions = generateOptions(60, disabledSeconds, hideDisabledOptions);
87
80 return ( 88 return (
81 <div className={`${prefixCls}-inner`}> 89 <div className={`${prefixCls}-inner`}>
82 <Header 90 <Header
@@ -91,6 +99,9 @@ const Panel = React.createClass({
91 hourOptions={hourOptions} 99 hourOptions={hourOptions}
92 minuteOptions={minuteOptions} 100 minuteOptions={minuteOptions}
93 secondOptions={secondOptions} 101 secondOptions={secondOptions}
102 disabledHours={disabledHours}
103 disabledMinutes={disabledMinutes}
104 disabledSeconds={disabledSeconds}
94 onChange={this.onChange} 105 onChange={this.onChange}
95 onClear={this.onClear} 106 onClear={this.onClear}
96 allowEmpty={allowEmpty} 107 allowEmpty={allowEmpty}
@@ -106,6 +117,9 @@ const Panel = React.createClass({
106 hourOptions={hourOptions} 117 hourOptions={hourOptions}
107 minuteOptions={minuteOptions} 118 minuteOptions={minuteOptions}
108 secondOptions={secondOptions} 119 secondOptions={secondOptions}
120 disabledHours={disabledHours}
121 disabledMinutes={disabledMinutes}
122 disabledSeconds={disabledSeconds}
109 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} 123 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
110 /> 124 />
111 </div> 125 </div>