AlertBox.tsx 1.1 KB

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