Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose TimePicker[open], close: #5775 & #5829 #5913

Merged
merged 1 commit into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions components/time-picker/demo/addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ Render addon contents to timepicker panel's bottom.
````jsx
import { TimePicker, Button } from 'antd';

ReactDOM.render(
<TimePicker
addon={panel => (
<Button size="small" type="primary" onClick={() => panel.close()}>
Ok
</Button>
)}
/>
, mountNode);
class TimePickerAddonDemo extends React.Component {
state = { open: false };

handleOpenChange = (open) => {
this.setState({ open });
}

handleClose = () => this.setState({ open: false })

render() {
return (
<TimePicker
open={this.state.open}
onOpenChange={this.handleOpenChange}
addon={() => (
<Button size="small" type="primary" onClick={this.handleClose}>
Ok
</Button>
)}
/>
);
}
}

ReactDOM.render(<TimePickerAddonDemo />, mountNode);
````
2 changes: 2 additions & 0 deletions components/time-picker/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | 无 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无 => -

| 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" |
Expand Down
11 changes: 11 additions & 0 deletions components/time-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status => open

disabled?: boolean;
placeholder?: string;
hideDisabledOptions?: boolean;
Expand Down Expand Up @@ -74,6 +76,13 @@ abstract class TimePicker extends React.Component<TimePickerProps, any> {
}
}

handleOpenClose = ({ open }) => {
const { onOpenChange } = this.props;
if (onOpenChange) {
onOpenChange(open);
}
}

saveTimePicker = (timePickerRef) => {
this.timePickerRef = timePickerRef;
}
Expand Down Expand Up @@ -121,6 +130,8 @@ abstract class TimePicker extends React.Component<TimePickerProps, any> {
showMinute={format.indexOf('mm') > -1}
showSecond={format.indexOf('ss') > -1}
onChange={this.handleChange}
onOpen={this.handleOpenClose}
onClose={this.handleOpenClose}
addon={addon}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions components/time-picker/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" |
Expand Down