From 518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 Mon Sep 17 00:00:00 2001 From: MG12 Date: Sat, 12 Dec 2015 20:34:00 +0800 Subject: add new options about disabled time --- src/module/Combobox.jsx | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/module/Combobox.jsx') diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx index a017ec9..27a8226 100644 --- a/src/module/Combobox.jsx +++ b/src/module/Combobox.jsx @@ -2,11 +2,21 @@ import React, {PropTypes} from 'react'; import Select from './Select'; import GregorianCalendar from 'gregorian-calendar'; -const formatOption = (option) => { +const formatOption = (option, disabledOptions) => { + let value = `${option}`; if (option < 10) { - return `0${option}`; + value = `0${option}`; } - return `${option}`; + + let disabled = false; + if (disabledOptions.indexOf(option) >= 0) { + disabled = true; + } + + return { + value, + disabled, + }; }; const Combobox = React.createClass({ @@ -21,6 +31,9 @@ const Combobox = React.createClass({ hourOptions: PropTypes.array, minuteOptions: PropTypes.array, secondOptions: PropTypes.array, + disabledHours: PropTypes.array, + disabledMinutes: PropTypes.array, + disabledSeconds: PropTypes.array, onCurrentSelectPanelChange: PropTypes.func, }, @@ -47,14 +60,14 @@ const Combobox = React.createClass({ }, getHourSelect(hour) { - const { prefixCls, hourOptions, showHour } = this.props; + const { prefixCls, hourOptions, disabledHours, showHour } = this.props; if (!showHour) { return null; } return ( formatOption(option))} + options={minuteOptions.map(option => formatOption(option, disabledMinutes))} selectedIndex={minuteOptions.indexOf(minute)} type="minute" onSelect={this.onItemChange} @@ -78,14 +91,14 @@ const Combobox = React.createClass({ }, getSecondSelect(second) { - const { prefixCls, secondOptions, showSecond } = this.props; + const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props; if (!showSecond) { return null; } return (