-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentPanel.tsx
84 lines (77 loc) · 2.22 KB
/
ContentPanel.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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
EuiHorizontalRule,
EuiPanel,
EuiTitle,
EuiText,
} from '@elastic/eui';
interface ContentPanelProps {
title?: string | JSX.Element;
titleSize?: 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l';
subTitleText?: string | JSX.Element;
bodyStyles?: object;
panelStyles?: object;
horizontalRuleClassName?: string;
actions?: React.ReactNode | React.ReactNode[];
children: React.ReactNode | React.ReactNode[];
}
const renderSubTitleText = (subTitleText: string | JSX.Element): JSX.Element | null => {
if (typeof subTitleText === 'string') {
if (!subTitleText) return null;
return (
<EuiText size="s" color="subdued">
{subTitleText}
</EuiText>
);
}
return subTitleText;
};
const ContentPanel: React.SFC<ContentPanelProps> = ({
title = '',
titleSize = 'm',
subTitleText = '',
bodyStyles = {},
panelStyles = {},
horizontalRuleClassName = '',
actions,
children,
}) => (
<EuiPanel style={{ paddingLeft: '0px', paddingRight: '0px', ...panelStyles }}>
<EuiFlexGroup style={{ padding: '0px 10px' }} justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem>
{typeof title === 'string' ? (
<EuiTitle size={titleSize}>
<h3>{title}</h3>
</EuiTitle>
) : (
title
)}
{renderSubTitleText(subTitleText)}
</EuiFlexItem>
{actions ? (
<EuiFlexItem grow={false}>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
{Array.isArray(actions) ? (
(actions as React.ReactNode[]).map(
(action: React.ReactNode, idx: number): React.ReactNode => (
<EuiFlexItem key={idx}>{action}</EuiFlexItem>
)
)
) : (
<EuiFlexItem>{actions}</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
<EuiHorizontalRule margin="xs" className={horizontalRuleClassName} />
<div style={{ padding: '0px 10px', ...bodyStyles }}>{children}</div>
</EuiPanel>
);
export default ContentPanel;