From d48c2084d569c1e2fee7da70f28fa951b9efd84f Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 28 Apr 2017 09:40:20 +0800 Subject: [PATCH] feat: expose TimePicker[open], close: #5775 & #5829 (#5913) --- components/time-picker/demo/addon.md | 34 ++++++++++++++++++++------- components/time-picker/index.en-US.md | 2 ++ components/time-picker/index.tsx | 11 +++++++++ components/time-picker/index.zh-CN.md | 2 ++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/components/time-picker/demo/addon.md b/components/time-picker/demo/addon.md index 40c53512c3..7c2a557d2d 100644 --- a/components/time-picker/demo/addon.md +++ b/components/time-picker/demo/addon.md @@ -16,13 +16,29 @@ Render addon contents to timepicker panel's bottom. ````jsx import { TimePicker, Button } from 'antd'; -ReactDOM.render( - ( - - )} - /> -, mountNode); +class TimePickerAddonDemo extends React.Component { + state = { open: false }; + + handleOpenChange = (open) => { + this.setState({ open }); + } + + handleClose = () => this.setState({ open: false }) + + render() { + return ( + ( + + )} + /> + ); + } +} + +ReactDOM.render(, mountNode); ```` diff --git a/components/time-picker/index.en-US.md b/components/time-picker/index.en-US.md index f437ef933c..6030d747a0 100644 --- a/components/time-picker/index.en-US.md +++ b/components/time-picker/index.en-US.md @@ -25,6 +25,8 @@ import moment from 'moment'; |---------------------|-----|-----|-------| | defaultValue | to set default time | [moment](http://momentjs.com/) | - | | value | to set time | [moment](http://momentjs.com/) | - | +| open | whether to popup panel | boolean | false | +| onOpenChange | a callback function which will be called while panel opening/closing | (status: boolean): void | 无 | | placeholder | display when there's no value | string | "Select a time" | | onChange | a callback function, can be executed when the selected time is changing | function(time: moment, timeString: string): void | - | | format | to set the time format | string | "HH:mm:ss" | diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx index 637271b01d..ff643b71ed 100644 --- a/components/time-picker/index.tsx +++ b/components/time-picker/index.tsx @@ -11,8 +11,10 @@ export interface TimePickerProps { size?: 'large' | 'default' | 'small'; value?: moment.Moment; defaultValue?: moment.Moment; + open?: boolean; format?: string; onChange?: (time: moment.Moment, timeString: string) => void; + onOpenChange?: (status: boolean) => void; disabled?: boolean; placeholder?: string; hideDisabledOptions?: boolean; @@ -74,6 +76,13 @@ abstract class TimePicker extends React.Component { } } + handleOpenClose = ({ open }) => { + const { onOpenChange } = this.props; + if (onOpenChange) { + onOpenChange(open); + } + } + saveTimePicker = (timePickerRef) => { this.timePickerRef = timePickerRef; } @@ -121,6 +130,8 @@ abstract class TimePicker extends React.Component { showMinute={format.indexOf('mm') > -1} showSecond={format.indexOf('ss') > -1} onChange={this.handleChange} + onOpen={this.handleOpenClose} + onClose={this.handleOpenClose} addon={addon} /> ); diff --git a/components/time-picker/index.zh-CN.md b/components/time-picker/index.zh-CN.md index 594709a92b..8a1a00b4ef 100644 --- a/components/time-picker/index.zh-CN.md +++ b/components/time-picker/index.zh-CN.md @@ -26,6 +26,8 @@ import moment from 'moment'; |---------------------|-----|-----|-------| | defaultValue | 默认时间 | [moment](http://momentjs.com/) | 无 | | value | 当前时间 | [moment](http://momentjs.com/) | 无 | +| open | 面板是否打开 | boolean | false | +| onOpenChange | 面板打开/关闭时的回调 | (open: boolean): void | 无 | | placeholder | 没有值的时候显示的内容 | string | "请选择时间" | | onChange | 时间发生变化的回调 | function(time: moment, timeString: string): void | 无 | | format | 展示的时间格式 | string | "HH:mm:ss" |