ant-design/components/alert/index.jsx

79 lines
2.5 KiB
React
Raw Normal View History

2015-07-27 20:53:08 +08:00
import React from 'react';
export default React.createClass({
getDefaultProps() {
2015-07-29 18:44:56 +08:00
return {
prefixCls: 'ant-alert'
};
2015-07-27 20:53:08 +08:00
},
2015-07-29 18:44:56 +08:00
getInitialState() {
return {
display: 'block'
};
2015-07-27 20:53:08 +08:00
},
2015-07-29 18:44:56 +08:00
handleClose(e) {
2015-07-29 15:22:47 +08:00
if (this.props.onClose) {
2015-07-29 18:44:56 +08:00
this.props.onClose.call(this, e);
2015-07-27 20:53:08 +08:00
}
this.setState({
display: 'none'
});
},
render () {
2015-07-29 18:44:56 +08:00
var iconClass = this.props.description ?
'ant-alert-with-description-icon anticon-' : 'ant-alert-icon anticon-';
2015-07-29 10:27:31 +08:00
switch (this.props.type) {
2015-07-27 20:53:08 +08:00
case 'success':
iconClass += 'check-circle';
break;
case 'info':
2015-07-30 11:20:14 +08:00
iconClass += 'info-circle';
2015-07-27 20:53:08 +08:00
break;
case 'error':
2015-07-30 11:20:14 +08:00
iconClass += 'exclamation-circle';
break;
2015-07-27 20:53:08 +08:00
case 'warn':
2015-07-30 11:20:14 +08:00
iconClass += 'question-circle';
2015-07-27 20:53:08 +08:00
break;
default:
iconClass += 'default';
}
2015-07-29 17:22:36 +08:00
if (this.props.description) {
2015-07-29 18:44:56 +08:00
let close = this.props.closable ?
2015-07-29 17:22:36 +08:00
<a onClick={this.handleClose} className={'ant-alert-with-description-close-icon'}><span
className='ant-alert-with-description-close-icon-x'></span></a> : '';
2015-07-27 20:53:08 +08:00
return (
2015-07-29 17:22:36 +08:00
<div style={{display: this.state.display}}
className={'ant-alert-with-description ant-alert-with-description-' + this.props.type}>
2015-07-27 20:53:08 +08:00
<i className={'anticon ' + iconClass}></i>
2015-07-29 17:22:36 +08:00
<p className={'ant-alert-with-description-message'}>{this.props.message}</p>
<span className={'ant-alert-with-description-description'}>{this.props.description}</span>
{close}
2015-07-27 20:53:08 +08:00
</div>
);
} else {
2015-07-29 10:27:31 +08:00
if (this.props.closeText) {
2015-07-27 20:53:08 +08:00
return (
2015-07-29 10:27:31 +08:00
<div style={{display: this.state.display}} className={'ant-alert ant-alert-' + this.props.type}>
2015-07-27 20:53:08 +08:00
<i className={'anticon ' + iconClass}></i>
2015-07-29 17:22:36 +08:00
<span className={'ant-alert-description'}>{this.props.message}</span>
2015-07-29 15:22:47 +08:00
<span onClick={this.handleClose} className={'ant-alert-close-text'}>{this.props.closeText}</span>
2015-07-27 20:53:08 +08:00
</div>
);
} else {
2015-07-29 18:44:56 +08:00
let close = this.props.closable ?
2015-07-29 17:22:36 +08:00
<a onClick={this.handleClose} className={'ant-alert-close-icon'}>
<span className='ant-alert-close-icon-x'></span>
</a> : '';
2015-07-27 20:53:08 +08:00
return (
2015-07-29 10:27:31 +08:00
<div style={{display: this.state.display}} className={'ant-alert ant-alert-' + this.props.type}>
2015-07-27 20:53:08 +08:00
<i className={'anticon ' + iconClass}></i>
2015-07-29 17:22:36 +08:00
<span className={'ant-alert-description'}>{this.props.message}</span>
{close}
2015-07-27 20:53:08 +08:00
</div>
);
}
}
}
});