AlertBox.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, { FunctionComponent, ReactNode } from 'react';
  2. import classNames from 'classnames';
  3. import { AppNotificationSeverity } from 'app/types';
  4. interface Props {
  5. title: string;
  6. icon?: string;
  7. body?: ReactNode;
  8. severity: AppNotificationSeverity;
  9. onClose?: () => void;
  10. }
  11. function getIconFromSeverity(severity: AppNotificationSeverity): string {
  12. switch (severity) {
  13. case AppNotificationSeverity.Error: {
  14. return 'fa fa-exclamation-triangle';
  15. }
  16. case AppNotificationSeverity.Success: {
  17. return 'fa fa-check';
  18. }
  19. default:
  20. return '';
  21. }
  22. }
  23. export const AlertBox: FunctionComponent<Props> = ({ title, icon, body, severity, onClose }) => {
  24. const alertClass = classNames('alert', `alert-${severity}`);
  25. return (
  26. <div className={alertClass}>
  27. <div className="alert-icon">
  28. <i className={icon || getIconFromSeverity(severity)} />
  29. </div>
  30. <div className="alert-body">
  31. <div className="alert-title">{title}</div>
  32. {body && <div className="alert-text">{body}</div>}
  33. </div>
  34. {onClose && (
  35. <button type="button" className="alert-close" onClick={onClose}>
  36. <i className="fa fa fa-remove" />
  37. </button>
  38. )}
  39. </div>
  40. );
  41. };