import React from 'react'; import ReactDOM from 'react-dom'; import Animate from 'rc-animate'; import Icon from '../icon'; export default React.createClass({ getDefaultProps() { return { prefixCls: 'ant-alert' }; }, getInitialState() { return { closing: true, closed: false }; }, handleClose(e) { let dom = ReactDOM.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); } }, animationEnd() { this.setState({ closed: true, closing: true }); }, render() { let iconClass = this.props.description ? 'ant-alert-with-description-icon' : 'ant-alert-icon'; let iconType = ''; 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'; } let html; let closeName = !this.state.closing ? ' ' + this.props.prefixCls + '-close' : ''; if (this.props.description) { let close = this.props.closable ? : ''; html =

{this.props.message}

{this.props.description} {close}
; } else { if (this.props.closeText) { html =
{this.props.message} {this.props.closeText}
; } else { let close = this.props.closable ? : ''; html =
{this.props.message} {close}
; } } return this.state.closed ? null : {html} ; } });