2021-12-18 09:54:53 +01:00
|
|
|
/*
|
|
|
|
* This is used to wrap MDX as returned from the mdxLoader
|
|
|
|
* method (see shared/mdx/loader.js)
|
|
|
|
* It is NOT for wrapping plain markdown/mdx
|
|
|
|
*/
|
|
|
|
import { useState, useEffect, Fragment } from 'react'
|
|
|
|
|
|
|
|
// See: https://mdxjs.com/guides/mdx-on-demand/
|
|
|
|
import { run } from '@mdx-js/mdx'
|
|
|
|
import * as runtime from 'react/jsx-runtime.js'
|
|
|
|
|
|
|
|
// Components that are available in all MDX
|
2021-12-19 19:08:54 +01:00
|
|
|
import customComponents from 'shared/components/mdx'
|
2021-12-18 15:41:37 +01:00
|
|
|
|
2021-12-19 19:08:54 +01:00
|
|
|
const MdxWrapper = ({mdx, app, components={}}) => {
|
2021-12-18 09:54:53 +01:00
|
|
|
|
|
|
|
const [mdxModule, setMdxModule] = useState()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
;(async () => {
|
|
|
|
setMdxModule(await run(mdx, runtime))
|
|
|
|
})()
|
|
|
|
}, [mdx])
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We use some default components that are available
|
|
|
|
* everywhere in MDX, but we also accept passing in
|
|
|
|
* extra components via props
|
|
|
|
*/
|
|
|
|
const allComponents = {
|
2021-12-19 19:08:54 +01:00
|
|
|
...customComponents,
|
2021-12-18 09:54:53 +01:00
|
|
|
...components
|
|
|
|
}
|
|
|
|
|
|
|
|
// React component for MDX content
|
|
|
|
const MdxContent = mdxModule ? mdxModule.default : Fragment
|
|
|
|
|
2021-12-18 15:41:37 +01:00
|
|
|
return (
|
2021-12-18 15:48:01 +01:00
|
|
|
<div className="prose lg:prose-xl prose-pre:bg-primary text-primary">
|
2021-12-18 15:41:37 +01:00
|
|
|
<MdxContent components={allComponents}/>
|
|
|
|
</div>
|
|
|
|
)
|
2021-12-18 09:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default MdxWrapper
|
|
|
|
|