From 518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 Mon Sep 17 00:00:00 2001
From: MG12 <wuzhao.mail@gmail.com>
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 (
       <Select
         prefixCls={prefixCls}
-        options={hourOptions.map(option => formatOption(option))}
+        options={hourOptions.map(option => formatOption(option, disabledHours))}
         selectedIndex={hourOptions.indexOf(hour)}
         type="hour"
         onSelect={this.onItemChange}
@@ -64,11 +77,11 @@ const Combobox = React.createClass({
   },
 
   getMinuteSelect(minute) {
-    const { prefixCls, minuteOptions } = this.props;
+    const { prefixCls, minuteOptions, disabledMinutes } = this.props;
     return (
       <Select
         prefixCls={prefixCls}
-        options={minuteOptions.map(option => 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 (
       <Select
         prefixCls={prefixCls}
-        options={secondOptions.map(option => formatOption(option))}
+        options={secondOptions.map(option => formatOption(option, disabledSeconds))}
         selectedIndex={secondOptions.indexOf(second)}
         type="second"
         onSelect={this.onItemChange}
-- 
cgit v1.2.3


From 0e62bf0b7bdc260e882fd185492939cbaed04d56 Mon Sep 17 00:00:00 2001
From: MG12 <wuzhao.mail@gmail.com>
Date: Sun, 13 Dec 2015 00:03:19 +0800
Subject: update test case and fix bugs

---
 src/module/Combobox.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/module/Combobox.jsx')

diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx
index 27a8226..1e172a7 100644
--- a/src/module/Combobox.jsx
+++ b/src/module/Combobox.jsx
@@ -9,7 +9,7 @@ const formatOption = (option, disabledOptions) => {
   }
 
   let disabled = false;
-  if (disabledOptions.indexOf(option) >= 0) {
+  if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
     disabled = true;
   }
 
-- 
cgit v1.2.3


From 71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 Mon Sep 17 00:00:00 2001
From: MG12 <wuzhao.mail@gmail.com>
Date: Mon, 14 Dec 2015 00:50:41 +0800
Subject: update disabled options

---
 src/module/Combobox.jsx | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

(limited to 'src/module/Combobox.jsx')

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({
     hourOptions: PropTypes.array,
     minuteOptions: PropTypes.array,
     secondOptions: PropTypes.array,
-    disabledHours: PropTypes.array,
-    disabledMinutes: PropTypes.array,
-    disabledSeconds: PropTypes.array,
+    disabledHours: PropTypes.func,
+    disabledMinutes: PropTypes.func,
+    disabledSeconds: PropTypes.func,
     onCurrentSelectPanelChange: PropTypes.func,
   },
 
@@ -64,10 +64,12 @@ const Combobox = React.createClass({
     if (!showHour) {
       return null;
     }
+    const disabledOptions = disabledHours();
+
     return (
       <Select
         prefixCls={prefixCls}
-        options={hourOptions.map(option => formatOption(option, disabledHours))}
+        options={hourOptions.map(option => formatOption(option, disabledOptions))}
         selectedIndex={hourOptions.indexOf(hour)}
         type="hour"
         onSelect={this.onItemChange}
@@ -77,11 +79,13 @@ const Combobox = React.createClass({
   },
 
   getMinuteSelect(minute) {
-    const { prefixCls, minuteOptions, disabledMinutes } = this.props;
+    const { prefixCls, minuteOptions, disabledMinutes, value } = this.props;
+    const disabledOptions = disabledMinutes(value.getHourOfDay());
+
     return (
       <Select
         prefixCls={prefixCls}
-        options={minuteOptions.map(option => formatOption(option, disabledMinutes))}
+        options={minuteOptions.map(option => formatOption(option, disabledOptions))}
         selectedIndex={minuteOptions.indexOf(minute)}
         type="minute"
         onSelect={this.onItemChange}
@@ -91,14 +95,16 @@ const Combobox = React.createClass({
   },
 
   getSecondSelect(second) {
-    const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props;
+    const { prefixCls, secondOptions, disabledSeconds, showSecond, value } = this.props;
     if (!showSecond) {
       return null;
     }
+    const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes());
+
     return (
       <Select
         prefixCls={prefixCls}
-        options={secondOptions.map(option => formatOption(option, disabledSeconds))}
+        options={secondOptions.map(option => formatOption(option, disabledOptions))}
         selectedIndex={secondOptions.indexOf(second)}
         type="second"
         onSelect={this.onItemChange}
-- 
cgit v1.2.3

