forked from reactstrap/reactstrap
/
ToastHeader.js
86 lines (77 loc) · 1.99 KB
/
ToastHeader.js
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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
const propTypes = {
tag: tagPropType,
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
wrapTag: tagPropType,
toggle: PropTypes.func,
className: PropTypes.string,
cssModule: PropTypes.object,
children: PropTypes.node,
closeAriaLabel: PropTypes.string,
charCode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
close: PropTypes.object,
};
const defaultProps = {
tag: 'strong',
wrapTag: 'div',
tagClassName: 'mr-auto',
closeAriaLabel: 'Close',
charCode: 215,
};
const ToastHeader = (props) => {
let closeButton;
let icon;
const {
className,
cssModule,
children,
toggle,
tag: Tag,
wrapTag: WrapTag,
closeAriaLabel,
close,
tagClassName,
icon: iconProp,
...attributes } = props;
const classes = mapToCssModules(classNames(
className,
'toast-header'
), cssModule);
if (!close && toggle) {
closeButton = (
<button type="button" onClick={toggle} className={mapToCssModules('btn-close', cssModule)} aria-label={closeAriaLabel} />
);
}
if (typeof iconProp === "string") {
icon = (
<svg
className={mapToCssModules(`rounded text-${iconProp}`)}
width="20"
height="20"
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid slice"
focusable="false"
role="img"
>
<rect fill="currentColor" width="100%" height="100%"></rect>
</svg>
);
} else if (iconProp) {
icon = iconProp;
}
return (
<WrapTag {...attributes} className={classes}>
{icon}
<Tag className={mapToCssModules(classNames(tagClassName, { "ml-2": icon != null }), cssModule)}>
{children}
</Tag>
{close || closeButton}
</WrapTag>
);
};
ToastHeader.propTypes = propTypes;
ToastHeader.defaultProps = defaultProps;
export default ToastHeader;