From 8df1da99d982c20da953a4c75977049a14149cc3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 17 Dec 2015 16:12:17 +0800 Subject: [PATCH] update demos --- .../time-picker/demo/disable-options.md | 30 +++++++++++++------ components/time-picker/demo/hide-options.md | 20 ++++++++----- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/components/time-picker/demo/disable-options.md b/components/time-picker/demo/disable-options.md index eb783c1f2d..a2d0f63655 100644 --- a/components/time-picker/demo/disable-options.md +++ b/components/time-picker/demo/disable-options.md @@ -1,27 +1,39 @@ # 禁止选项 -- order: 5 +- order: 5 -禁止部分选项。 +限制选择 `20:30` 到 `23:30` 这个时间段。 --- ````jsx import { TimePicker } from 'antd'; +function newArray(start, end) { + let result = []; + for (let i = start; i < end; i++) { + result.push(i); + } + return result; +} + function disabledHours() { - return [0, 4, 8, 12, 16, 20]; + let hours = newArray(0, 60); + hours.splice(20, 4); + return hours; } function disabledMinutes(h) { - return [h % 60]; -} - -function disabledSeconds(h, m) { - return [h + m % 60]; + if (h === 20) { + return newArray(0, 31); + } else if (h === 23) { + return newArray(30, 60); + } else { + return []; + } } ReactDOM.render( - + , document.getElementById('components-time-picker-demo-disable-options')); ```` diff --git a/components/time-picker/demo/hide-options.md b/components/time-picker/demo/hide-options.md index 5245e69164..1041281a1a 100644 --- a/components/time-picker/demo/hide-options.md +++ b/components/time-picker/demo/hide-options.md @@ -1,27 +1,31 @@ -# 隐藏选项 +# 只显示部分选项 -- order: 6 +- order: 6 -禁止部分选项。 +通过 `hideDisabledOptions` 将不可选的选项隐藏。 --- ````jsx import { TimePicker } from 'antd'; -function disabledHours() { - return [0, 4, 8, 12, 16, 20]; +function newArray(start, end) { + let result = []; + for (let i = start; i < end; i++) { + result.push(i); + } + return result; } function disabledMinutes(h) { - return [h % 60]; + return newArray(0, 60).filter(value => value % 10 !== 0); } function disabledSeconds(h, m) { - return [h + m % 60]; + return newArray(0, 60).filter(value => value % 30 !== 0); } ReactDOM.render( - + , document.getElementById('components-time-picker-demo-hide-options')); ````