UNPKG

@lesnoypudge/utils-react

Version:

lesnoypudge's utils-react

24 lines (23 loc) 743 B
import { useContext } from "react"; import { HeadingContext } from "../../context/HeadingContext/HeadingContext.js"; import { MAX_LEVEL, START_LEVEL } from "../../vars/index.js"; import { jsx } from "react/jsx-runtime"; const HeadingProvider = ({ startFrom, children }) => { const upperLevel = useContext(HeadingContext); const withStartFrom = startFrom !== void 0; if (!withStartFrom && upperLevel === MAX_LEVEL) { console.warn("Maximum heading level exceeded"); } const nextLevel = startFrom ?? Math.min(MAX_LEVEL, (upperLevel ?? START_LEVEL) + 1); return /* @__PURE__ */ jsx(HeadingContext.Provider, { value: nextLevel, children }); }; export { HeadingProvider }; //# sourceMappingURL=HeadingProvider.js.map