aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-14 00:50:41 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-14 00:50:41 +0800
commit71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 (patch)
treee24404e929db29204fa008546377351d314f9480 /src
parent0e62bf0b7bdc260e882fd185492939cbaed04d56 (diff)
downloadtime-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.gz
time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.zst
time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.zip
update disabled options
Diffstat (limited to 'src')
-rw-r--r--src/TimePicker.jsx12
-rw-r--r--src/module/Combobox.jsx22
-rw-r--r--src/module/Header.jsx15
-rw-r--r--src/module/Panel.jsx19
4 files changed, 38 insertions, 30 deletions
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index fb855e2..ad4e834 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -34,9 +34,9 @@ const Picker = React.createClass({
34 style: PropTypes.object, 34 style: PropTypes.object,
35 className: PropTypes.string, 35 className: PropTypes.string,
36 showSecond: PropTypes.bool, 36 showSecond: PropTypes.bool,
37 disabledHours: PropTypes.array, 37 disabledHours: PropTypes.func,
38 disabledMinutes: PropTypes.array, 38 disabledMinutes: PropTypes.func,
39 disabledSeconds: PropTypes.array, 39 disabledSeconds: PropTypes.func,
40 hideDisabledOptions: PropTypes.bool, 40 hideDisabledOptions: PropTypes.bool,
41 onChange: PropTypes.func, 41 onChange: PropTypes.func,
42 onOpen: PropTypes.func, 42 onOpen: PropTypes.func,
@@ -55,9 +55,9 @@ const Picker = React.createClass({
55 allowEmpty: true, 55 allowEmpty: true,
56 showHour: true, 56 showHour: true,
57 showSecond: true, 57 showSecond: true,
58 disabledHours: null, 58 disabledHours: noop,
59 disabledMinutes: null, 59 disabledMinutes: noop,
60 disabledSeconds: null, 60 disabledSeconds: noop,
61 hideDisabledOptions: false, 61 hideDisabledOptions: false,
62 placement: 'bottomLeft', 62 placement: 'bottomLeft',
63 onChange: noop, 63 onChange: noop,
diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx
index 1e172a7..7374b39 100644
--- a/src/module/Combobox.jsx
+++ b/src/module/Combobox.jsx
@@ -31,9 +31,9 @@ const Combobox = React.createClass({
31 hourOptions: PropTypes.array, 31 hourOptions: PropTypes.array,
32 minuteOptions: PropTypes.array, 32 minuteOptions: PropTypes.array,
33 secondOptions: PropTypes.array, 33 secondOptions: PropTypes.array,
34 disabledHours: PropTypes.array, 34 disabledHours: PropTypes.func,
35 disabledMinutes: PropTypes.array, 35 disabledMinutes: PropTypes.func,
36 disabledSeconds: PropTypes.array, 36 disabledSeconds: PropTypes.func,
37 onCurrentSelectPanelChange: PropTypes.func, 37 onCurrentSelectPanelChange: PropTypes.func,
38 }, 38 },
39 39
@@ -64,10 +64,12 @@ const Combobox = React.createClass({
64 if (!showHour) { 64 if (!showHour) {
65 return null; 65 return null;
66 } 66 }
67 const disabledOptions = disabledHours();
68
67 return ( 69 return (
68 <Select 70 <Select
69 prefixCls={prefixCls} 71 prefixCls={prefixCls}
70 options={hourOptions.map(option => formatOption(option, disabledHours))} 72 options={hourOptions.map(option => formatOption(option, disabledOptions))}
71 selectedIndex={hourOptions.indexOf(hour)} 73 selectedIndex={hourOptions.indexOf(hour)}
72 type="hour" 74 type="hour"
73 onSelect={this.onItemChange} 75 onSelect={this.onItemChange}
@@ -77,11 +79,13 @@ const Combobox = React.createClass({
77 }, 79 },
78 80
79 getMinuteSelect(minute) { 81 getMinuteSelect(minute) {
80 const { prefixCls, minuteOptions, disabledMinutes } = this.props; 82 const { prefixCls, minuteOptions, disabledMinutes, value } = this.props;
83 const disabledOptions = disabledMinutes(value.getHourOfDay());
84
81 return ( 85 return (
82 <Select 86 <Select
83 prefixCls={prefixCls} 87 prefixCls={prefixCls}
84 options={minuteOptions.map(option => formatOption(option, disabledMinutes))} 88 options={minuteOptions.map(option => formatOption(option, disabledOptions))}
85 selectedIndex={minuteOptions.indexOf(minute)} 89 selectedIndex={minuteOptions.indexOf(minute)}
86 type="minute" 90 type="minute"
87 onSelect={this.onItemChange} 91 onSelect={this.onItemChange}
@@ -91,14 +95,16 @@ const Combobox = React.createClass({
91 }, 95 },
92 96
93 getSecondSelect(second) { 97 getSecondSelect(second) {
94 const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props; 98 const { prefixCls, secondOptions, disabledSeconds, showSecond, value } = this.props;
95 if (!showSecond) { 99 if (!showSecond) {
96 return null; 100 return null;
97 } 101 }
102 const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes());
103
98 return ( 104 return (
99 <Select 105 <Select
100 prefixCls={prefixCls} 106 prefixCls={prefixCls}
101 options={secondOptions.map(option => formatOption(option, disabledSeconds))} 107 options={secondOptions.map(option => formatOption(option, disabledOptions))}
102 selectedIndex={secondOptions.indexOf(second)} 108 selectedIndex={secondOptions.indexOf(second)}
103 type="second" 109 type="second"
104 onSelect={this.onItemChange} 110 onSelect={this.onItemChange}
diff --git a/src/module/Header.jsx b/src/module/Header.jsx
index fec02af..9a048dc 100644
--- a/src/module/Header.jsx
+++ b/src/module/Header.jsx
@@ -13,9 +13,9 @@ const Header = React.createClass({
13 hourOptions: PropTypes.array, 13 hourOptions: PropTypes.array,
14 minuteOptions: PropTypes.array, 14 minuteOptions: PropTypes.array,
15 secondOptions: PropTypes.array, 15 secondOptions: PropTypes.array,
16 disabledHours: PropTypes.array, 16 disabledHours: PropTypes.func,
17 disabledMinutes: PropTypes.array, 17 disabledMinutes: PropTypes.func,
18 disabledSeconds: PropTypes.array, 18 disabledSeconds: PropTypes.func,
19 onChange: PropTypes.func, 19 onChange: PropTypes.func,
20 onClear: PropTypes.func, 20 onClear: PropTypes.func,
21 onEsc: PropTypes.func, 21 onEsc: PropTypes.func,
@@ -87,10 +87,13 @@ const Header = React.createClass({
87 } 87 }
88 88
89 // if time value is disabled, response warning. 89 // if time value is disabled, response warning.
90 const disabledHourOptions = disabledHours();
91 const disabledMinuteOptions = disabledMinutes(value.getHourOfDay());
92 const disabledSecondOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes());
90 if ( 93 if (
91 (disabledHours && disabledHours.indexOf(value.getHourOfDay()) >= 0) || 94 (disabledHourOptions && disabledHourOptions.indexOf(value.getHourOfDay()) >= 0) ||
92 (disabledMinutes && disabledMinutes.indexOf(value.getMinutes()) >= 0) || 95 (disabledMinuteOptions && disabledMinuteOptions.indexOf(value.getMinutes()) >= 0) ||
93 (disabledSeconds && disabledSeconds.indexOf(value.getSeconds()) >= 0) 96 (disabledSecondOptions && disabledSecondOptions.indexOf(value.getSeconds()) >= 0)
94 ) { 97 ) {
95 this.setState({ 98 this.setState({
96 invalid: true, 99 invalid: true,
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx
index 12d23f7..94d3842 100644
--- a/src/module/Panel.jsx
+++ b/src/module/Panel.jsx
@@ -24,9 +24,9 @@ const Panel = React.createClass({
24 placeholder: PropTypes.string, 24 placeholder: PropTypes.string,
25 gregorianCalendarLocale: PropTypes.object, 25 gregorianCalendarLocale: PropTypes.object,
26 formatter: PropTypes.object, 26 formatter: PropTypes.object,
27 disabledHours: PropTypes.array, 27 disabledHours: PropTypes.func,
28 disabledMinutes: PropTypes.array, 28 disabledMinutes: PropTypes.func,
29 disabledSeconds: PropTypes.array, 29 disabledSeconds: PropTypes.func,
30 hideDisabledOptions: PropTypes.bool, 30 hideDisabledOptions: PropTypes.bool,
31 onChange: PropTypes.func, 31 onChange: PropTypes.func,
32 onEsc: PropTypes.func, 32 onEsc: PropTypes.func,
@@ -40,10 +40,6 @@ const Panel = React.createClass({
40 40
41 getDefaultProps() { 41 getDefaultProps() {
42 return { 42 return {
43 disabledHours: null,
44 disabledMinutes: null,
45 disabledSeconds: null,
46 hideDisabledOptions: false,
47 onChange: noop, 43 onChange: noop,
48 onClear: noop, 44 onClear: noop,
49 }; 45 };
@@ -81,9 +77,12 @@ const Panel = React.createClass({
81 render() { 77 render() {
82 const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; 78 const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props;
83 const value = this.state.value; 79 const value = this.state.value;
84 const hourOptions = generateOptions(24, disabledHours, hideDisabledOptions); 80 const disabledHourOptions = disabledHours();
85 const minuteOptions = generateOptions(60, disabledMinutes, hideDisabledOptions); 81 const disabledMinuteOptions = disabledMinutes(value.getHourOfDay());
86 const secondOptions = generateOptions(60, disabledSeconds, hideDisabledOptions); 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);
87 86
88 return ( 87 return (
89 <div className={`${prefixCls}-inner`}> 88 <div className={`${prefixCls}-inner`}>