loading-spinner.js 702 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from './icon'
  3. import { useEffect, useState } from 'react'
  4. import PropTypes from 'prop-types'
  5. function LoadingSpinner({ delay = 0 }) {
  6. const { t } = useTranslation()
  7. const [show, setShow] = useState(false)
  8. useEffect(() => {
  9. const timer = window.setTimeout(() => {
  10. setShow(true)
  11. }, delay)
  12. return () => {
  13. window.clearTimeout(timer)
  14. }
  15. }, [delay])
  16. if (!show) {
  17. return null
  18. }
  19. return (
  20. <div className="loading">
  21. <Icon type="refresh" fw spin />
  22. &nbsp;
  23. {t('loading')}…
  24. </div>
  25. )
  26. }
  27. LoadingSpinner.propTypes = {
  28. delay: PropTypes.number,
  29. }
  30. export default LoadingSpinner