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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-03-27 22:21:39 +04:30
|
|
|
|
|
|
|
|
import React from 'react';
|
2021-09-09 17:51:22 +04:30
|
|
|
import CircularProgress from '@mui/material/CircularProgress';
|
2023-06-04 21:08:39 +02:00
|
|
|
import { Box } from '@mui/material';
|
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;
|
2023-05-18 13:48:01 +02:00
|
|
|
usePadding?: boolean;
|
2021-03-27 22:21:39 +04:30
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function LoadingPlaceholder(props: IProps) {
|
2023-05-18 13:48:01 +02:00
|
|
|
const { children, shouldRender, component, componentProps, usePadding } = 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={{
|
2023-05-18 13:48:01 +02:00
|
|
|
margin: '0px auto',
|
|
|
|
|
marginTop: usePadding ? 'unset' : '10px',
|
|
|
|
|
marginBottom: usePadding ? 'unset' : '10px',
|
|
|
|
|
padding: usePadding ? '10px 0' : 'unset',
|
2023-02-06 10:06:33 +01:00
|
|
|
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
|
|
|
);
|
|
|
|
|
}
|