Skip to content
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

[docs] Able to load doc components inside markdown files #34243

Merged
merged 13 commits into from Sep 28, 2022

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Sep 9, 2022

Follow up on #26774
Fixes this TODO:

// TODO: Only import on demand via @mui/markdown/loader

I want to use the {{ "component" }} synthax on MUI-X to inject some new components.
But I can't because the light of available components is hardcoded in this repository.

  • In the Markdown loader, add a new srcComponents (better name) export that contains the custom components for the current page
  • In MarkdownDocs render the custom components using srcComponents
  • Modify all the files using the markdown loader to spread the props instead of defining them one by one (I had to add one for the components and it's a pain was there a reason not to spread before ?)
  • Test that I can now import custom components from MUI-X ([docs] Use components instead of demos for SelectorsDocs mui-x#6103)

https://deploy-preview-34243--material-ui.netlify.app/material-ui/react-button/

@flaviendelangle flaviendelangle added the docs Improvements or additions to the documentation label Sep 9, 2022
@flaviendelangle flaviendelangle self-assigned this Sep 9, 2022
@flaviendelangle flaviendelangle changed the title Docs component md loader [docs] Use markdown loader for custom components Sep 9, 2022
@mui-bot
Copy link

mui-bot commented Sep 9, 2022

No bundle size changes

Generated by 🚫 dangerJS against c4ee119

@flaviendelangle flaviendelangle marked this pull request as ready for review September 9, 2022 14:41
@siriwatknp
Copy link
Member

siriwatknp commented Sep 12, 2022

@flaviendelangle If my understanding is correct, you want to reuse the component with default props right? The benefit of the new approach is to reduce the demo files, are there other benefits to this?


My comment about the usage:

// From
{{"component": "modules/components/SelectorsDocs.js", "category": "Visible Columns"}}

// To
{{"component": "modules/components/SelectorsDocs.js", "props": { "category": "Visible Columns" }}}

I rather group the properties under "props" to avoid props overriding.

@flaviendelangle
Copy link
Member Author

flaviendelangle commented Sep 12, 2022

@siriwatknp

Concerning the way we pass props, I kept the synthax used for ComponentLinkHeader

{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}

But if we want to change the signature for something more explicit, that's fine for me.
And I agree that being explicit is probably better here.


The benefit of the new approach is to reduce the demo files, are there other benefits to this?

I have two main reasons

  1. For coherence: We have a way of rendering components with the {{"component"}} syntax, but it is only usable for ComponentLinkHeader, which is weird.
    When I arrived at MUI, I had a hard time understanding the logic being those syntaxes. Sometime we have {{"component"}}, sometime {{"demo"}} leading to a 2 lines JS file calling a component.

  2. I have a use case where the demo approach is painful. I would like to render a small table on some doc page with the signature of 1-2 props (the one explained in the same section).
    And it would force me to create a lot of small demo, with a NoSnap suffix to avoid having snapshots of it in our regressions tests.

Something like

{{ "component": "modules/components/PickerValidationPropTable.js", "props: { "propNames": ["shouldDisableMonth"] }}

@flaviendelangle
Copy link
Member Author

@oliviertassinari @siriwatknp if you can take a look

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks fair enough


export default function Page(props) {
const { versions } = props;
return (
<VersionsContext.Provider value={versions}>
<MarkdownDocs demos={demos} docs={docs} demoComponents={demoComponents} />
<MarkdownDocs {...pageProps} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better with?

Suggested change
<MarkdownDocs {...pageProps} />
<MarkdownDocs pageProps={pageProps} />

My concern is about how can we help the future developers to find where these props are coming from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main problem is that it was a major pain to add a new prop on all those files because it was not spread.
And it's very easy to forget one file and have missing content that will be hard to spot.

And I don't see how the current version solves this: help the future developers to find where these props are coming from
If I want to know what is passed to MarkdownDocs, I can check the props it receives.
The hard part when I tried to understand how everything works was to find the loader.js file, which took me some time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @flaviendelangle, the MarkdownDocs is the only component that connects to the {{ }} format anyway. I don't see why we need to pass props as pageProps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only value would be about making how props drill down a bit more explicit. Spreading tends to hide the actual structure of the props that the component receives. If this argument doesn't resonate, then please ignore my initial comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I misread your comment, I thought you wanted to keep today's signature.
No strong opinion between your proposal and mine then.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 26, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 26, 2022
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@siriwatknp siriwatknp added the core Infrastructure work going on behind the scenes label Sep 27, 2022
@siriwatknp siriwatknp changed the title [docs] Use markdown loader for custom components [docs] Able to load doc components inside markdown files Sep 28, 2022
@siriwatknp siriwatknp merged commit c45a3f1 into mui:master Sep 28, 2022
@flaviendelangle flaviendelangle deleted the docs-component-md-loader branch September 28, 2022 08:01
alexfauquette pushed a commit to alexfauquette/material-ui that referenced this pull request Oct 14, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants