1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-17 14:37:58 +00:00
seahub/frontend/src/components/toast/alert.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-12-07 04:59:25 +00:00
import React from 'react';
import PropTypes from 'prop-types';
2018-12-07 04:59:25 +00:00
const propTypes = {
intent: PropTypes.string.isRequired,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
onRemove: PropTypes.func.isRequired,
children: PropTypes.string,
isRemovable: PropTypes.bool,
};
2018-12-07 04:59:25 +00:00
class Alert extends React.PureComponent {
2018-12-07 04:59:25 +00:00
getIconClass(intent) {
2018-12-07 04:59:25 +00:00
switch (intent) {
case 'success':
return 'fa fa-check-circle';
case 'warning':
return 'fa fa-exclamation-triangle';
case 'none':
return 'fa fa-exclamation-circle';
case 'danger':
return 'fa fa-exclamation-circle';
default:
return 'fa fa-check-circle';
2018-12-07 04:59:25 +00:00
}
}
render() {
const { intent, title, children, isRemovable, onRemove } = this.props;
const iconClass = this.getIconClass(intent);
2018-12-07 04:59:25 +00:00
return (
<div className={`seahub-toast-alert-container ${intent || 'success'}`}>
<div className="toast-alert-icon">
<i className={iconClass} />
2018-12-07 04:59:25 +00:00
</div>
<div className="toast-text-container">
<p className="toast-text-title">{title}</p>
{children ? <p className="toast-text-child">{children}</p> : null}
2018-12-07 04:59:25 +00:00
</div>
{isRemovable && (
<div onClick={onRemove} className="toast-close">
<span>&times;</span>
</div>
)}
2018-12-07 04:59:25 +00:00
</div>
);
}
}
Alert.propTypes = propTypes;
export default Alert;