2021-10-06 04:33:24 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import Icon from './icon'
|
2022-01-11 04:17:56 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
2024-09-25 09:46:02 -04:00
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
import { Spinner } from 'react-bootstrap-5'
|
2024-10-11 05:22:38 -04:00
|
|
|
import classNames from 'classnames'
|
2021-10-06 04:33:24 -04:00
|
|
|
|
2024-02-06 10:19:37 -05:00
|
|
|
function LoadingSpinner({
|
2024-10-11 05:22:38 -04:00
|
|
|
align,
|
2024-02-06 10:19:37 -05:00
|
|
|
delay = 0,
|
|
|
|
loadingText,
|
2024-10-11 05:22:38 -04:00
|
|
|
size,
|
2024-02-06 10:19:37 -05:00
|
|
|
}: {
|
2024-10-11 05:22:38 -04:00
|
|
|
align?: 'left' | 'center'
|
2024-02-06 10:19:37 -05:00
|
|
|
delay?: 0 | 500 // 500 is our standard delay
|
|
|
|
loadingText?: string
|
2024-10-11 05:22:38 -04:00
|
|
|
size?: 'sm'
|
2024-02-06 10:19:37 -05:00
|
|
|
}) {
|
2021-10-06 04:33:24 -04:00
|
|
|
const { t } = useTranslation()
|
2022-01-11 04:17:56 -05:00
|
|
|
|
|
|
|
const [show, setShow] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const timer = window.setTimeout(() => {
|
|
|
|
setShow(true)
|
|
|
|
}, delay)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.clearTimeout(timer)
|
|
|
|
}
|
|
|
|
}, [delay])
|
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-10-11 05:22:38 -04:00
|
|
|
const alignmentClass =
|
|
|
|
align === 'left' ? 'align-items-start' : 'align-items-center'
|
|
|
|
|
2021-10-06 04:33:24 -04:00
|
|
|
return (
|
2024-09-25 09:46:02 -04:00
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={
|
|
|
|
<div className="loading">
|
|
|
|
<Icon type="refresh" fw spin />
|
|
|
|
|
|
|
|
{loadingText || t('loading')}…
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
bs5={
|
2024-10-11 05:22:38 -04:00
|
|
|
<div className={classNames(`d-flex ${alignmentClass}`)}>
|
2024-09-25 09:46:02 -04:00
|
|
|
<Spinner
|
|
|
|
animation="border"
|
|
|
|
aria-hidden="true"
|
|
|
|
role="status"
|
2024-10-11 05:22:38 -04:00
|
|
|
className="align-self-center"
|
|
|
|
size={size}
|
2024-09-25 09:46:02 -04:00
|
|
|
/>
|
|
|
|
|
|
|
|
{loadingText || t('loading')}…
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2021-10-06 04:33:24 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LoadingSpinner
|
2023-10-17 04:41:40 -04:00
|
|
|
|
|
|
|
export function FullSizeLoadingSpinner({
|
|
|
|
delay = 0,
|
|
|
|
minHeight,
|
2024-02-06 10:19:37 -05:00
|
|
|
loadingText,
|
2023-10-17 04:41:40 -04:00
|
|
|
}: {
|
2024-02-06 10:19:37 -05:00
|
|
|
delay?: 0 | 500
|
2023-10-17 04:41:40 -04:00
|
|
|
minHeight?: string
|
2024-02-06 10:19:37 -05:00
|
|
|
loadingText?: string
|
2023-10-17 04:41:40 -04:00
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div className="full-size-loading-spinner-container" style={{ minHeight }}>
|
2024-02-06 10:19:37 -05:00
|
|
|
<LoadingSpinner loadingText={loadingText} delay={delay} />
|
2023-10-17 04:41:40 -04:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|