-
Notifications
You must be signed in to change notification settings - Fork 843
/
Copy pathpanel.tsx
127 lines (111 loc) Β· 2.82 KB
/
panel.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, {
ButtonHTMLAttributes,
FunctionComponent,
HTMLAttributes,
ReactNode,
Ref,
} from 'react';
import classNames from 'classnames';
import { CommonProps, ExclusiveUnion, Omit } from '../common';
import { EuiBetaBadge } from '../badge/beta_badge';
export type PanelPaddingSize = 'none' | 's' | 'm' | 'l';
export interface EuiPanelProps extends CommonProps {
/**
* If active, adds a deeper shadow to the panel
*/
hasShadow?: boolean;
/**
* Padding applied to the panel
*/
paddingSize?: PanelPaddingSize;
/**
* When true the panel will grow to match `EuiFlexItem`
*/
grow?: boolean;
panelRef?: Ref<HTMLDivElement>;
/**
* Add a badge to the panel to label it as "Beta" or other non-GA state
*/
betaBadgeLabel?: string;
/**
* Add a description to the beta badge (will appear in a tooltip)
*/
betaBadgeTooltipContent?: ReactNode;
/**
* Optional title will be supplied as tooltip title or title attribute otherwise the label will be used
*/
betaBadgeTitle?: string;
}
interface Divlike
extends EuiPanelProps,
Omit<HTMLAttributes<HTMLDivElement>, 'onClick'> {}
interface Buttonlike
extends EuiPanelProps,
ButtonHTMLAttributes<HTMLButtonElement> {}
type Props = ExclusiveUnion<Divlike, Buttonlike>;
const paddingSizeToClassNameMap = {
none: null,
s: 'euiPanel--paddingSmall',
m: 'euiPanel--paddingMedium',
l: 'euiPanel--paddingLarge',
};
export const SIZES = Object.keys(paddingSizeToClassNameMap);
export const EuiPanel: FunctionComponent<Props> = ({
children,
className,
paddingSize = 'm',
hasShadow = false,
grow = true,
panelRef,
onClick,
betaBadgeLabel,
betaBadgeTooltipContent,
betaBadgeTitle,
...rest
}) => {
const classes = classNames(
'euiPanel',
paddingSize ? paddingSizeToClassNameMap[paddingSize] : null,
{
'euiPanel--shadow': hasShadow,
'euiPanel--flexGrowZero': !grow,
'euiPanel--isClickable': onClick,
'euiPanel--hasBetaBadge': betaBadgeLabel,
},
className
);
let optionalBetaBadge;
if (betaBadgeLabel) {
optionalBetaBadge = (
<span className="euiPanel__betaBadgeWrapper">
<EuiBetaBadge
label={betaBadgeLabel}
title={betaBadgeTitle}
tooltipContent={betaBadgeTooltipContent}
className="euiPanel__betaBadge"
/>
</span>
);
}
if (onClick) {
return (
<button
ref={panelRef as Ref<HTMLButtonElement>}
className={classes}
onClick={onClick}
{...rest as ButtonHTMLAttributes<HTMLButtonElement>}>
{optionalBetaBadge}
{children}
</button>
);
}
return (
<div
ref={panelRef as Ref<HTMLDivElement>}
className={classes}
{...rest as HTMLAttributes<HTMLDivElement>}>
{optionalBetaBadge}
{children}
</div>
);
};