2015-06-24 19:20:47 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Tooltip from 'rc-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';
|
2015-11-24 11:21:37 +08:00
|
|
|
|
2016-03-09 17:23:10 +08:00
|
|
|
const placements = getPlacements();
|
2015-06-24 19:20:47 +08:00
|
|
|
const prefixCls = 'ant-popover';
|
2016-01-14 16:46:38 +08:00
|
|
|
const noop = function () {};
|
2015-11-24 11:21:37 +08:00
|
|
|
const transitionNames = {
|
|
|
|
top: 'zoom-down',
|
|
|
|
bottom: 'zoom-up',
|
|
|
|
left: 'zoom-right',
|
|
|
|
right: 'zoom-left',
|
|
|
|
topLeft: 'zoom-down',
|
|
|
|
bottomLeft: 'zoom-up',
|
|
|
|
leftTop: 'zoom-right',
|
|
|
|
rightTop: 'zoom-left',
|
|
|
|
topRight: 'zoom-down',
|
|
|
|
bottomRight: 'zoom-up',
|
|
|
|
leftBottom: 'zoom-right',
|
|
|
|
rightBottom: 'zoom-left',
|
|
|
|
};
|
2015-06-24 19:20:47 +08:00
|
|
|
|
|
|
|
export default React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
visible: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
transitionName: '',
|
|
|
|
placement: 'top',
|
|
|
|
trigger: 'click',
|
2015-08-19 20:12:34 +08:00
|
|
|
overlayStyle: {},
|
2015-11-24 11:21:37 +08:00
|
|
|
onConfirm: noop,
|
|
|
|
onCancel: noop,
|
|
|
|
okText: '确定',
|
2015-12-04 14:58:19 +08:00
|
|
|
cancelText: '取消',
|
|
|
|
onVisibleChange() {},
|
2015-06-24 19:20:47 +08:00
|
|
|
};
|
|
|
|
},
|
2015-12-04 14:58:19 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if ('visible' in nextProps) {
|
|
|
|
this.setState({ visible: nextProps.visible });
|
|
|
|
}
|
|
|
|
},
|
2015-08-18 14:02:55 +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);
|
|
|
|
},
|
2015-08-18 14:02:55 +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);
|
|
|
|
},
|
2015-12-04 14:58:19 +08:00
|
|
|
onVisibleChange(visible) {
|
|
|
|
this.setVisible(visible);
|
|
|
|
},
|
|
|
|
setVisible(visible) {
|
|
|
|
if (!('visible' in this.props)) {
|
|
|
|
this.setState({ visible });
|
|
|
|
}
|
2016-03-13 16:49:05 +08:00
|
|
|
this.props.onVisibleChange(visible);
|
2015-08-07 19:21:02 +08:00
|
|
|
},
|
2015-06-24 19:20:47 +08:00
|
|
|
render() {
|
2016-02-02 11:52:00 +08:00
|
|
|
const { title, okText, cancelText, placement, overlayStyle, trigger, ...restProps } = this.props;
|
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-03-28 16:09:13 +08:00
|
|
|
<Icon type="question-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-01-07 14:21:29 +08:00
|
|
|
<Button onClick={this.cancel} type="ghost" size="small">{cancelText}</Button>
|
|
|
|
<Button onClick={this.confirm} type="primary" size="small">{okText}</Button>
|
|
|
|
</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
|
|
|
|
2015-11-24 11:21:37 +08:00
|
|
|
const transitionName = transitionNames[placement];
|
2015-06-24 19:20:47 +08:00
|
|
|
|
|
|
|
return (
|
2016-03-09 17:23:10 +08:00
|
|
|
<Tooltip {...restProps}
|
|
|
|
placement={placement}
|
|
|
|
builtinPlacements={placements}
|
2016-01-07 17:46:46 +08:00
|
|
|
overlayStyle={overlayStyle}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
onVisibleChange={this.onVisibleChange}
|
|
|
|
transitionName={transitionName}
|
|
|
|
visible={this.state.visible}
|
|
|
|
trigger={trigger}
|
|
|
|
overlay={overlay}>
|
2015-06-24 19:20:47 +08:00
|
|
|
{this.props.children}
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|