AlertBox.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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:
  19. return '';
  20. }
  21. }
  22. export const AlertBox: FunctionComponent<Props> = ({ title, icon, text, severity, onClose }) => {
  23. return (
  24. <div className={`alert alert-${severity}`}>
  25. <div className="alert-icon">
  26. <i className={icon || getIconFromSeverity(severity)} />
  27. </div>
  28. <div className="alert-body">
  29. <div className="alert-title">{title}</div>
  30. {text && <div className="alert-text">{text}</div>}
  31. </div>
  32. {onClose && (
  33. <button type="button" className="alert-close" onClick={onClose}>
  34. <i className="fa fa fa-remove" />
  35. </button>
  36. )}
  37. </div>
  38. );
  39. };