You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design/components/modal/index.jsx

62 lines
1.4 KiB
React

10 years ago
var React = require('react');
var Dialog = require('rc-dialog');
10 years ago
function noop() {
}
10 years ago
var Modal = React.createClass({
getInitialState() {
return {
visible: false,
confirmLoading: false
};
},
10 years ago
handleCancel() {
var d = this.refs.d;
d.requestClose();
10 years ago
},
10 years ago
getDefaultProps() {
10 years ago
return {
10 years ago
prefixCls: 'ant-modal',
10 years ago
onOk: noop,
10 years ago
onCancel: noop
10 years ago
};
},
handleOk() {
this.setState({
confirmLoading: true
});
if (typeof this.props.onOk) {
this.props.onOk();
}
},
componentWillReceiveProps(nextProps) {
if ('visible' in nextProps) {
// 隐藏后去除按钮 loading 效果
if (!nextProps.visible) {
this.setState({
confirmLoading: false
});
}
}
10 years ago
},
render() {
var loadingIcon = this.state.confirmLoading ?
<i className="anticon anticon-loading"></i> : '';
10 years ago
var props = this.props;
var footer = props.footer || [
<button key="cancel" type="button" className="ant-btn ant-btn-lg" onClick={this.handleCancel}> </button>,
<button key="confirm" type="button" className="ant-btn ant-btn-primary ant-btn-lg" onClick={this.handleOk}>
{loadingIcon}
</button>
];
return <Dialog transitionName="zoom" onBeforeClose={props.onCancel} visible={this.state.visible} maskAnimation="fade" width="500" footer={footer} {...props} ref="d" />;
}
10 years ago
});
10 years ago
module.exports = Modal;