/
ColumnView.tsx
75 lines (64 loc) · 1.94 KB
/
ColumnView.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
import React from 'react';
import classNames from 'classnames';
import './styles/ColumnView.scss';
import prefixClass from './utils/prefixClass';
import icBEM from './utils/icBEM';
export const COMPONENT_NAME = prefixClass('column-view');
const ROOT_BEM = icBEM(COMPONENT_NAME);
export const BEM = {
root: ROOT_BEM,
header: ROOT_BEM.element('header'),
body: ROOT_BEM.element('body'),
footer: ROOT_BEM.element('footer'),
};
type OwnProps = {
header?: React.ReactNode;
footer?: React.ReactNode;
flexBody?: boolean;
bodyPadding?: {
top?: number;
bottom?: number;
left?: number;
right?: number;
};
};
type Props = OwnProps & typeof ColumnView.defaultProps;
function ColumnView({
header, footer, flexBody, bodyPadding,
// React props
// @ts-expect-error ts-migrate(2339) FIXME: Property 'className' does not exist on type 'Props... Remove this comment to see the full error message
className, children, ...wrapperProps
}: Props) {
const rootClassName = classNames(`${BEM.root}`, className);
const bodyClassName = BEM.body.modifier('flex', flexBody);
const bodyStyle = {
paddingTop: bodyPadding.top,
paddingBottom: bodyPadding.bottom,
paddingLeft: bodyPadding.left,
paddingRight: bodyPadding.right,
};
return (
<div className={rootClassName} {...wrapperProps}>
{header && (
<div className={`${BEM.header}`}>
{header}
</div>
)}
<div className={`${bodyClassName}`} style={bodyStyle}>
{children}
</div>
{footer && (
<div className={`${BEM.footer}`}>
{footer}
</div>
)}
</div>
);
}
ColumnView.defaultProps = {
header: undefined,
footer: undefined,
flexBody: false,
bodyPadding: { bottom: 24 },
};
export default ColumnView;