2018-12-07 04:59:25 +00:00
|
|
|
import React from 'react';
|
2023-09-13 00:40:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-12-07 04:59:25 +00:00
|
|
|
|
2024-06-25 08:46:29 +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
|
|
|
|
2024-06-25 08:46:29 +00:00
|
|
|
class Alert extends React.PureComponent {
|
2018-12-07 04:59:25 +00:00
|
|
|
|
2024-06-25 08:46:29 +00:00
|
|
|
getIconClass(intent) {
|
2018-12-07 04:59:25 +00:00
|
|
|
switch (intent) {
|
2019-01-31 09:37:02 +00:00
|
|
|
case 'success':
|
2024-06-25 08:46:29 +00:00
|
|
|
return 'fa fa-check-circle';
|
2019-01-31 09:37:02 +00:00
|
|
|
case 'warning':
|
2024-06-25 08:46:29 +00:00
|
|
|
return 'fa fa-exclamation-triangle';
|
2019-01-31 09:37:02 +00:00
|
|
|
case 'none':
|
2024-06-25 08:46:29 +00:00
|
|
|
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() {
|
2024-06-25 08:46:29 +00:00
|
|
|
const { intent, title, children, isRemovable, onRemove } = this.props;
|
|
|
|
const iconClass = this.getIconClass(intent);
|
2018-12-07 04:59:25 +00:00
|
|
|
return (
|
2024-06-25 08:46:29 +00:00
|
|
|
<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>
|
2024-06-25 08:46:29 +00:00
|
|
|
<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>
|
2024-06-25 08:46:29 +00:00
|
|
|
{isRemovable && (
|
|
|
|
<div onClick={onRemove} className="toast-close">
|
|
|
|
<span>×</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-12-07 04:59:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-25 08:46:29 +00:00
|
|
|
Alert.propTypes = propTypes;
|
2023-09-13 00:40:50 +00:00
|
|
|
|
|
|
|
export default Alert;
|