2016-07-07 20:25:03 +08:00
|
|
|
import * as React from 'react';
|
2016-04-07 15:02:22 +08:00
|
|
|
import Tooltip 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';
|
2016-03-09 17:23:10 +08:00
|
|
|
import getPlacements from '../popover/placements';
|
2016-06-22 13:18:43 +08:00
|
|
|
import splitObject from '../_util/splitObject';
|
2015-11-24 11:21:37 +08:00
|
|
|
|
2016-04-07 16:43:00 +08:00
|
|
|
const noop = () => {};
|
2015-06-24 19:20:47 +08:00
|
|
|
|
2016-07-25 11:28:43 +08:00
|
|
|
export interface PopconfirmProps {
|
|
|
|
/**
|
|
|
|
* Position of popup-container, options:`top`, `left`, `right`, `bottom`
|
|
|
|
*/
|
|
|
|
placement?: 'top' | 'left' | 'right' | 'bottom';
|
|
|
|
/** Description of Popconfirm */
|
|
|
|
title: React.ReactNode;
|
|
|
|
/** Callback when confirm */
|
|
|
|
onConfirm?: () => void;
|
|
|
|
/** Callback when cancel */
|
|
|
|
onCancel?: () => void;
|
|
|
|
/** Callback when display/hide */
|
|
|
|
onVisibleChange?: (visible: boolean) => void;
|
|
|
|
/** Confirm button text */
|
|
|
|
okText?: React.ReactNode;
|
|
|
|
/** Cancel button text */
|
|
|
|
cancelText?: React.ReactNode;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
transitionName?: string;
|
|
|
|
trigger?: 'hover' | 'focus' | 'click';
|
|
|
|
/** Style of overlay */
|
|
|
|
overlayStyle?: React.CSSProperties;
|
|
|
|
prefixCls?: string;
|
|
|
|
}
|
|
|
|
|
2016-07-25 11:35:51 +08:00
|
|
|
export interface PopconfirmContext {
|
|
|
|
antLocale?: {
|
|
|
|
Popconfirm?: any,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-25 11:28:43 +08:00
|
|
|
export default 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',
|
|
|
|
onConfirm: noop,
|
|
|
|
onCancel: noop,
|
2016-04-07 16:43:00 +08:00
|
|
|
onVisibleChange: noop,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 17:33:37 +08:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
antLocale: React.PropTypes.object,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 17:33:37 +08:00
|
|
|
|
2016-07-25 11:39:54 +08:00
|
|
|
context: PopconfirmContext;
|
|
|
|
|
2016-03-29 17:33:37 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2016-05-11 09:32:33 +08:00
|
|
|
visible: false,
|
2015-06-24 19:20:47 +08:00
|
|
|
};
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2015-12-04 14:58:19 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if ('visible' in nextProps) {
|
|
|
|
this.setState({ visible: nextProps.visible });
|
|
|
|
}
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
confirm = () => {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setVisible(false);
|
2015-06-24 19:20:47 +08:00
|
|
|
this.props.onConfirm.call(this);
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel = () => {
|
2015-12-04 14:58:19 +08:00
|
|
|
this.setVisible(false);
|
2015-06-24 19:20:47 +08:00
|
|
|
this.props.onCancel.call(this);
|
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) {
|
|
|
|
if (!('visible' in this.props)) {
|
|
|
|
this.setState({ visible });
|
|
|
|
}
|
2016-03-13 16:49:05 +08:00
|
|
|
this.props.onVisibleChange(visible);
|
2016-03-29 17:33:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 19:20:47 +08:00
|
|
|
render() {
|
2016-08-31 15:00:13 +08:00
|
|
|
const [{ prefixCls, title, placement, arrowPointAtCenter }, restProps] = splitObject(
|
|
|
|
this.props,
|
|
|
|
['prefixCls', 'title', 'placement', 'arrowPointAtCenter']
|
|
|
|
);
|
2016-03-03 17:43:38 +08:00
|
|
|
let { okText, cancelText } = this.props;
|
2016-03-05 16:39:27 +08:00
|
|
|
if (this.context.antLocale && this.context.antLocale.Popconfirm) {
|
|
|
|
okText = okText || this.context.antLocale.Popconfirm.okText;
|
|
|
|
cancelText = cancelText || this.context.antLocale.Popconfirm.cancelText;
|
2016-03-03 17:43:38 +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`}>
|
2016-03-03 21:00:38 +08:00
|
|
|
<Button onClick={this.cancel} type="ghost" size="small">{cancelText || '取消'}</Button>
|
|
|
|
<Button onClick={this.confirm} type="primary" size="small">{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}
|
|
|
|
builtinPlacements={getPlacements({ arrowPointAtCenter })}
|
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
|
|
|
}
|