@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
57 lines (53 loc) • 1.53 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import PropTypes from 'prop-types';
import React__default from 'react';
const HeadingContext = /*#__PURE__*/React__default.createContext(1);
function Section(_ref) {
let {
as: BaseComponent = 'section',
level: levelOverride,
...rest
} = _ref;
const parentLevel = React__default.useContext(HeadingContext);
const level = levelOverride ?? parentLevel + 1;
const BaseComponentAsAny = BaseComponent;
return /*#__PURE__*/React__default.createElement(HeadingContext.Provider, {
value: Math.min(level, 6)
}, /*#__PURE__*/React__default.createElement(BaseComponentAsAny, rest));
}
Section.propTypes = {
/**
* Provide an alternative tag or component to use instead of the default
* <section> element
*/
as: PropTypes.elementType,
/**
* Specify the content that will be placed in the component
*/
children: PropTypes.node,
/**
* Specify a class name for the outermost node of the component
*/
className: PropTypes.string,
/**
* Overrides the level of the section
*/
level: PropTypes.number
};
function Heading(props) {
const HeadingIntrinsic = `h${React__default.useContext(HeadingContext)}`;
return /*#__PURE__*/React__default.createElement(HeadingIntrinsic, props);
}
Heading.propTypes = {
/**
* Specify the content that will be placed in the component
*/
children: PropTypes.node,
/**
* Specify a class name for the outermost node of the component
*/
className: PropTypes.string
};
export { Heading, Section };