2024-09-11 11:27:50 +00:00
|
|
|
import { createPortal } from 'react-dom'
|
2024-02-28 16:49:44 +00:00
|
|
|
import styles from './style.module.scss'
|
2024-09-11 14:33:13 +00:00
|
|
|
import { PropsWithChildren } from 'react'
|
2024-02-28 16:49:44 +00:00
|
|
|
|
|
|
|
interface Props {
|
2024-08-30 10:28:33 +00:00
|
|
|
desc?: string
|
|
|
|
variant?: 'small' | 'default'
|
2024-02-28 16:49:44 +00:00
|
|
|
}
|
|
|
|
|
2024-09-11 14:33:13 +00:00
|
|
|
export const LoadingSpinner = (props: PropsWithChildren<Props>) => {
|
|
|
|
const { desc, children, variant = 'default' } = props
|
2024-02-28 16:49:44 +00:00
|
|
|
|
2024-08-30 10:28:33 +00:00
|
|
|
switch (variant) {
|
|
|
|
case 'small':
|
|
|
|
return (
|
|
|
|
<div
|
2024-09-02 10:49:51 +00:00
|
|
|
className={`${styles.loadingSpinnerContainer}`}
|
|
|
|
data-variant={variant}
|
2024-08-30 10:28:33 +00:00
|
|
|
>
|
|
|
|
<div className={styles.loadingSpinner}></div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
default:
|
2024-09-11 11:27:50 +00:00
|
|
|
return createPortal(
|
2024-08-30 10:28:33 +00:00
|
|
|
<div className={styles.loadingSpinnerOverlay}>
|
2024-09-02 10:49:51 +00:00
|
|
|
<div
|
|
|
|
className={styles.loadingSpinnerContainer}
|
|
|
|
data-variant={variant}
|
|
|
|
>
|
2024-08-30 10:28:33 +00:00
|
|
|
<div className={styles.loadingSpinner}></div>
|
2024-09-11 14:33:13 +00:00
|
|
|
{desc && (
|
|
|
|
<div className={styles.loadingSpinnerDesc}>
|
|
|
|
{desc}
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
2024-08-30 10:28:33 +00:00
|
|
|
</div>
|
2024-09-11 11:27:50 +00:00
|
|
|
</div>,
|
|
|
|
document.getElementById('root')!
|
2024-08-30 10:28:33 +00:00
|
|
|
)
|
|
|
|
}
|
2024-02-28 16:49:44 +00:00
|
|
|
}
|