@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
106 lines (102 loc) • 3.13 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix.js';
import { Icon } from '../Icon/MskIcon.js';
const ModalHeader = /*#__PURE__*/React__default.forwardRef(function ModalHeader(_ref, ref) {
let {
buttonOnClick,
children,
className: customClassName,
closeClassName,
closeIconClassName,
closeModal,
iconDescription,
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__default.createElement("div", _extends({
className: headerClass
}, rest, {
ref: ref
}), label && /*#__PURE__*/React__default.createElement("h2", {
className: labelClass
}, label), title && /*#__PURE__*/React__default.createElement("h3", {
className: titleClass
}, title), children, /*#__PURE__*/React__default.createElement("button", {
onClick: handleCloseButtonClick,
className: closeClass,
title: iconDescription,
"aria-label": iconDescription,
type: "button"
}, /*#__PURE__*/React__default.createElement(Icon, {
icon: "clear",
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 };