Skip to content

Instantly share code, notes, and snippets.

@hiwelo
Created March 31, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiwelo/7000364d722f55f1c60f32757e67f28c to your computer and use it in GitHub Desktop.
Save hiwelo/7000364d722f55f1c60f32757e67f28c to your computer and use it in GitHub Desktop.
import React, { FunctionComponent } from 'react';
import useHeadingContext from '../../utilities/headings/hooks';
import { HeadingContext } from '../../utilities/headings';
import { HEADING_LEVEL_MAX } from '../../utilities/headings/constants';
/**
* The `Section` component offers a way to encapsulate a series of related
* content offering a series of helpers managing automatically heading levels
* for example.
*/
const Section: FunctionComponent = ({ children }) => {
const currentHeadingLevel = useHeadingContext();
const sectionHeadingLevel = Math.min(
currentHeadingLevel + 1,
HEADING_LEVEL_MAX,
);
return (
<HeadingContext.Provider value={sectionHeadingLevel}>
{children}
</HeadingContext.Provider>
);
};
export default Section;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment