From 518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 Mon Sep 17 00:00:00 2001 From: MG12 Date: Sat, 12 Dec 2015 20:34:00 +0800 Subject: add new options about disabled time --- examples/pick-time.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/pick-time.js b/examples/pick-time.js index dd5a2ce..074e72c 100644 --- a/examples/pick-time.js +++ b/examples/pick-time.js @@ -24,11 +24,27 @@ function onChange(value) { console.log(value && formatter.format(value)); } +const options = { + disabledHours() { + return [0, 2, 21]; + }, + disabledMinutes(h) { + return h === 22 ? [0, 3, 31] : []; + }, + disabledSeconds(h, m) { + return []; + }, +}; + ReactDom.render( , + onChange={onChange} + disabledHours={[0, 2, 21]} + disabledMinutes={[0, 2, 21]} + disabledSeconds={[]} + hideDisabledOptions={true} />, document.getElementById('__react-content') ); -- cgit v1.2.3 From 0e62bf0b7bdc260e882fd185492939cbaed04d56 Mon Sep 17 00:00:00 2001 From: MG12 Date: Sun, 13 Dec 2015 00:03:19 +0800 Subject: update test case and fix bugs --- examples/disabled.html | 1 + examples/disabled.js | 36 ++++++++++++++++++++++++++++++++++++ examples/hidden.html | 1 + examples/hidden.js | 37 +++++++++++++++++++++++++++++++++++++ examples/pick-time.js | 18 +----------------- 5 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 examples/disabled.html create mode 100644 examples/disabled.js create mode 100644 examples/hidden.html create mode 100644 examples/hidden.js (limited to 'examples') diff --git a/examples/disabled.html b/examples/disabled.html new file mode 100644 index 0000000..48cdce8 --- /dev/null +++ b/examples/disabled.html @@ -0,0 +1 @@ +placeholder diff --git a/examples/disabled.js b/examples/disabled.js new file mode 100644 index 0000000..24d0068 --- /dev/null +++ b/examples/disabled.js @@ -0,0 +1,36 @@ +/* eslint no-console:0 */ + +import 'rc-time-picker/assets/index.less'; + +import React from 'react'; +import ReactDom from 'react-dom'; + +import GregorianCalendar from 'gregorian-calendar'; +import DateTimeFormat from 'gregorian-calendar-format'; +import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; + +import TimePicker from 'rc-time-picker'; +import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN'; + +const showSecond = true; +const str = showSecond ? 'HH:mm:ss' : 'HH:mm'; + +const formatter = new DateTimeFormat(str); + +const now = new GregorianCalendar(zhCn); +now.setTime(Date.now()); + +function onChange(value) { + console.log(value && formatter.format(value)); +} + +ReactDom.render( + , + document.getElementById('__react-content') +); diff --git a/examples/hidden.html b/examples/hidden.html new file mode 100644 index 0000000..48cdce8 --- /dev/null +++ b/examples/hidden.html @@ -0,0 +1 @@ +placeholder diff --git a/examples/hidden.js b/examples/hidden.js new file mode 100644 index 0000000..1084236 --- /dev/null +++ b/examples/hidden.js @@ -0,0 +1,37 @@ +/* eslint no-console:0 */ + +import 'rc-time-picker/assets/index.less'; + +import React from 'react'; +import ReactDom from 'react-dom'; + +import GregorianCalendar from 'gregorian-calendar'; +import DateTimeFormat from 'gregorian-calendar-format'; +import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; + +import TimePicker from 'rc-time-picker'; +import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN'; + +const showSecond = true; +const str = showSecond ? 'HH:mm:ss' : 'HH:mm'; + +const formatter = new DateTimeFormat(str); + +const now = new GregorianCalendar(zhCn); +now.setTime(Date.now()); + +function onChange(value) { + console.log(value && formatter.format(value)); +} + +ReactDom.render( + , + document.getElementById('__react-content') +); diff --git a/examples/pick-time.js b/examples/pick-time.js index 074e72c..f66e416 100644 --- a/examples/pick-time.js +++ b/examples/pick-time.js @@ -24,27 +24,11 @@ function onChange(value) { console.log(value && formatter.format(value)); } -const options = { - disabledHours() { - return [0, 2, 21]; - }, - disabledMinutes(h) { - return h === 22 ? [0, 3, 31] : []; - }, - disabledSeconds(h, m) { - return []; - }, -}; - ReactDom.render( , + onChange={onChange} />, document.getElementById('__react-content') ); -- cgit v1.2.3 From 71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 Mon Sep 17 00:00:00 2001 From: MG12 Date: Mon, 14 Dec 2015 00:50:41 +0800 Subject: update disabled options --- examples/disabled.js | 34 ++++++++++++++++++++++++++++++++-- examples/hidden.js | 6 +++--- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'examples') 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); const now = new GregorianCalendar(zhCn); now.setTime(Date.now()); +function generateOptions(length, excludedOptions) { + const arr = []; + for (let value = 0; value < length; value++) { + if (excludedOptions.indexOf(value) < 0) { + arr.push(value); + } + } + return arr; +} + function onChange(value) { console.log(value && formatter.format(value)); } +function disabledHours() { + return [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]; +} + +function disabledMinutes(h) { + switch (h) { + case 9: + return generateOptions(60, [30]); + case 21: + return generateOptions(60, [0]); + default: + return generateOptions(60, [0, 30]); + } +} + +function disabledSeconds(h, m) { + return [h + m % 60]; +} + ReactDom.render( , + disabledHours={disabledHours} + disabledMinutes={disabledMinutes} + disabledSeconds={disabledSeconds} />, document.getElementById('__react-content') ); 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( defaultValue={now} className="xxx" onChange={onChange} - disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} - disabledMinutes={[0, 2, 4, 6, 8]} - hideDisabledOptions={true} />, + disabledHours={() => [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} + disabledMinutes={() => [0, 2, 4, 6, 8]} + hideDisabledOptions />, document.getElementById('__react-content') ); -- cgit v1.2.3