Created
March 31, 2020 14:29
-
-
Save hiwelo/7000364d722f55f1c60f32757e67f28c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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