diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/disabled.js | 34 | ||||
-rw-r--r-- | examples/hidden.js | 6 |
2 files changed, 35 insertions, 5 deletions
diff --git a/examples/disabled.js b/examples/disabled.js index 24d0068..633b8db 100644 --- a/examples/disabled.js +++ b/examples/disabled.js | |||
@@ -20,17 +20,47 @@ const formatter = new DateTimeFormat(str); | |||
20 | const now = new GregorianCalendar(zhCn); | 20 | const now = new GregorianCalendar(zhCn); |
21 | now.setTime(Date.now()); | 21 | now.setTime(Date.now()); |
22 | 22 | ||
23 | function generateOptions(length, excludedOptions) { | ||
24 | const arr = []; | ||
25 | for (let value = 0; value < length; value++) { | ||
26 | if (excludedOptions.indexOf(value) < 0) { | ||
27 | arr.push(value); | ||
28 | } | ||
29 | } | ||
30 | return arr; | ||
31 | } | ||
32 | |||
23 | function onChange(value) { | 33 | function onChange(value) { |
24 | console.log(value && formatter.format(value)); | 34 | console.log(value && formatter.format(value)); |
25 | } | 35 | } |
26 | 36 | ||
37 | function disabledHours() { | ||
38 | return [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]; | ||
39 | } | ||
40 | |||
41 | function disabledMinutes(h) { | ||
42 | switch (h) { | ||
43 | case 9: | ||
44 | return generateOptions(60, [30]); | ||
45 | case 21: | ||
46 | return generateOptions(60, [0]); | ||
47 | default: | ||
48 | return generateOptions(60, [0, 30]); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | function disabledSeconds(h, m) { | ||
53 | return [h + m % 60]; | ||
54 | } | ||
55 | |||
27 | ReactDom.render( | 56 | ReactDom.render( |
28 | <TimePicker formatter={formatter} locale={TimePickerLocale} | 57 | <TimePicker formatter={formatter} locale={TimePickerLocale} |
29 | showSecond={showSecond} | 58 | showSecond={showSecond} |
30 | defaultValue={now} | 59 | defaultValue={now} |
31 | className="xxx" | 60 | className="xxx" |
32 | onChange={onChange} | 61 | onChange={onChange} |
33 | disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} | 62 | disabledHours={disabledHours} |
34 | disabledMinutes={[0, 2, 4, 6, 8]} />, | 63 | disabledMinutes={disabledMinutes} |
64 | disabledSeconds={disabledSeconds} />, | ||
35 | document.getElementById('__react-content') | 65 | document.getElementById('__react-content') |
36 | ); | 66 | ); |
diff --git a/examples/hidden.js b/examples/hidden.js index 1084236..da366cc 100644 --- a/examples/hidden.js +++ b/examples/hidden.js | |||
@@ -30,8 +30,8 @@ ReactDom.render( | |||
30 | defaultValue={now} | 30 | defaultValue={now} |
31 | className="xxx" | 31 | className="xxx" |
32 | onChange={onChange} | 32 | onChange={onChange} |
33 | disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} | 33 | disabledHours={() => [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} |
34 | disabledMinutes={[0, 2, 4, 6, 8]} | 34 | disabledMinutes={() => [0, 2, 4, 6, 8]} |
35 | hideDisabledOptions={true} />, | 35 | hideDisabledOptions />, |
36 | document.getElementById('__react-content') | 36 | document.getElementById('__react-content') |
37 | ); | 37 | ); |