import React from 'react'; import Tooltip from '../tooltip'; import { AbstractTooltipProps } from '../tooltip'; import Icon from '../icon'; import Button from '../button'; export interface PopconfirmProps extends AbstractTooltipProps { title: React.ReactNode; onConfirm?: (e: React.MouseEvent) => void; onCancel?: (e: React.MouseEvent) => void; okText?: React.ReactNode; cancelText?: React.ReactNode; } export interface PopconfirmContext { antLocale?: { Popconfirm?: any, }; } export default class Popconfirm extends React.Component { static defaultProps = { prefixCls: 'ant-popover', transitionName: 'zoom-big', placement: 'top', trigger: 'click', }; static contextTypes = { antLocale: React.PropTypes.object, }; context: PopconfirmContext; constructor(props: PopconfirmProps) { super(props); this.state = { visible: props.visible, }; } componentWillReceiveProps(nextProps: PopconfirmProps) { if ('visible' in nextProps) { this.setState({ visible: nextProps.visible }); } } confirm = (e) => { this.setVisible(false); const onConfirm = this.props.onConfirm; if (onConfirm) { onConfirm.call(this, e); } } cancel = (e) => { this.setVisible(false); const onCancel = this.props.onCancel; if (onCancel) { onCancel.call(this, e); } } onVisibleChange = (visible) => { this.setVisible(visible); } setVisible(visible) { const props = this.props; if (!('visible' in props)) { this.setState({ visible }); } const onVisibleChange = props.onVisibleChange; if (onVisibleChange) { onVisibleChange(visible); } } render() { const { props, context } = this; const { prefixCls, title, placement, ...restProps } = props; let { okText, cancelText } = props; const popconfirmLocale = context.antLocale && context.antLocale.Popconfirm; if (popconfirmLocale) { okText = okText || popconfirmLocale.okText; cancelText = cancelText || popconfirmLocale.cancelText; } const overlay = (
{title}
); return ( ); } }