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.

98 lines
3.1 KiB

9 years ago
import React from 'react';
import Animate from 'rc-animate';
import Icon from '../iconfont';
9 years ago
export default React.createClass({
getDefaultProps() {
return {
prefixCls: 'ant-alert'
};
9 years ago
},
getInitialState() {
return {
closing: true,
closed: false
};
9 years ago
},
handleClose(e) {
let dom = React.findDOMNode(this);
dom.style.height = dom.offsetHeight + 'px';
// Magic code
// 重复一次后才能正确设置 height
dom.style.height = dom.offsetHeight + 'px';
this.setState({
closing: false
});
if (this.props.onClose) {
this.props.onClose.call(this, e);
9 years ago
}
},
animationEnd() {
9 years ago
this.setState({
closed: true,
closing: true
9 years ago
});
},
render() {
let iconClass = this.props.description ?
'ant-alert-with-description-icon' : 'ant-alert-icon';
let iconType = '';
9 years ago
switch (this.props.type) {
case 'success':
iconType = 'check-circle';
break;
case 'info':
iconType = 'info-circle';
break;
case 'error':
iconType = 'exclamation-circle';
break;
case 'warn':
iconType = 'question-circle';
break;
default:
iconType = 'default';
9 years ago
}
let html;
let closeName = !this.state.closing ? ' ' + this.props.prefixCls + '-close' : '';
if (this.props.description) {
let close = this.props.closable ?
<a onClick={this.handleClose} className={'ant-alert-with-description-close-icon'}>
<span className="ant-alert-with-description-close-icon-x"></span>
</a> : '';
html = <div data-show={this.state.closing} className={'ant-alert-with-description ant-alert-with-description-' + this.props.type + closeName}>
<Icon className={iconClass} type={iconType} />
<p className={'ant-alert-with-description-message'}>{this.props.message}</p>
<span className={'ant-alert-with-description-description'}>{this.props.description}</span>
{close}
</div>;
9 years ago
} else {
9 years ago
if (this.props.closeText) {
html = <div data-show={this.state.closing} className={'ant-alert ant-alert-' + this.props.type + closeName}>
<Icon className={iconClass} type={iconType} />
<span className={'ant-alert-description'}>{this.props.message}</span>
<span onClick={this.handleClose} className={'ant-alert-close-text'}>{this.props.closeText}</span>
</div>;
9 years ago
} else {
let close = this.props.closable ?
<a onClick={this.handleClose} className={'ant-alert-close-icon'}>
<span className="ant-alert-close-icon-x"></span>
</a> : '';
html = <div data-show={this.state.closing} className={'ant-alert ant-alert-' + this.props.type + closeName}>
<Icon className={iconClass} type={iconType} />
<span className={'ant-alert-description'}>{this.props.message}</span>
{close}
</div>;
9 years ago
}
}
return this.state.closed ? null : <Animate
component=""
showProp="data-show"
transitionName="slide-up"
onEnd={this.animationEnd}>
{html}
</Animate>;
9 years ago
}
});