UNPKG

@carbon/react

Version:

React components for the Carbon Design System

113 lines (109 loc) 3.38 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import { Close } from '@carbon/icons-react'; import { usePrefix } from '../../internal/usePrefix.js'; import { IconButton } from '../IconButton/index.js'; const ModalHeader = /*#__PURE__*/React.forwardRef(function ModalHeader({ buttonOnClick, children, className: customClassName, closeClassName, closeIconClassName, closeModal, iconDescription = 'Close', label, labelClassName, title, titleClassName, ...rest }, ref) { const prefix = usePrefix(); function handleCloseButtonClick(evt) { closeModal?.(evt); buttonOnClick?.(evt); } const headerClass = cx(`${prefix}--modal-header`, customClassName); const labelClass = cx(`${prefix}--modal-header__label ${prefix}--type-delta`, labelClassName); const titleClass = cx(`${prefix}--modal-header__heading ${prefix}--type-beta`, titleClassName); const closeClass = cx(`${prefix}--modal-close`, closeClassName); const closeIconClass = cx(`${prefix}--modal-close__icon`, closeIconClassName); return /*#__PURE__*/React.createElement("div", _extends({ className: headerClass }, rest, { ref: ref }), label && /*#__PURE__*/React.createElement("h2", { className: labelClass }, label), title && /*#__PURE__*/React.createElement("h2", { className: titleClass }, title), children, /*#__PURE__*/React.createElement("div", { className: `${prefix}--modal-close-button` }, /*#__PURE__*/React.createElement(IconButton, { className: closeClass, label: iconDescription, onClick: handleCloseButtonClick, "aria-label": iconDescription, align: "left" }, /*#__PURE__*/React.createElement(Close, { size: 20, "aria-hidden": "true", tabIndex: "-1", className: closeIconClass })))); }); ModalHeader.propTypes = { /** * Provide an optional function to be called when the close button is * clicked */ buttonOnClick: PropTypes.func, /** * Specify the content to be placed in the ModalHeader */ children: PropTypes.node, /** * Specify an optional className to be applied to the modal header */ className: PropTypes.string, /** * Specify an optional className to be applied to the modal close node */ closeClassName: PropTypes.string, /** * Specify an optional className to be applied to the modal close icon node */ closeIconClassName: PropTypes.string, /** * Provide an optional function to be called when the modal is closed */ closeModal: PropTypes.func, /** * Specify a description for the close icon that can be read by screen * readers */ iconDescription: PropTypes.string, /** * Specify an optional label to be displayed */ label: PropTypes.node, /** * Specify an optional className to be applied to the modal header label */ labelClassName: PropTypes.string, /** * Specify an optional title to be displayed */ title: PropTypes.node, /** * Specify an optional className to be applied to the modal heading */ titleClassName: PropTypes.string }; export { ModalHeader };