loading-spinner.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from './icon'
  3. import { useEffect, useState } from 'react'
  4. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  5. import { Spinner } from 'react-bootstrap-5'
  6. function LoadingSpinner({
  7. delay = 0,
  8. loadingText,
  9. }: {
  10. delay?: 0 | 500 // 500 is our standard delay
  11. loadingText?: string
  12. }) {
  13. const { t } = useTranslation()
  14. const [show, setShow] = useState(false)
  15. useEffect(() => {
  16. const timer = window.setTimeout(() => {
  17. setShow(true)
  18. }, delay)
  19. return () => {
  20. window.clearTimeout(timer)
  21. }
  22. }, [delay])
  23. if (!show) {
  24. return null
  25. }
  26. return (
  27. <BootstrapVersionSwitcher
  28. bs3={
  29. <div className="loading">
  30. <Icon type="refresh" fw spin />
  31. &nbsp;
  32. {loadingText || t('loading')}…
  33. </div>
  34. }
  35. bs5={
  36. <div className="text-center mt-4">
  37. <Spinner
  38. animation="border"
  39. aria-hidden="true"
  40. role="status"
  41. className="align-middle"
  42. />
  43. &nbsp;
  44. {loadingText || t('loading')}…
  45. </div>
  46. }
  47. />
  48. )
  49. }
  50. export default LoadingSpinner
  51. export function FullSizeLoadingSpinner({
  52. delay = 0,
  53. minHeight,
  54. loadingText,
  55. }: {
  56. delay?: 0 | 500
  57. minHeight?: string
  58. loadingText?: string
  59. }) {
  60. return (
  61. <div className="full-size-loading-spinner-container" style={{ minHeight }}>
  62. <LoadingSpinner loadingText={loadingText} delay={delay} />
  63. </div>
  64. )
  65. }