overleaf/services/web/frontend/js/shared/components/loading-spinner.tsx
Jakob Ackermann 83cf21d8cf Merge pull request #15271 from overleaf/jpa-lazy-loading
[web] lazy load big optional UI elements

GitOrigin-RevId: 18d723c66834be3984b74c3c89cfb46e2fffbfc1
2023-10-18 08:04:05 +00:00

57 lines
1 KiB
TypeScript

import { useTranslation } from 'react-i18next'
import Icon from './icon'
import { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
function LoadingSpinner({ delay = 0 }) {
const { t } = useTranslation()
const [show, setShow] = useState(false)
useEffect(() => {
const timer = window.setTimeout(() => {
setShow(true)
}, delay)
return () => {
window.clearTimeout(timer)
}
}, [delay])
if (!show) {
return null
}
return (
<div className="loading">
<Icon type="refresh" fw spin />
&nbsp;
{t('loading')}
</div>
)
}
LoadingSpinner.propTypes = {
delay: PropTypes.number,
}
export default LoadingSpinner
export function FullSizeLoadingSpinner({
delay = 0,
minHeight,
}: {
delay?: number
minHeight?: string
}) {
return (
<div className="full-size-loading-spinner-container" style={{ minHeight }}>
<LoadingSpinner delay={delay} />
</div>
)
}
FullSizeLoadingSpinner.propTypes = {
delay: PropTypes.number,
minHeight: PropTypes.string,
}