From 7211e9ba9d88c89444e7909190e7c51d298200ad Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Fri, 23 Feb 2018 11:16:42 +0800 Subject: Lift disabledHours to Panel --- src/Combobox.jsx | 20 ++++---------------- src/Panel.jsx | 27 +++++++++++++++++++++++---- 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 { disabledSeconds: PropTypes.func, onCurrentSelectPanelChange: PropTypes.func, use12Hours: PropTypes.bool, + isAM: PropTypes.bool, }; onItemChange = (type, itemValue) => { @@ -45,7 +46,7 @@ class Combobox extends Component { if (type === 'hour') { if (use12Hours) { - if (this.isAM()) { + if (this.props.isAM) { value.hour(+itemValue % 12); } else { value.hour((+itemValue % 12) + 12); @@ -83,20 +84,12 @@ class Combobox extends Component { if (!showHour) { return null; } - let disabledOptions = disabledHours(); + const disabledOptions = disabledHours(); let hourOptionsAdj; let hourAdj; if (use12Hours) { hourOptionsAdj = [12].concat(hourOptions.filter(h => h < 12 && h > 0)); hourAdj = (hour % 12) || 12; - - if (Array.isArray(disabledOptions)) { - if (this.isAM()) { - disabledOptions = disabledOptions.filter(h => h < 12).map(h => (h === 0 ? 12 : h)); - } else { - disabledOptions = disabledOptions.map(h => (h === 12 ? 12 : h - 12)); - } - } } else { hourOptionsAdj = hourOptions; hourAdj = hour; @@ -164,7 +157,7 @@ class Combobox extends Component { .map(c => format.match(/\sA/) ? c.toUpperCase() : c) .map(c => ({ value: c })); - const selected = this.isAM() ? 0 : 1; + const selected = this.props.isAM ? 0 : 1; return (