UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

67 lines (59 loc) 2.07 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var PropTypes = require('prop-types'); var React = require('react'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); const HeadingContext = /*#__PURE__*/React__default["default"].createContext(1); function Section(_ref) { let { as: BaseComponent = 'section', level: levelOverride, ...rest } = _ref; const parentLevel = React__default["default"].useContext(HeadingContext); const level = levelOverride ?? parentLevel + 1; const BaseComponentAsAny = BaseComponent; return /*#__PURE__*/React__default["default"].createElement(HeadingContext.Provider, { value: Math.min(level, 6) }, /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, rest)); } Section.propTypes = { /** * Provide an alternative tag or component to use instead of the default * <section> element */ as: PropTypes__default["default"].elementType, /** * Specify the content that will be placed in the component */ children: PropTypes__default["default"].node, /** * Specify a class name for the outermost node of the component */ className: PropTypes__default["default"].string, /** * Overrides the level of the section */ level: PropTypes__default["default"].number }; function Heading(props) { const HeadingIntrinsic = `h${React__default["default"].useContext(HeadingContext)}`; return /*#__PURE__*/React__default["default"].createElement(HeadingIntrinsic, props); } Heading.propTypes = { /** * Specify the content that will be placed in the component */ children: PropTypes__default["default"].node, /** * Specify a class name for the outermost node of the component */ className: PropTypes__default["default"].string }; exports.Heading = Heading; exports.Section = Section;