diff options
author | MG12 <wuzhao.mail@gmail.com> | 2015-12-16 12:19:56 +0800 |
---|---|---|
committer | MG12 <wuzhao.mail@gmail.com> | 2015-12-16 12:19:56 +0800 |
commit | 700c77e4f32e2ec18f3c63b176bf83bac24cdb74 (patch) | |
tree | dd7b0d090e946586dbc3bb5268a0a5b5619f81e4 /src/module/Combobox.jsx | |
parent | 182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff) | |
parent | bec70d57f3ef17ed1ef29c660936be235804061e (diff) | |
download | time-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.tar.gz time-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.tar.zst time-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.zip |
Merge pull request #10 from react-component/1.0.0-alpha7
1.0.0 alpha7
Diffstat (limited to 'src/module/Combobox.jsx')
-rw-r--r-- | src/module/Combobox.jsx | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx index a017ec9..7374b39 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 && 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.func, | ||
35 | disabledMinutes: PropTypes.func, | ||
36 | disabledSeconds: PropTypes.func, | ||
24 | onCurrentSelectPanelChange: PropTypes.func, | 37 | onCurrentSelectPanelChange: PropTypes.func, |
25 | }, | 38 | }, |
26 | 39 | ||
@@ -47,14 +60,16 @@ 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 | } |
67 | const disabledOptions = disabledHours(); | ||
68 | |||
54 | return ( | 69 | return ( |
55 | <Select | 70 | <Select |
56 | prefixCls={prefixCls} | 71 | prefixCls={prefixCls} |
57 | options={hourOptions.map(option => formatOption(option))} | 72 | options={hourOptions.map(option => formatOption(option, disabledOptions))} |
58 | selectedIndex={hourOptions.indexOf(hour)} | 73 | selectedIndex={hourOptions.indexOf(hour)} |
59 | type="hour" | 74 | type="hour" |
60 | onSelect={this.onItemChange} | 75 | onSelect={this.onItemChange} |
@@ -64,11 +79,13 @@ const Combobox = React.createClass({ | |||
64 | }, | 79 | }, |
65 | 80 | ||
66 | getMinuteSelect(minute) { | 81 | getMinuteSelect(minute) { |
67 | const { prefixCls, minuteOptions } = this.props; | 82 | const { prefixCls, minuteOptions, disabledMinutes, value } = this.props; |
83 | const disabledOptions = disabledMinutes(value.getHourOfDay()); | ||
84 | |||
68 | return ( | 85 | return ( |
69 | <Select | 86 | <Select |
70 | prefixCls={prefixCls} | 87 | prefixCls={prefixCls} |
71 | options={minuteOptions.map(option => formatOption(option))} | 88 | options={minuteOptions.map(option => formatOption(option, disabledOptions))} |
72 | selectedIndex={minuteOptions.indexOf(minute)} | 89 | selectedIndex={minuteOptions.indexOf(minute)} |
73 | type="minute" | 90 | type="minute" |
74 | onSelect={this.onItemChange} | 91 | onSelect={this.onItemChange} |
@@ -78,14 +95,16 @@ const Combobox = React.createClass({ | |||
78 | }, | 95 | }, |
79 | 96 | ||
80 | getSecondSelect(second) { | 97 | getSecondSelect(second) { |
81 | const { prefixCls, secondOptions, showSecond } = this.props; | 98 | const { prefixCls, secondOptions, disabledSeconds, showSecond, value } = this.props; |
82 | if (!showSecond) { | 99 | if (!showSecond) { |
83 | return null; | 100 | return null; |
84 | } | 101 | } |
102 | const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); | ||
103 | |||
85 | return ( | 104 | return ( |
86 | <Select | 105 | <Select |
87 | prefixCls={prefixCls} | 106 | prefixCls={prefixCls} |
88 | options={secondOptions.map(option => formatOption(option))} | 107 | options={secondOptions.map(option => formatOption(option, disabledOptions))} |
89 | selectedIndex={secondOptions.indexOf(second)} | 108 | selectedIndex={secondOptions.indexOf(second)} |
90 | type="second" | 109 | type="second" |
91 | onSelect={this.onItemChange} | 110 | onSelect={this.onItemChange} |