Files
suwayomi-material-you-webui/src/components/util/LoadingPlaceholder.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-03-27 22:21:39 +04:30
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import React from 'react';
2021-09-09 17:51:22 +04:30
import CircularProgress from '@mui/material/CircularProgress';
import { Box } from '@mui/system';
2021-03-27 22:21:39 +04:30
interface IProps {
shouldRender?: boolean | (() => boolean);
children?: React.ReactNode;
component?: string | React.FunctionComponent<any> | React.ComponentClass<any, any>;
componentProps?: any;
2021-03-27 22:21:39 +04:30
}
export default function LoadingPlaceholder(props: IProps) {
const { children, shouldRender, component, componentProps } = props;
2021-03-27 22:21:39 +04:30
let condition = true;
if (shouldRender !== undefined) {
condition = shouldRender instanceof Function ? shouldRender() : shouldRender;
}
2021-03-27 22:21:39 +04:30
if (condition) {
if (component) {
return React.createElement(component, componentProps);
}
if (children) {
return <>{children}</>;
2021-03-27 22:21:39 +04:30
}
}
return (
<Box
sx={{
margin: '10px auto',
display: 'flex',
justifyContent: 'center',
}}
>
2021-03-27 22:21:39 +04:30
<CircularProgress thickness={5} />
</Box>
2021-03-27 22:21:39 +04:30
);
}