-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layout props #189
Layout props #189
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇 Looking good so far!
Mind adding a test to ensure that props are passed to the layout?
packages/mdx/mdx-hast-to-jsx.js
Outdated
'\n' + | ||
`export default ({components}) => <MDXTag name="wrapper" ${layout ? `Layout={${layout}}` : ''} components={components}>${jsxNodes | ||
`export default (props) => <MDXTag name="wrapper" ${layout ? `Layout={${layout}} layoutProps={objectWithoutProperties(props, ['components'])}` : ''} components={props.components}>${jsxNodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the output JSX still requires babel parsing maybe it makes sense to use destructuring?
export default ({ components, ...props }) =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! That way I won't be breaking anything, and the change set will be cleaner.
The component exported by MDX files recognized only one prop: components. That was the only prop being passed to the custom layout component, which made MDX very hard to integrate with tools like Gatsby. This change passes all props to the custom layout component, not only "components". Fixes #187.
Done. I added that test to @mdx-js/runtime tests, I hope that's fine. There's also a @mdx-js/tag test which tests if |
I'm not sure why tests for Node 8.11.3 are failing. I tried locally with that version and it works. |
This is great, thanks! Looks like the failed test was a timeout blip that happens every once in a while. Just reran it and all seems good 💟 |
* Git-ignore Lerna's debug log file * Pass rest of the props to custom Layout component The component exported by MDX files recognized only one prop: components. That was the only prop being passed to the custom layout component, which made MDX very hard to integrate with tools like Gatsby. This change passes all props to the custom layout component, not only "components". Fixes #187.
I'm sure that this solution for layout props isn't ideal, but it's a crucial piece of the puzzle for integrating MDX into some tools. The API can always be changed later. Also, this is a breaking change to anyone who decided to use the
components
prop in their MDX file, because now that should becomeprops.components
.With this change we'll be able to do stuff like this:
posts/layout-props.mdx
:pages/index.js
:Would resolve: