/
PageContent.tsx
102 lines (92 loc) · 2.71 KB
/
PageContent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
disableLoading?: boolean;
bodyClass?: string;
headerClass?: string;
}
const PageContentLoading: FC<{ isLoading: boolean }> = ({
children,
isLoading,
}) => {
const ref = useLoading(isLoading);
return (
<div ref={ref} aria-busy={isLoading} aria-live="polite">
{children}
</div>
);
};
export const PageContent: FC<IPageContentProps> = ({
children,
header,
disablePadding = false,
disableBorder = false,
bodyClass = '',
headerClass = '',
isLoading = false,
disableLoading = false,
className,
...rest
}) => {
const { classes: styles } = useStyles();
const headerClasses = classnames(
'header',
styles.headerContainer,
headerClass || styles.headerPadding,
{
[styles.paddingDisabled]: disablePadding,
[styles.borderDisabled]: disableBorder,
}
);
const bodyClasses = classnames(
'body',
bodyClass ? bodyClass : styles.bodyContainer,
{
[styles.paddingDisabled]: disablePadding,
[styles.borderDisabled]: disableBorder,
}
);
const paperProps = disableBorder ? { elevation: 0 } : {};
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;
}
return (
<PageContentLoading isLoading={isLoading}>{content}</PageContentLoading>
);
};