1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import classNames from 'classnames';
|
6 | import { mapToCssModules, tagPropType } from './utils';
|
7 | var propTypes = {
|
8 | tag: tagPropType,
|
9 | icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
10 | wrapTag: tagPropType,
|
11 | toggle: PropTypes.func,
|
12 | className: PropTypes.string,
|
13 | cssModule: PropTypes.object,
|
14 | children: PropTypes.node,
|
15 | closeAriaLabel: PropTypes.string,
|
16 | charCode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
17 | close: PropTypes.object
|
18 | };
|
19 | var defaultProps = {
|
20 | tag: 'strong',
|
21 | wrapTag: 'div',
|
22 | tagClassName: 'mr-auto',
|
23 | closeAriaLabel: 'Close',
|
24 | charCode: 215
|
25 | };
|
26 |
|
27 | var ToastHeader = function ToastHeader(props) {
|
28 | var closeButton;
|
29 | var icon;
|
30 |
|
31 | var className = props.className,
|
32 | cssModule = props.cssModule,
|
33 | children = props.children,
|
34 | toggle = props.toggle,
|
35 | Tag = props.tag,
|
36 | WrapTag = props.wrapTag,
|
37 | closeAriaLabel = props.closeAriaLabel,
|
38 | charCode = props.charCode,
|
39 | close = props.close,
|
40 | tagClassName = props.tagClassName,
|
41 | iconProp = props.icon,
|
42 | attributes = _objectWithoutPropertiesLoose(props, ["className", "cssModule", "children", "toggle", "tag", "wrapTag", "closeAriaLabel", "charCode", "close", "tagClassName", "icon"]);
|
43 |
|
44 | var classes = mapToCssModules(classNames(className, 'toast-header'), cssModule);
|
45 |
|
46 | if (!close && toggle) {
|
47 | var closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode;
|
48 | closeButton = React.createElement("button", {
|
49 | type: "button",
|
50 | onClick: toggle,
|
51 | className: mapToCssModules('close', cssModule),
|
52 | "aria-label": closeAriaLabel
|
53 | }, React.createElement("span", {
|
54 | "aria-hidden": "true"
|
55 | }, closeIcon));
|
56 | }
|
57 |
|
58 | if (typeof iconProp === "string") {
|
59 | icon = React.createElement("svg", {
|
60 | className: mapToCssModules("rounded text-" + iconProp),
|
61 | width: "20",
|
62 | height: "20",
|
63 | xmlns: "http://www.w3.org/2000/svg",
|
64 | preserveAspectRatio: "xMidYMid slice",
|
65 | focusable: "false",
|
66 | role: "img"
|
67 | }, React.createElement("rect", {
|
68 | fill: "currentColor",
|
69 | width: "100%",
|
70 | height: "100%"
|
71 | }));
|
72 | } else if (iconProp) {
|
73 | icon = iconProp;
|
74 | }
|
75 |
|
76 | return React.createElement(WrapTag, _extends({}, attributes, {
|
77 | className: classes
|
78 | }), icon, React.createElement(Tag, {
|
79 | className: mapToCssModules(classNames(tagClassName, {
|
80 | "ml-2": icon != null
|
81 | }), cssModule)
|
82 | }, children), close || closeButton);
|
83 | };
|
84 |
|
85 | ToastHeader.propTypes = propTypes;
|
86 | ToastHeader.defaultProps = defaultProps;
|
87 | export default ToastHeader; |
\ | No newline at end of file |