AlertBox.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.Warning: {
  17. return 'fa fa-exclamation-triangle';
  18. }
  19. case AppNotificationSeverity.Info: {
  20. return 'fa fa-info-circle';
  21. }
  22. case AppNotificationSeverity.Success: {
  23. return 'fa fa-check';
  24. }
  25. default:
  26. return '';
  27. }
  28. }
  29. export const AlertBox: FunctionComponent<Props> = ({ title, icon, body, severity, onClose }) => {
  30. const alertClass = classNames('alert', `alert-${severity}`);
  31. return (
  32. <div className={alertClass}>
  33. <div className="alert-icon">
  34. <i className={icon || getIconFromSeverity(severity)} />
  35. </div>
  36. <div className="alert-body">
  37. <div className="alert-title">{title}</div>
  38. {body && <div className="alert-text">{body}</div>}
  39. </div>
  40. {onClose && (
  41. <button type="button" className="alert-close" onClick={onClose}>
  42. <i className="fa fa fa-remove" />
  43. </button>
  44. )}
  45. </div>
  46. );
  47. };