wooorm / xdm

Just a *really* good MDX compiler. No runtime. With esbuild, Rollup, and webpack plugins
http://wooorm.com/xdm/
MIT License
595 stars 18 forks source link

`defaultComponents` configuration prop #108

Closed Zachiah closed 2 years ago

Zachiah commented 2 years ago

Initial checklist

Subject

Adding a prop to the compile configuration called defaultComponents that does the same thing as the components prop does on individual mdx components but to every component.

Problem

I need the functionallity of the components prop on all mdx imports. I'm using solid-start and my pages are the mdx files. This makes a great development experience, but unfortunately I'm unable to pass props to the mdx components. A global defaultComponents configuration prop on the rollup plugin would fix that.

TODO

Solution

I figure it's pretty easy to add the defaultComponents prop to config and just use it in the compiled components as defaults right?

TODO

Alternatives

As far as in general, the alternative would be to make a components object stored in a separate file and import it into every place where you render any mdx components. (Or you could make a mdx component wrapper that renders a component with the props you need).

For me though I would have not use mdx as pages. So basically move them into a different folder and import them with dynamic routes.

Another way this could be solved is by providing an option in config for a component that renders the MDX Component. So in config

{
   rendererComponent: (comp) => <Comp components={{/*my components here*/}} />
}

TODO