mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-24 17:51:51 +02:00
* Update test for the loading spinner component * Create a story for the loading spinner component * Move role and use CSS for spacing instead * Add a classname prop * Reuse LoadingSpinner * Use OLSpinner instead of Spinner * Use data-testid since status role was moved * Wait for journals to load * Use `isLoading` prop instead and fix the button's height * Use `isLoading` prop instead * Use LoadingSpinner instead and remove spacing * Update test for the loading spinner component * Use `isLoading` prop instead * Add aria-describedby to layout button for processing state * Replace `spinner` to `ol-spinner` * Scope status * Remove redundant `div.loading` --------- Co-authored-by: Antoine Clausse <antoine.clausse@overleaf.com> GitOrigin-RevId: 8f43b991f8f458b2abd5a4661913ac9b972d892a
82 lines
1.6 KiB
TypeScript
82 lines
1.6 KiB
TypeScript
import { useTranslation } from 'react-i18next'
|
|
import { useEffect, useState } from 'react'
|
|
import OLSpinner, { OLSpinnerSize } from '@/shared/components/ol/ol-spinner'
|
|
import classNames from 'classnames'
|
|
|
|
function LoadingSpinner({
|
|
align,
|
|
delay = 0,
|
|
loadingText,
|
|
size = 'sm',
|
|
className,
|
|
}: {
|
|
align?: 'left' | 'center'
|
|
delay?: 0 | 500 // 500 is our standard delay
|
|
loadingText?: string
|
|
size?: OLSpinnerSize
|
|
className?: string
|
|
}) {
|
|
const { t } = useTranslation()
|
|
|
|
const [show, setShow] = useState(false)
|
|
|
|
useEffect(() => {
|
|
// Ensure that spinner is displayed immediately if delay is 0
|
|
if (delay === 0) {
|
|
setShow(true)
|
|
return
|
|
}
|
|
|
|
const timer = window.setTimeout(() => {
|
|
setShow(true)
|
|
}, delay)
|
|
|
|
return () => {
|
|
window.clearTimeout(timer)
|
|
}
|
|
}, [delay])
|
|
|
|
if (!show) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div
|
|
role="status"
|
|
className={classNames(
|
|
'loading',
|
|
className,
|
|
align === 'left' ? 'align-items-start' : 'align-items-center'
|
|
)}
|
|
>
|
|
<OLSpinner size={size} />
|
|
{loadingText || `${t('loading')}…`}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default LoadingSpinner
|
|
|
|
export function FullSizeLoadingSpinner({
|
|
delay = 0,
|
|
minHeight,
|
|
loadingText,
|
|
size = 'sm',
|
|
className,
|
|
}: {
|
|
delay?: 0 | 500
|
|
minHeight?: string
|
|
loadingText?: string
|
|
size?: OLSpinnerSize
|
|
className?: string
|
|
}) {
|
|
return (
|
|
<div
|
|
className={classNames('full-size-loading-spinner-container', className)}
|
|
style={{ minHeight }}
|
|
>
|
|
<LoadingSpinner size={size} loadingText={loadingText} delay={delay} />
|
|
</div>
|
|
)
|
|
}
|