2024-06-11 12:59:52 +02:00
|
|
|
import type React from 'react';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { FC, ReactNode } from 'react';
|
2022-05-09 14:38:12 +02:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
2024-03-18 13:58:05 +01:00
|
|
|
import { Paper, type PaperProps, styled } from '@mui/material';
|
2022-05-09 14:38:12 +02:00
|
|
|
import { useStyles } from './PageContent.styles';
|
|
|
|
import useLoading from 'hooks/useLoading';
|
|
|
|
import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender';
|
|
|
|
|
|
|
|
interface IPageContentProps extends PaperProps {
|
|
|
|
header?: ReactNode;
|
|
|
|
isLoading?: boolean;
|
|
|
|
/**
|
|
|
|
* @deprecated fix feature event log and remove
|
|
|
|
*/
|
|
|
|
disablePadding?: boolean;
|
|
|
|
/**
|
|
|
|
* @deprecated fix feature event log and remove
|
|
|
|
*/
|
|
|
|
disableBorder?: boolean;
|
2022-07-13 16:35:43 +02:00
|
|
|
disableLoading?: boolean;
|
2022-05-09 14:38:12 +02:00
|
|
|
bodyClass?: string;
|
2022-10-31 12:46:31 +01:00
|
|
|
headerClass?: string;
|
2023-08-10 09:28:10 +02:00
|
|
|
withTabs?: boolean;
|
2022-05-09 14:38:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-05 15:23:40 +01:00
|
|
|
const StyledHeader = styled('div')(({ theme }) => ({
|
|
|
|
borderBottomStyle: 'solid',
|
|
|
|
borderBottomWidth: '1px',
|
|
|
|
borderBottomColor: theme.palette.divider,
|
|
|
|
[theme.breakpoints.down('md')]: {
|
|
|
|
padding: theme.spacing(3, 2),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledPaper = styled(Paper)(({ theme }) => ({
|
|
|
|
borderRadius: theme.shape.borderRadiusLarge,
|
|
|
|
boxShadow: 'none',
|
|
|
|
}));
|
|
|
|
|
2024-06-11 12:59:52 +02:00
|
|
|
const PageContentLoading: FC<{
|
|
|
|
isLoading: boolean;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}> = ({ children, isLoading }) => {
|
2022-07-13 16:35:43 +02:00
|
|
|
const ref = useLoading(isLoading);
|
|
|
|
|
|
|
|
return (
|
2023-10-02 14:25:46 +02:00
|
|
|
<div ref={ref} aria-busy={isLoading} aria-live='polite'>
|
2022-07-13 16:35:43 +02:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-09 14:38:12 +02:00
|
|
|
export const PageContent: FC<IPageContentProps> = ({
|
|
|
|
children,
|
|
|
|
header,
|
|
|
|
disablePadding = false,
|
|
|
|
disableBorder = false,
|
|
|
|
bodyClass = '',
|
2022-10-31 12:46:31 +01:00
|
|
|
headerClass = '',
|
2022-05-09 14:38:12 +02:00
|
|
|
isLoading = false,
|
2022-07-13 16:35:43 +02:00
|
|
|
disableLoading = false,
|
2022-05-09 14:38:12 +02:00
|
|
|
className,
|
2023-08-10 09:28:10 +02:00
|
|
|
withTabs,
|
2022-05-09 14:38:12 +02:00
|
|
|
...rest
|
|
|
|
}) => {
|
|
|
|
const { classes: styles } = useStyles();
|
|
|
|
|
2022-10-31 12:46:31 +01:00
|
|
|
const headerClasses = classnames(
|
|
|
|
'header',
|
|
|
|
headerClass || styles.headerPadding,
|
|
|
|
{
|
|
|
|
[styles.paddingDisabled]: disablePadding,
|
|
|
|
[styles.borderDisabled]: disableBorder,
|
2023-08-10 09:28:10 +02:00
|
|
|
[styles.withTabs]: withTabs,
|
2023-10-02 14:25:46 +02:00
|
|
|
},
|
2022-10-31 12:46:31 +01:00
|
|
|
);
|
2022-05-09 14:38:12 +02:00
|
|
|
|
2022-05-18 11:56:55 +02:00
|
|
|
const bodyClasses = classnames(
|
2022-07-22 09:31:08 +02:00
|
|
|
'body',
|
2022-05-18 11:56:55 +02:00
|
|
|
bodyClass ? bodyClass : styles.bodyContainer,
|
|
|
|
{
|
|
|
|
[styles.paddingDisabled]: disablePadding,
|
|
|
|
[styles.borderDisabled]: disableBorder,
|
2023-10-02 14:25:46 +02:00
|
|
|
},
|
2022-05-18 11:56:55 +02:00
|
|
|
);
|
2022-05-09 14:38:12 +02:00
|
|
|
|
|
|
|
const paperProps = disableBorder ? { elevation: 0 } : {};
|
|
|
|
|
2022-07-13 16:35:43 +02:00
|
|
|
const content = (
|
2023-01-05 15:23:40 +01:00
|
|
|
<StyledPaper
|
2022-07-13 16:35:43 +02:00
|
|
|
{...rest}
|
|
|
|
{...paperProps}
|
2023-01-05 15:23:40 +01:00
|
|
|
className={classnames(className)}
|
2022-07-13 16:35:43 +02:00
|
|
|
>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(header)}
|
|
|
|
show={
|
2023-01-05 15:23:40 +01:00
|
|
|
<StyledHeader className={headerClasses}>
|
2022-07-13 16:35:43 +02:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={typeof header === 'string'}
|
|
|
|
show={<PageHeader title={header as string} />}
|
|
|
|
elseShow={header}
|
|
|
|
/>
|
2023-01-05 15:23:40 +01:00
|
|
|
</StyledHeader>
|
2022-07-13 16:35:43 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div className={bodyClasses}>{children}</div>
|
2023-01-05 15:23:40 +01:00
|
|
|
</StyledPaper>
|
2022-07-13 16:35:43 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (disableLoading) {
|
2023-11-13 14:47:51 +01:00
|
|
|
return <div>{content}</div>;
|
2022-07-13 16:35:43 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:38:12 +02:00
|
|
|
return (
|
2022-07-13 16:35:43 +02:00
|
|
|
<PageContentLoading isLoading={isLoading}>{content}</PageContentLoading>
|
2022-05-09 14:38:12 +02:00
|
|
|
);
|
|
|
|
};
|