-
Notifications
You must be signed in to change notification settings - Fork 839
/
Copy pathcall_out.tsx
132 lines (114 loc) · 3.18 KB
/
call_out.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
128
129
130
131
132
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { forwardRef, HTMLAttributes, ReactNode } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../common';
import { IconType, EuiIcon } from '../icon';
import { EuiText } from '../text';
import { useEuiTheme } from '../../services';
import { EuiPanel } from '../panel';
import { EuiTitle } from '../title';
import { euiCallOutStyles, euiCallOutHeadingStyles } from './call_out.styles';
export const COLORS = ['primary', 'success', 'warning', 'danger'] as const;
export type Color = typeof COLORS[number];
export const HEADINGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'] as const;
type Heading = typeof HEADINGS[number];
type Size = 's' | 'm';
export type EuiCallOutProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'color'> & {
title?: ReactNode;
iconType?: IconType;
color?: Color;
size?: Size;
heading?: Heading;
};
export const EuiCallOut = forwardRef<HTMLDivElement, EuiCallOutProps>(
(
{
title,
color = 'primary',
size = 'm',
iconType,
children,
className,
heading = 'p',
...rest
},
ref
) => {
const theme = useEuiTheme();
const styles = euiCallOutStyles(theme);
const cssStyles = [styles.euiCallOut];
const cssIconStyle = [styles.euiCallOut__icon];
const cssDescriptionStyle = [styles.euiCallOut__description];
const headerStyles = euiCallOutHeadingStyles(theme);
const cssHeaderStyles = [
headerStyles.euiCallOutHeader,
headerStyles[color],
];
const classes = classNames(
'euiCallOut',
{
[`euiCallOut--${color}`]: color,
},
className
);
let headerIcon;
if (iconType) {
headerIcon = (
<EuiIcon
css={cssIconStyle}
type={iconType}
size="m"
aria-hidden="true"
color="inherit" // forces the icon to inherit its parent color
/>
);
}
let optionalChildren;
if (children) {
optionalChildren = (
<EuiText
css={cssDescriptionStyle}
size={size === 's' ? 'xs' : 's'}
color="default"
>
{children}
</EuiText>
);
}
let header;
if (title) {
const H: Heading = heading;
header = (
<EuiTitle size={size === 's' ? 'xxs' : 'xs'} css={cssHeaderStyles}>
<H className="euiCallOutHeader__title">
{headerIcon}
{title}
</H>
</EuiTitle>
);
}
return (
<EuiPanel
borderRadius="none"
color={color}
css={cssStyles}
paddingSize={size === 's' ? 's' : 'm'}
className={classes}
panelRef={ref}
grow={false}
{...rest}
>
{header}
{optionalChildren}
</EuiPanel>
);
}
);
EuiCallOut.displayName = 'EuiCallOut';