aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/disabled.js
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-16 12:19:56 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-16 12:19:56 +0800
commit700c77e4f32e2ec18f3c63b176bf83bac24cdb74 (patch)
treedd7b0d090e946586dbc3bb5268a0a5b5619f81e4 /examples/disabled.js
parent182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff)
parentbec70d57f3ef17ed1ef29c660936be235804061e (diff)
downloadtime-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 'examples/disabled.js')
-rw-r--r--examples/disabled.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/disabled.js b/examples/disabled.js
new file mode 100644
index 0000000..633b8db
--- /dev/null
+++ b/examples/disabled.js
@@ -0,0 +1,66 @@
1/* eslint no-console:0 */
2
3import 'rc-time-picker/assets/index.less';
4
5import React from 'react';
6import ReactDom from 'react-dom';
7
8import GregorianCalendar from 'gregorian-calendar';
9import DateTimeFormat from 'gregorian-calendar-format';
10import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
11
12import TimePicker from 'rc-time-picker';
13import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN';
14
15const showSecond = true;
16const str = showSecond ? 'HH:mm:ss' : 'HH:mm';
17
18const formatter = new DateTimeFormat(str);
19
20const now = new GregorianCalendar(zhCn);
21now.setTime(Date.now());
22
23function 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
33function onChange(value) {
34 console.log(value && formatter.format(value));
35}
36
37function disabledHours() {
38 return [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23];
39}
40
41function 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
52function disabledSeconds(h, m) {
53 return [h + m % 60];
54}
55
56ReactDom.render(
57 <TimePicker formatter={formatter} locale={TimePickerLocale}
58 showSecond={showSecond}
59 defaultValue={now}
60 className="xxx"
61 onChange={onChange}
62 disabledHours={disabledHours}
63 disabledMinutes={disabledMinutes}
64 disabledSeconds={disabledSeconds} />,
65 document.getElementById('__react-content')
66);