2022-05-09 14:38:12 +02:00
|
|
|
import React, { FC, ReactNode } from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
|
|
|
import { Paper, PaperProps } from '@mui/material';
|
|
|
|
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-07-13 16:35:43 +02:00
|
|
|
const PageContentLoading: FC<{ isLoading: boolean }> = ({
|
|
|
|
children,
|
|
|
|
isLoading,
|
|
|
|
}) => {
|
|
|
|
const ref = useLoading(isLoading);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div ref={ref} aria-busy={isLoading} aria-live="polite">
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-09 14:38:12 +02:00
|
|
|
export const PageContent: FC<IPageContentProps> = ({
|
|
|
|
children,
|
|
|
|
header,
|
|
|
|
disablePadding = false,
|
|
|
|
disableBorder = false,
|
|
|
|
bodyClass = '',
|
|
|
|
isLoading = false,
|
2022-07-13 16:35:43 +02:00
|
|
|
disableLoading = false,
|
2022-05-09 14:38:12 +02:00
|
|
|
className,
|
|
|
|
...rest
|
|
|
|
}) => {
|
|
|
|
const { classes: styles } = useStyles();
|
|
|
|
|
|
|
|
const headerClasses = classnames(styles.headerContainer, {
|
|
|
|
[styles.paddingDisabled]: disablePadding,
|
|
|
|
[styles.borderDisabled]: disableBorder,
|
|
|
|
});
|
|
|
|
|
2022-05-18 11:56:55 +02:00
|
|
|
const bodyClasses = classnames(
|
|
|
|
bodyClass ? bodyClass : styles.bodyContainer,
|
|
|
|
{
|
|
|
|
[styles.paddingDisabled]: disablePadding,
|
|
|
|
[styles.borderDisabled]: disableBorder,
|
|
|
|
}
|
|
|
|
);
|
2022-05-09 14:38:12 +02:00
|
|
|
|
|
|
|
const paperProps = disableBorder ? { elevation: 0 } : {};
|
|
|
|
|
2022-07-13 16:35:43 +02:00
|
|
|
const content = (
|
|
|
|
<Paper
|
|
|
|
{...rest}
|
|
|
|
{...paperProps}
|
|
|
|
className={classnames(styles.container, className)}
|
|
|
|
>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(header)}
|
|
|
|
show={
|
|
|
|
<div className={headerClasses}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={typeof header === 'string'}
|
|
|
|
show={<PageHeader title={header as string} />}
|
|
|
|
elseShow={header}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div className={bodyClasses}>{children}</div>
|
|
|
|
</Paper>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (disableLoading) {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
);
|
|
|
|
};
|