Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/content/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext } from 'react'

// The simplification to pass a Number instead object
// It can be converted to `SectionContext({ level: 1 })` in the future
Comment thread
Joozty marked this conversation as resolved.
const LevelContext = createContext(1)

export default LevelContext
17 changes: 17 additions & 0 deletions components/content/heading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { forwardRef, useContext } from 'react'

import LevelContext from './context'

import { Heading } from 'design'

const SectionHeading = forwardRef(({ children, ...passProps }, ref) => {
const level = useContext(LevelContext)

return (
<Heading ref={ref} level={level} {...passProps}>
{children}
</Heading>
)
})

export default SectionHeading
2 changes: 2 additions & 0 deletions components/content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export Heading from './heading'
export Section from './section'
21 changes: 21 additions & 0 deletions components/content/section.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { forwardRef, useContext } from 'react'

import LevelContext from './context'

const Section = forwardRef(
(
{ children, level: forceLevel, tag: Tag = 'section', ...restProps },
ref
) => {
const contextLevel = useContext(LevelContext)
const level = forceLevel ?? contextLevel + 1

return (
<Tag ref={ref} {...restProps}>
<LevelContext.Provider value={level}>{children}</LevelContext.Provider>
</Tag>
)
}
)

export default Section
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path')

const withSourceMaps = require('@zeit/next-source-maps')
const withMDX = require('@next/mdx')()

const camelCaseLoader = path.join(__dirname, 'webpack/camelcase-loader.js')

Expand Down Expand Up @@ -115,4 +116,4 @@ const nextConfig = {
},
}

module.exports = withSourceMaps(nextConfig)
module.exports = withMDX(withSourceMaps(nextConfig))
Loading