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';
|
2015-06-24 19:20:47 +08:00
|
|
|
const prefixCls = 'ant-popover';
|
|
|
|
|
|
|
|
export default React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
visible: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
transitionName: '',
|
|
|
|
placement: 'top',
|
|
|
|
trigger: 'click',
|
2015-08-19 20:12:34 +08:00
|
|
|
overlayStyle: {},
|
|
|
|
onConfirm: function () {
|
|
|
|
},
|
|
|
|
onCancel: function () {
|
|
|
|
}
|
2015-06-24 19:20:47 +08:00
|
|
|
};
|
|
|
|
},
|
2015-08-18 14:02:55 +08:00
|
|
|
confirm() {
|
2015-06-24 19:20:47 +08:00
|
|
|
this.props.onConfirm.call(this);
|
|
|
|
this.setState({
|
|
|
|
visible: false
|
|
|
|
});
|
|
|
|
},
|
2015-08-18 14:02:55 +08:00
|
|
|
cancel() {
|
2015-06-24 19:20:47 +08:00
|
|
|
this.props.onCancel.call(this);
|
|
|
|
this.setState({
|
|
|
|
visible: false
|
|
|
|
});
|
|
|
|
},
|
2015-08-18 14:02:55 +08:00
|
|
|
onVisibleChange(v) {
|
2015-08-07 19:21:02 +08:00
|
|
|
this.setState({
|
|
|
|
visible: v
|
|
|
|
});
|
|
|
|
},
|
2015-06-24 19:20:47 +08:00
|
|
|
render() {
|
|
|
|
const overlay = <div>
|
|
|
|
<div className={prefixCls + '-content'}>
|
|
|
|
<p className={prefixCls + '-message'}>
|
2015-10-02 15:58:37 +08:00
|
|
|
<Icon type="exclamation-circle" />
|
2015-06-24 19:20:47 +08:00
|
|
|
{this.props.title}
|
|
|
|
</p>
|
2015-08-19 20:12:34 +08:00
|
|
|
|
2015-06-24 19:20:47 +08:00
|
|
|
<div className={prefixCls + '-buttons'}>
|
2015-10-26 11:08:36 +08:00
|
|
|
<Button onClick={this.cancel} type="ghost" size="small">取消</Button>
|
|
|
|
<Button onClick={this.confirm} type="primary" size="small">确定</Button>
|
2015-06-24 19:20:47 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
|
|
|
|
const transitionName = ({
|
|
|
|
top: 'zoom-down',
|
|
|
|
bottom: 'zoom-up',
|
|
|
|
left: 'zoom-right',
|
2015-11-05 18:14:20 +08:00
|
|
|
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
|
|
|
})[this.props.placement];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip placement={this.props.placement}
|
2015-08-19 20:12:34 +08:00
|
|
|
overlayStyle={this.props.overlayStyle}
|
2015-08-07 19:21:02 +08:00
|
|
|
prefixCls={prefixCls}
|
|
|
|
onVisibleChange={this.onVisibleChange}
|
|
|
|
transitionName={transitionName}
|
|
|
|
visible={this.state.visible}
|
|
|
|
trigger={this.props.trigger}
|
|
|
|
overlay={overlay}>
|
2015-06-24 19:20:47 +08:00
|
|
|
{this.props.children}
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|