aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/module/Combobox.jsx
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-12 20:34:00 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-12 20:34:00 +0800
commit518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 (patch)
tree664ef5377589dc3c4def7e732dfaa76e89da1fb1 /src/module/Combobox.jsx
parent182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff)
downloadtime-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.gz
time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.zst
time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.zip
add new options about disabled time
Diffstat (limited to 'src/module/Combobox.jsx')
-rw-r--r--src/module/Combobox.jsx31
1 files changed, 22 insertions, 9 deletions
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';
2import Select from './Select'; 2import Select from './Select';
3import GregorianCalendar from 'gregorian-calendar'; 3import GregorianCalendar from 'gregorian-calendar';
4 4
5const formatOption = (option) => { 5const formatOption = (option, disabledOptions) => {
6 let value = `${option}`;
6 if (option < 10) { 7 if (option < 10) {
7 return `0${option}`; 8 value = `0${option}`;
8 } 9 }
9 return `${option}`; 10
11 let disabled = false;
12 if (disabledOptions.indexOf(option) >= 0) {
13 disabled = true;
14 }
15
16 return {
17 value,
18 disabled,
19 };
10}; 20};
11 21
12const Combobox = React.createClass({ 22const Combobox = React.createClass({
@@ -21,6 +31,9 @@ const Combobox = React.createClass({
21 hourOptions: PropTypes.array, 31 hourOptions: PropTypes.array,
22 minuteOptions: PropTypes.array, 32 minuteOptions: PropTypes.array,
23 secondOptions: PropTypes.array, 33 secondOptions: PropTypes.array,
34 disabledHours: PropTypes.array,
35 disabledMinutes: PropTypes.array,
36 disabledSeconds: PropTypes.array,
24 onCurrentSelectPanelChange: PropTypes.func, 37 onCurrentSelectPanelChange: PropTypes.func,
25 }, 38 },
26 39
@@ -47,14 +60,14 @@ const Combobox = React.createClass({
47 }, 60 },
48 61
49 getHourSelect(hour) { 62 getHourSelect(hour) {
50 const { prefixCls, hourOptions, showHour } = this.props; 63 const { prefixCls, hourOptions, disabledHours, showHour } = this.props;
51 if (!showHour) { 64 if (!showHour) {
52 return null; 65 return null;
53 } 66 }
54 return ( 67 return (
55 <Select 68 <Select
56 prefixCls={prefixCls} 69 prefixCls={prefixCls}
57 options={hourOptions.map(option => formatOption(option))} 70 options={hourOptions.map(option => formatOption(option, disabledHours))}
58 selectedIndex={hourOptions.indexOf(hour)} 71 selectedIndex={hourOptions.indexOf(hour)}
59 type="hour" 72 type="hour"
60 onSelect={this.onItemChange} 73 onSelect={this.onItemChange}
@@ -64,11 +77,11 @@ const Combobox = React.createClass({
64 }, 77 },
65 78
66 getMinuteSelect(minute) { 79 getMinuteSelect(minute) {
67 const { prefixCls, minuteOptions } = this.props; 80 const { prefixCls, minuteOptions, disabledMinutes } = this.props;
68 return ( 81 return (
69 <Select 82 <Select
70 prefixCls={prefixCls} 83 prefixCls={prefixCls}
71 options={minuteOptions.map(option => formatOption(option))} 84 options={minuteOptions.map(option => formatOption(option, disabledMinutes))}
72 selectedIndex={minuteOptions.indexOf(minute)} 85 selectedIndex={minuteOptions.indexOf(minute)}
73 type="minute" 86 type="minute"
74 onSelect={this.onItemChange} 87 onSelect={this.onItemChange}
@@ -78,14 +91,14 @@ const Combobox = React.createClass({
78 }, 91 },
79 92
80 getSecondSelect(second) { 93 getSecondSelect(second) {
81 const { prefixCls, secondOptions, showSecond } = this.props; 94 const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props;
82 if (!showSecond) { 95 if (!showSecond) {
83 return null; 96 return null;
84 } 97 }
85 return ( 98 return (
86 <Select 99 <Select
87 prefixCls={prefixCls} 100 prefixCls={prefixCls}
88 options={secondOptions.map(option => formatOption(option))} 101 options={secondOptions.map(option => formatOption(option, disabledSeconds))}
89 selectedIndex={secondOptions.indexOf(second)} 102 selectedIndex={secondOptions.indexOf(second)}
90 type="second" 103 type="second"
91 onSelect={this.onItemChange} 104 onSelect={this.onItemChange}