aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Combobox.jsx20
-rw-r--r--src/Panel.jsx27
2 files changed, 27 insertions, 20 deletions
diff --git a/src/Combobox.jsx b/src/Combobox.jsx
index 19fbd19..ae53356 100644
--- a/src/Combobox.jsx
+++ b/src/Combobox.jsx
@@ -37,6 +37,7 @@ class Combobox extends Component {
37 disabledSeconds: PropTypes.func, 37 disabledSeconds: PropTypes.func,
38 onCurrentSelectPanelChange: PropTypes.func, 38 onCurrentSelectPanelChange: PropTypes.func,
39 use12Hours: PropTypes.bool, 39 use12Hours: PropTypes.bool,
40 isAM: PropTypes.bool,
40 }; 41 };
41 42
42 onItemChange = (type, itemValue) => { 43 onItemChange = (type, itemValue) => {
@@ -45,7 +46,7 @@ class Combobox extends Component {
45 46
46 if (type === 'hour') { 47 if (type === 'hour') {
47 if (use12Hours) { 48 if (use12Hours) {
48 if (this.isAM()) { 49 if (this.props.isAM) {
49 value.hour(+itemValue % 12); 50 value.hour(+itemValue % 12);
50 } else { 51 } else {
51 value.hour((+itemValue % 12) + 12); 52 value.hour((+itemValue % 12) + 12);
@@ -83,20 +84,12 @@ class Combobox extends Component {
83 if (!showHour) { 84 if (!showHour) {
84 return null; 85 return null;
85 } 86 }
86 let disabledOptions = disabledHours(); 87 const disabledOptions = disabledHours();
87 let hourOptionsAdj; 88 let hourOptionsAdj;
88 let hourAdj; 89 let hourAdj;
89 if (use12Hours) { 90 if (use12Hours) {
90 hourOptionsAdj = [12].concat(hourOptions.filter(h => h < 12 && h > 0)); 91 hourOptionsAdj = [12].concat(hourOptions.filter(h => h < 12 && h > 0));
91 hourAdj = (hour % 12) || 12; 92 hourAdj = (hour % 12) || 12;
92
93 if (Array.isArray(disabledOptions)) {
94 if (this.isAM()) {
95 disabledOptions = disabledOptions.filter(h => h < 12).map(h => (h === 0 ? 12 : h));
96 } else {
97 disabledOptions = disabledOptions.map(h => (h === 12 ? 12 : h - 12));
98 }
99 }
100 } else { 93 } else {
101 hourOptionsAdj = hourOptions; 94 hourOptionsAdj = hourOptions;
102 hourAdj = hour; 95 hourAdj = hour;
@@ -164,7 +157,7 @@ class Combobox extends Component {
164 .map(c => format.match(/\sA/) ? c.toUpperCase() : c) 157 .map(c => format.match(/\sA/) ? c.toUpperCase() : c)
165 .map(c => ({ value: c })); 158 .map(c => ({ value: c }));
166 159
167 const selected = this.isAM() ? 0 : 1; 160 const selected = this.props.isAM ? 0 : 1;
168 161
169 return ( 162 return (
170 <Select 163 <Select
@@ -178,11 +171,6 @@ class Combobox extends Component {
178 ); 171 );
179 } 172 }
180 173
181 isAM() {
182 const value = (this.props.value || this.props.defaultOpenValue);
183 return value.hour() >= 0 && value.hour() < 12;
184 }
185
186 render() { 174 render() {
187 const { prefixCls, defaultOpenValue } = this.props; 175 const { prefixCls, defaultOpenValue } = this.props;
188 const value = this.props.value || defaultOpenValue; 176 const value = this.props.value || defaultOpenValue;
diff --git a/src/Panel.jsx b/src/Panel.jsx
index 1adb19a..648944d 100644
--- a/src/Panel.jsx
+++ b/src/Panel.jsx
@@ -93,9 +93,27 @@ class Panel extends Component {
93 this.props.onEsc(); 93 this.props.onEsc();
94 } 94 }
95 95
96 disabledHours = () => {
97 const { use12Hours, disabledHours } = this.props;
98 let disabledOptions = disabledHours();
99 if (use12Hours && Array.isArray(disabledOptions)) {
100 if (this.isAM()) {
101 disabledOptions = disabledOptions.filter(h => h < 12).map(h => (h === 0 ? 12 : h));
102 } else {
103 disabledOptions = disabledOptions.map(h => (h === 12 ? 12 : h - 12));
104 }
105 }
106 return disabledOptions;
107 }
108
109 isAM() {
110 const value = (this.state.value || this.props.defaultOpenValue);
111 return value.hour() >= 0 && value.hour() < 12;
112 }
113
96 render() { 114 render() {
97 const { 115 const {
98 prefixCls, className, placeholder, disabledHours, disabledMinutes, 116 prefixCls, className, placeholder, disabledMinutes,
99 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, 117 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
100 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, 118 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
101 focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly, 119 focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly,
@@ -103,7 +121,7 @@ class Panel extends Component {
103 const { 121 const {
104 value, currentSelectPanel, 122 value, currentSelectPanel,
105 } = this.state; 123 } = this.state;
106 const disabledHourOptions = disabledHours(); 124 const disabledHourOptions = this.disabledHours();
107 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); 125 const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
108 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, 126 const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
109 value ? value.minute() : null); 127 value ? value.minute() : null);
@@ -131,7 +149,7 @@ class Panel extends Component {
131 hourOptions={hourOptions} 149 hourOptions={hourOptions}
132 minuteOptions={minuteOptions} 150 minuteOptions={minuteOptions}
133 secondOptions={secondOptions} 151 secondOptions={secondOptions}
134 disabledHours={disabledHours} 152 disabledHours={this.disabledHours}
135 disabledMinutes={disabledMinutes} 153 disabledMinutes={disabledMinutes}
136 disabledSeconds={disabledSeconds} 154 disabledSeconds={disabledSeconds}
137 onChange={this.onChange} 155 onChange={this.onChange}
@@ -153,11 +171,12 @@ class Panel extends Component {
153 hourOptions={hourOptions} 171 hourOptions={hourOptions}
154 minuteOptions={minuteOptions} 172 minuteOptions={minuteOptions}
155 secondOptions={secondOptions} 173 secondOptions={secondOptions}
156 disabledHours={disabledHours} 174 disabledHours={this.disabledHours}
157 disabledMinutes={disabledMinutes} 175 disabledMinutes={disabledMinutes}
158 disabledSeconds={disabledSeconds} 176 disabledSeconds={disabledSeconds}
159 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} 177 onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
160 use12Hours={use12Hours} 178 use12Hours={use12Hours}
179 isAM={this.isAM()}
161 /> 180 />
162 {addon(this)} 181 {addon(this)}
163 </div> 182 </div>