feat: RangePicker disabledTime (#3568)

* RangePicker disabledTime

* update API document of RangePicker
This commit is contained in:
陆离 2016-10-25 17:39:17 +08:00 committed by Benjy Cui
parent a3388aa840
commit d051d94af4
5 changed files with 51 additions and 5 deletions

View File

@ -45,7 +45,7 @@ export default class RangePicker extends React.Component<any, any> {
render() {
const props = this.props;
const { disabledDate, showTime, prefixCls, popupStyle, style, onOk, locale } = props;
const { disabledDate, disabledTime, showTime, prefixCls, popupStyle, style, onOk, locale } = props;
const state = this.state;
const calendarClassName = classNames({
@ -77,6 +77,7 @@ export default class RangePicker extends React.Component<any, any> {
className={calendarClassName}
timePicker={props.timePicker}
disabledDate={disabledDate}
disabledTime={disabledTime}
dateInputPlaceholder={[startPlaceholder, endPlaceholder]}
locale={locale.lang}
onOk={onOk}

View File

@ -8,6 +8,7 @@ title:
## zh-CN
设置 `disabledDate` 方法,来确定不可选时段。
设置 `disabledTime` 方法,来确定 showTime 的 RangePicker 的不可选时间段。
如上例:不可选择今天之后的日期。
@ -19,13 +20,54 @@ As in the example above: you can't select a date later than today.
````jsx
import { DatePicker } from 'antd';
const RangePicker = DatePicker.RangePicker;
function newArray(start, end) {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
}
const disabledDate = function (current) {
// can not select days after today
return current && current.valueOf() > Date.now();
};
ReactDOM.render(
<DatePicker disabledDate={disabledDate} />
function disabledTime(time, type) {
console.log('disabledTime', time, type);
if (type === 'start') {
return {
disabledHours() {
return newArray(0, 60).splice(4, 20);
},
disabledMinutes() {
return newArray(30, 60);
},
disabledSeconds() {
return [55, 56];
},
};
}
return {
disabledHours() {
return newArray(0, 60).splice(20, 4);
},
disabledMinutes() {
return newArray(0, 31);
},
disabledSeconds() {
return [55, 56];
},
};
}
ReactDOM.render(<div>
<DatePicker disabledDate={disabledDate} />
<br />
<RangePicker showTime disabledDate={disabledDate} disabledTime={disabledTime} />
</div>
, mountNode);
````

View File

@ -70,6 +70,8 @@ moment.tz.setDefault('Asia/Shanghai')
| format | to set the date format | String | "YYYY-MM-DD HH:mm:ss" |
| onChange | a callback function, can be executed when the selected time is changing | function(dates: [moment, moment], dateStrings: [string, string]) | - |
| showTime | to provide an additional time selection | Object/Boolean | [TimePicker Options](/components/time-picker/#api) |
| disabledDate | to specify the date that cannot be selected | function(date: moment, dateString: string) | - |
| disabledTime | to specify the time that cannot be selected | function(dates: [moment, moment], partial: 'start'|'end') | - |
The following properties are the same with `DatePicker`: `disabled` `style` `popupStyle` `size` `locale` `showTime` `onOk` `getCalendarContainer`

View File

@ -70,7 +70,8 @@ moment.tz.setDefault('Asia/Shanghai')
| format | 展示的日期格式 | string | "YYYY-MM-DD HH:mm:ss" |
| onChange | 时间发生变化的回调,发生在用户选择时间时 | function(dates: [moment, moment], dateStrings: [string, string]) | 无 |
| showTime | 增加时间选择功能 | Object or Boolean | [TimePicker Options](/components/time-picker/#api) |
| disabledDate | 不可选择的日期 | function | 无 |
| disabledTime | 不可选择的时间 | function(dates: [moment, moment], partial: 'start'|'end') | 无 |
`disabled` `style` `popupStyle` `size` `locale` `showTime` `onOk` `getCalendarContainer` 属性与 DatePicker 的一致。
<style>

View File

@ -43,7 +43,7 @@
"object-assign": "~4.1.0",
"omit.js": "^0.1.0",
"rc-animate": "~2.3.0",
"rc-calendar": "~7.2.0",
"rc-calendar": "~7.3.1",
"rc-cascader": "~0.10.1",
"rc-checkbox": "~1.4.0",
"rc-collapse": "~1.6.4",