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, charCode, close, tagClassName, icon: iconProp, ...attributes } = props; const classes = mapToCssModules(classNames( className, 'toast-header' ), cssModule); if (!close && toggle) { const closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode; closeButton = ( ); } if (typeof iconProp === "string") { icon = ( ); } else if (iconProp) { icon = iconProp; } return ( {icon} {children} {close || closeButton} ); }; ToastHeader.propTypes = propTypes; ToastHeader.defaultProps = defaultProps; export default ToastHeader;