ant-design/components/modal/index.jsx

60 lines
1.4 KiB
React
Raw Normal View History

import React from 'react';
import Dialog from 'rc-dialog';
2015-06-11 16:35:36 +08:00
function noop() {
}
2015-06-10 22:02:13 +08:00
export default React.createClass({
2015-06-12 17:11:32 +08:00
getInitialState() {
return {
visible: false,
confirmLoading: false
2015-06-12 17:11:32 +08:00
};
},
2015-06-10 22:02:13 +08:00
handleCancel() {
2015-06-25 15:29:56 +08:00
var d = this.refs.d;
d.requestClose();
2015-06-10 22:02:13 +08:00
},
2015-06-11 16:35:36 +08:00
getDefaultProps() {
2015-06-10 22:02:13 +08:00
return {
2015-06-12 12:01:02 +08:00
prefixCls: 'ant-modal',
2015-06-11 16:35:36 +08:00
onOk: noop,
2015-06-12 23:46:04 +08:00
onCancel: noop
2015-06-10 22:02:13 +08:00
};
},
handleOk() {
2015-06-12 17:11:32 +08:00
this.setState({
confirmLoading: true
2015-06-12 17:11:32 +08:00
});
if (typeof this.props.onOk) {
this.props.onOk();
}
2015-06-12 17:11:32 +08:00
},
componentWillReceiveProps(nextProps) {
if ('visible' in nextProps) {
// 隐藏后去除按钮 loading 效果
if (!nextProps.visible) {
this.setState({
confirmLoading: false
});
}
}
2015-06-10 22:02:13 +08:00
},
render() {
var loadingIcon = this.state.confirmLoading ?
<i className="anticon anticon-loading"></i> : '';
2015-06-10 22:02:13 +08:00
var props = this.props;
2015-06-12 17:37:39 +08:00
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" />;
2015-06-10 17:59:32 +08:00
}
2015-06-10 22:02:13 +08:00
});