2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2017-03-17 15:23:25 +08:00
|
|
|
import Tooltip, { AbstractTooltipProps } from '../tooltip';
|
2015-11-20 11:05:34 +08:00
|
|
|
import Icon from '../icon';
|
2015-11-03 20:06:44 +08:00
|
|
|
import Button from '../button';
|
2017-03-17 15:23:25 +08:00
|
|
|
import injectLocale from '../locale-provider/injectLocale';
|
2015-11-24 11:21:37 +08:00
|
|
|
|
2016-11-30 16:43:35 +08:00
|
|
|
export interface PopconfirmProps extends AbstractTooltipProps {
|
|
|
|
title: React.ReactNode;
|
2017-02-24 16:07:39 +08:00
|
|
|
onConfirm?: (e: React.MouseEvent<any>) => void;
|
|
|
|
onCancel?: (e: React.MouseEvent<any>) => void;
|
2016-07-25 11:28:43 +08:00
|
|
|
okText?: React.ReactNode;
|
|
|
|
cancelText?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
abstract class Popconfirm extends React.Component<PopconfirmProps, any> {
|
2016-03-29 17:33:37 +08:00
|
|
|
static defaultProps = {
|
2016-08-31 13:50:50 +08:00
|
|
|
prefixCls: 'ant-popover',
|
2016-04-07 15:02:22 +08:00
|
|
|
transitionName: 'zoom-big',
|
2016-03-29 17:33:37 +08:00
|
|
|
placement: 'top',
|
|
|
|
trigger: 'click',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 17:33:37 +08:00
|
|
|
|
2016-11-30 15:46:50 +08:00
|
|
|
constructor(props: PopconfirmProps) {
|
2016-03-29 17:33:37 +08:00
|
|
|
super(props);
|
2016-11-30 15:46:50 +08:00
|
|
|
|
2016-03-29 17:33:37 +08:00
|
|
|
this.state = {
|
2016-11-30 15:46:50 +08:00
|
|
|
visible: props.visible,
|
2015-06-24 19:20:47 +08:00
|
|
|
};
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2017-05-25 16:54:15 +08:00
|
|
|
abstract getLocale();
|
2017-03-17 15:23:25 +08:00
|
|
|
|
2016-11-30 16:43:35 +08:00
|
|
|
componentWillReceiveProps(nextProps: PopconfirmProps) {
|
2015-12-04 14:58:19 +08:00
|
|
|
if ('visible' in nextProps) {
|
|
|
|
this.setState({ visible: nextProps.visible });
|
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
onConfirm = (e) => {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setVisible(false);
|
2016-10-24 12:04:26 +08:00
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
const { onConfirm } = this.props;
|
2016-10-24 12:04:26 +08:00
|
|
|
if (onConfirm) {
|
2017-02-24 16:07:39 +08:00
|
|
|
onConfirm.call(this, e);
|
2016-10-24 12:04:26 +08:00
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
onCancel = (e) => {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setVisible(false);
|
2016-10-24 12:04:26 +08:00
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
const { onCancel } = this.props;
|
2016-10-24 12:04:26 +08:00
|
|
|
if (onCancel) {
|
2017-02-24 16:07:39 +08:00
|
|
|
onCancel.call(this, e);
|
2016-10-24 12:04:26 +08:00
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onVisibleChange = (visible) => {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setVisible(visible);
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2015-12-04 14:58:19 +08:00
|
|
|
setVisible(visible) {
|
2016-11-30 15:46:50 +08:00
|
|
|
const props = this.props;
|
|
|
|
if (!('visible' in props)) {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setState({ visible });
|
|
|
|
}
|
2016-10-24 12:04:26 +08:00
|
|
|
|
2017-03-17 15:23:25 +08:00
|
|
|
const { onVisibleChange } = props;
|
2016-10-24 12:04:26 +08:00
|
|
|
if (onVisibleChange) {
|
|
|
|
onVisibleChange(visible);
|
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 19:20:47 +08:00
|
|
|
render() {
|
2017-03-17 15:23:25 +08:00
|
|
|
const { prefixCls, title, placement, okText, cancelText, ...restProps } = this.props;
|
|
|
|
const popconfirmLocale = this.getLocale();
|
2016-11-30 15:46:50 +08:00
|
|
|
|
2016-01-07 14:21:29 +08:00
|
|
|
const overlay = (
|
|
|
|
<div>
|
2016-03-17 15:10:49 +08:00
|
|
|
<div className={`${prefixCls}-inner-content`}>
|
2016-03-10 16:22:52 +08:00
|
|
|
<div className={`${prefixCls}-message`}>
|
2016-04-16 17:38:30 +08:00
|
|
|
<Icon type="exclamation-circle" />
|
2016-03-10 16:22:52 +08:00
|
|
|
<div className={`${prefixCls}-message-title`}>{title}</div>
|
|
|
|
</div>
|
2016-02-17 18:04:42 +08:00
|
|
|
<div className={`${prefixCls}-buttons`}>
|
2017-03-17 15:23:25 +08:00
|
|
|
<Button onClick={this.onCancel} size="small">
|
|
|
|
{cancelText || popconfirmLocale.cancelText}
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.onConfirm} type="primary" size="small">
|
|
|
|
{okText || popconfirmLocale.okText}
|
|
|
|
</Button>
|
2016-01-07 14:21:29 +08:00
|
|
|
</div>
|
2015-06-24 19:20:47 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2015-06-24 19:20:47 +08:00
|
|
|
|
|
|
|
return (
|
2016-08-31 13:50:50 +08:00
|
|
|
<Tooltip
|
|
|
|
{...restProps}
|
2016-01-07 17:46:46 +08:00
|
|
|
prefixCls={prefixCls}
|
2016-08-31 13:50:50 +08:00
|
|
|
placement={placement}
|
2016-01-07 17:46:46 +08:00
|
|
|
onVisibleChange={this.onVisibleChange}
|
|
|
|
visible={this.state.visible}
|
2016-06-06 13:54:10 +08:00
|
|
|
overlay={overlay}
|
2016-08-31 13:50:50 +08:00
|
|
|
/>
|
2015-06-24 19:20:47 +08:00
|
|
|
);
|
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
2017-03-17 15:23:25 +08:00
|
|
|
|
|
|
|
const injectPopconfirmLocale = injectLocale('Popconfirm', {
|
|
|
|
cancelText: '取消',
|
|
|
|
okText: '确定',
|
|
|
|
});
|
|
|
|
export default injectPopconfirmLocale<PopconfirmProps>(Popconfirm as any);
|