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

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';
2021-11-17 15:42:43 +03:30
import { Box } from '@mui/system';
2021-03-27 22:21:39 +04:30
interface IProps {
2023-02-06 10:06:33 +01:00
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) {
2023-02-06 10:06:33 +01:00
const { children, shouldRender, component, componentProps } = props;
2021-03-27 22:21:39 +04:30
2021-10-24 22:56:10 +03: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) {
2023-03-11 18:05:58 +01:00
return children as JSX.Element;
2021-03-27 22:21:39 +04:30
}
}
return (
2023-02-06 10:06:33 +01:00
<Box
sx={{
margin: '10px auto',
display: 'flex',
justifyContent: 'center',
}}
2021-11-17 15:42:43 +03:30
>
2021-03-27 22:21:39 +04:30
<CircularProgress thickness={5} />
2021-11-17 15:42:43 +03:30
</Box>
2021-03-27 22:21:39 +04:30
);
}