fedisearch/application/src/components/Loader.tsx

61 wiersze
1.7 KiB
TypeScript
Czysty Zwykły widok Historia

2022-01-01 19:37:33 +00:00
import React, { ReactNode } from 'react'
import Spinner from './Spinner'
2022-01-01 19:37:33 +00:00
const Loader: React.FC<{ children: ReactNode, loading: boolean, hideContent?: boolean, table?: number, showTop?: boolean, showBottom?: boolean }> = ({
showTop,
showBottom,
hideContent,
children,
table,
loading
}) => {
2022-01-15 19:44:37 +00:00
const className = 'loader' + (loading ? ' -loading' : '')
const spinner = (
<div className={'d-flex justify-content-center'}>
<Spinner/>
2022-01-15 19:44:37 +00:00
</div>
)
2022-01-15 19:44:37 +00:00
if (table) {
return (
<>
{showTop && loading
? (
<tbody>
<tr className={className}>
<td colSpan={table}>
{spinner}
</td>
</tr>
</tbody>
)
: ''}
{hideContent && loading ? '' : children}
{showBottom && loading
? (
<tbody>
<tr className={className}>
<td colSpan={table}>
<div className={'d-flex justify-content-center'}>
<Spinner/>
</div>
</td>
</tr>
</tbody>
)
: ''}
</>
2022-01-15 19:44:37 +00:00
)
}
return (
<>
{showTop && loading ? spinner : ''}
{hideContent && loading ? '' : children}
{showBottom && loading ? spinner : ''}
</>
2022-01-01 19:37:33 +00:00
)
}
export default Loader