-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create an MDX component to render MDX content with default mapp…
…ed components
- Loading branch information
1 parent
6dde701
commit 210f5bd
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { MDXRenderer } from 'gatsby-plugin-mdx'; | ||
import { MDXProvider } from '@mdx-js/react'; | ||
import Button from './Button'; | ||
import MDXCallout from './MDXCallout'; | ||
import Collapser from './Collapser'; | ||
import Icon from './Icon'; | ||
import InlineCode from './InlineCode'; | ||
import Link from './Link'; | ||
import MDXCodeBlock from './MDXCodeBlock'; | ||
import MDXCollapserGroup from './MDXCollapserGroup'; | ||
import MDXLink from './MDXLink'; | ||
import MDXTable from './MDXTable'; | ||
import MDXVideo from './MDXVideo'; | ||
|
||
const defaultComponents = { | ||
a: MDXLink, | ||
code: MDXCodeBlock, | ||
pre: (props) => props.children, | ||
Button, | ||
ButtonLink: (props) => <Button {...props} as={Link} />, | ||
Callout: MDXCallout, | ||
Collapser, | ||
CollapserGroup: MDXCollapserGroup, | ||
Icon, | ||
InlineCode, | ||
Link, | ||
table: MDXTable, | ||
Video: MDXVideo, | ||
}; | ||
|
||
const MDX = ({ body, components }) => { | ||
return ( | ||
<MDXProvider components={{ ...defaultComponents, ...components }}> | ||
<MDXRenderer>{body}</MDXRenderer> | ||
</MDXProvider> | ||
); | ||
}; | ||
|
||
MDX.propTypes = { | ||
body: PropTypes.node, | ||
components: PropTypes.object, | ||
}; | ||
|
||
export default MDX; |