|
|
|
import * as React from 'react';
|
|
|
|
import Tooltip, { AbstractTooltipProps } from '../tooltip';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import Button from '../button';
|
|
|
|
import { ButtonType } from '../button/button';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import defaultLocale from '../locale-provider/default';
|
|
|
|
|
|
|
|
export interface PopconfirmProps extends AbstractTooltipProps {
|
|
|
|
title: React.ReactNode;
|
|
|
|
onConfirm?: (e: React.MouseEvent<any>) => void;
|
|
|
|
onCancel?: (e: React.MouseEvent<any>) => void;
|
|
|
|
okText?: React.ReactNode;
|
|
|
|
okType?: ButtonType;
|
|
|
|
cancelText?: React.ReactNode;
|
|
|
|
icon?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PopconfirmState {
|
|
|
|
visible?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PopconfirmLocale {
|
|
|
|
okText: string;
|
|
|
|
cancelText: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Popconfirm extends React.Component<PopconfirmProps, PopconfirmState> {
|
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-popover',
|
|
|
|
transitionName: 'zoom-big',
|
|
|
|
placement: 'top',
|
|
|
|
trigger: 'click',
|
|
|
|
okType: 'primary',
|
|
|
|
icon: <Icon type="exclamation-circle" />,
|
|
|
|
};
|
|
|
|
|
|
|
|
private tooltip: any;
|
|
|
|
|
|
|
|
constructor(props: PopconfirmProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
visible: props.visible,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps: PopconfirmProps) {
|
|
|
|
if ('visible' in nextProps) {
|
|
|
|
this.setState({ visible: nextProps.visible });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getPopupDomNode() {
|
|
|
|
return this.tooltip.getPopupDomNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
onConfirm = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
this.setVisible(false);
|
|
|
|
|
|
|
|
const { onConfirm } = this.props;
|
|
|
|
if (onConfirm) {
|
|
|
|
onConfirm.call(this, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onCancel = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
this.setVisible(false);
|
|
|
|
|
|
|
|
const { onCancel } = this.props;
|
|
|
|
if (onCancel) {
|
|
|
|
onCancel.call(this, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onVisibleChange = (visible: boolean) => {
|
|
|
|
this.setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
setVisible(visible: boolean) {
|
|
|
|
const props = this.props;
|
|
|
|
if (!('visible' in props)) {
|
|
|
|
this.setState({ visible });
|
|
|
|
}
|
|
|
|
|
|
|
|
const { onVisibleChange } = props;
|
|
|
|
if (onVisibleChange) {
|
|
|
|
onVisibleChange(visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveTooltip = (node: any) => {
|
|
|