G2GDataTransferStatusIcon.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { type ComponentPropsWithoutRef } from 'react';
  2. /**
  3. * Get the union type of all the values in an object, array or array-like type `T`
  4. * @see {@link https://github.com/piotrwitek/utility-types/blob/df2502ef504c4ba8bd9de81a45baef112b7921d0/src/mapped-types.ts#L589-L597}
  5. */
  6. type ValuesType<
  7. T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any>
  8. > = T extends ReadonlyArray<any>
  9. ? T[number]
  10. : T extends ArrayLike<any>
  11. ? T[number]
  12. : T extends object
  13. ? T[keyof T]
  14. : never;
  15. /**
  16. * G2G transfer progress status master
  17. */
  18. const G2G_PROGRESS_STATUS = {
  19. PENDING: 'PENDING',
  20. IN_PROGRESS: 'IN_PROGRESS',
  21. COMPLETED: 'COMPLETED',
  22. ERROR: 'ERROR',
  23. } as const;
  24. /**
  25. * G2G transfer progress status
  26. */
  27. type G2GProgressStatus = ValuesType<typeof G2G_PROGRESS_STATUS>
  28. /**
  29. * Props for {@link G2GDataTransfer}
  30. */
  31. interface Props extends ComponentPropsWithoutRef<'i'>{
  32. status: G2GProgressStatus;
  33. }
  34. /**
  35. * Icon for G2G transfer status
  36. */
  37. const G2GDataTransferStatusIcon = ({ status, className, ...props }: Props): JSX.Element | null => {
  38. if (status === G2G_PROGRESS_STATUS.IN_PROGRESS) {
  39. return (
  40. <i className={`fa fa-spinner fa-pulse fa-fw ${className}`} aria-label="in progress" {...props} />
  41. );
  42. }
  43. if (status === G2G_PROGRESS_STATUS.COMPLETED) {
  44. return (
  45. <i className={`fa fa-check-circle-o fa-fw text-info ${className}`} aria-label="completed" {...props} />
  46. );
  47. }
  48. if (status === G2G_PROGRESS_STATUS.ERROR) {
  49. return (
  50. <i className={`fa fa-exclamation-circle fa-fw text-danger ${className}`} aria-label="error" {...props} />
  51. );
  52. }
  53. return <i className={`fa fa-circle-o fa-fw ${className}`} aria-label="pending" {...props} />;
  54. };
  55. export default G2GDataTransferStatusIcon;