diff options
Diffstat (limited to 'src/module/Combobox.jsx')
-rw-r--r-- | src/module/Combobox.jsx | 31 |
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'; | |||
2 | import Select from './Select'; | 2 | import Select from './Select'; |
3 | import GregorianCalendar from 'gregorian-calendar'; | 3 | import GregorianCalendar from 'gregorian-calendar'; |
4 | 4 | ||
5 | const formatOption = (option) => { | 5 | const 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 | ||
12 | const Combobox = React.createClass({ | 22 | const 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} |