mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
83cf21d8cf
[web] lazy load big optional UI elements GitOrigin-RevId: 18d723c66834be3984b74c3c89cfb46e2fffbfc1
57 lines
1 KiB
TypeScript
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 />
|
|
|
|
{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,
|
|
}
|