You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.5 KiB

import React from 'react';
9 years ago
import ReactDOM from 'react-dom';
import Dialog from './index';
9 years ago
import Icon from '../icon';
9 years ago
import Button from '../button';
10 years ago
export default function (props) {
let div = document.createElement('div');
document.body.appendChild(div);
let d;
10 years ago
props = props || {};
props.iconClassName = props.iconClassName || 'question-circle';
let iconClassType = props.iconClassName;
let width = props.width || 416;
// 默认为 true,保持向下兼容
if (!('okCancel' in props)) {
props.okCancel = true;
}
10 years ago
props.okText = props.okText || (props.okCancel ? '确定' : '知道了');
props.cancelText = props.cancelText || '取消';
10 years ago
function close() {
d.setState({
visible: false
});
9 years ago
ReactDOM.unmountComponentAtNode(div);
div.parentNode.removeChild(div);
10 years ago
}
function onCancel() {
let cancelFn = props.onCancel;
10 years ago
if (cancelFn) {
let ret;
10 years ago
if (cancelFn.length) {
ret = cancelFn(close);
10 years ago
} else {
ret = cancelFn();
if (!ret) {
close();
}
}
if (ret && ret.then) {
ret.then(close);
10 years ago
}
10 years ago
} else {
close();
}
}
function onOk() {
let okFn = props.onOk;
10 years ago
if (okFn) {
let ret;
10 years ago
if (okFn.length) {
ret = okFn(close);
10 years ago
} else {
ret = okFn();
if (!ret) {
close();
}
}
if (ret && ret.then) {
ret.then(close);
10 years ago
}
10 years ago
} else {
close();
}
}
let body = <div className="ant-confirm-body">
<Icon type={iconClassType} />
10 years ago
<span className="ant-confirm-title">{props.title}</span>
<div className="ant-confirm-content">{props.content}</div>
10 years ago
</div>;
10 years ago
let footer = null;
if (props.okCancel) {
footer = <div className="ant-confirm-btns">
<Button type="ghost" size="large" onClick={onCancel}>
{props.cancelText}
</Button>
<Button type="primary" size="large" onClick={onOk}>
{props.okText}
</Button>
</div>;
} else {
footer = <div className="ant-confirm-btns">
<Button type="primary" size="large" onClick={onOk}>
{props.okText}
</Button>
</div>;
}
9 years ago
ReactDOM.render(<Dialog
10 years ago
prefixCls="ant-modal"
className="ant-confirm"
visible
10 years ago
closable={false}
title=""
transitionName="zoom"
footer=""
10 years ago
maskTransitionName="fade" width={width}>
10 years ago
<div style={{zoom: 1, overflow: 'hidden'}}>{body} {footer}</div>
10 years ago
</Dialog>, div, function () {
d = this;
});
}