ant-design/components/popconfirm/index.jsx

78 lines
1.8 KiB
React
Raw Normal View History

2015-06-24 19:20:47 +08:00
import React from 'react';
import Tooltip from 'rc-tooltip';
2015-10-02 15:58:37 +08:00
import Icon from '../iconfont';
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'}>
<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',
right: 'zoom-left'
})[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>
);
}
});