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

[base] components -> slots API rename #34693

Merged
merged 29 commits into from Oct 19, 2022

Conversation

michaldudak
Copy link
Member

@michaldudak michaldudak commented Oct 10, 2022

As discussed in #33416 and #34080, this PR:

  • renames the components prop to slots
  • renames the componentsProps prop to slotProps
  • changes casing in slots' fields from Pascal-case to camelCase (Root -> root)

The above changes were implemented only in MUI Base.
In cases where a Base component is used in a Material UI component (Badge, Modal, Popper, Slider), the new props were added to the Material UI code and alongside the old ones, so that there are no breaking changes in the stable package.

Breaking change

  • Change all occurrences of components and componentsProps props in Base components to slots and slotProps, respectively.
  • Change casing of slots' fields to camelCase
-<SwitchUnstyled components={{Root: CustomRoot}} componentsProps={{rail: { className: 'custom-rail' }}} />
+<SwitchUnstyled slots={{root: CustomRoot}} slotProps={{rail: { className: 'custom-rail' }}} />

There is a codemod that can help to deal with the breaking changes.
It will rename the props of unstyled components. However, if there are any custom components wrapping the Base ones, their props won't be affected by the codemod and must by renamed manually.

Run the following command to execute the codemod:

npx @mui/codemod v5.0.0/base-rename-components-to-slots <path>

cc @flaviendelangle

@mui-bot
Copy link

mui-bot commented Oct 10, 2022

Details of bundle changes

@material-ui/core: parsed: +0.24% , gzip: +0.38%
@material-ui/unstyled: parsed: -0.39% 😍, gzip: +0.06%
@mui/material-next: parsed: -0.04% 😍, gzip: +0.21%

Generated by 🚫 dangerJS against babd354

@michaldudak michaldudak force-pushed the base-components-api-rename branch 3 times, most recently from 871b7e8 to 166f967 Compare October 10, 2022 09:46
@mnajdova
Copy link
Member

@michaldudak what do you think about accompanying this change with a codemod? It shouldn't be complicated to be written considering we have similar codemods. We could target all imports in @mui/base for the components.

Another idea for making the transition easier will be to warn in the components if some of the old props are used.

@michaldudak
Copy link
Member Author

what do you think about accompanying this change with a codemod? It shouldn't be complicated to be written considering we have similar codemods. We could target all imports in @mui/base for the components.

Sure, I can try writing one. However, it won't cover (userland) components built on top of Base components, so it may give a false sense of security.

Another idea for making the transition easier will be to warn in the components if some of the old props are used.

We can do this in Material UI as both old and new APIs will be used in parallel. I wouldn't do this immediately after introducing the new API, though. Let's create a gentler introduction in the docs first and then, closer to deprecation we can have a warning.

@siriwatknp
Copy link
Member

The overall changes look good to me. Are you going to add the codemod in this PR or in a separate one?

@michaldudak
Copy link
Member Author

I'll create it in this PR.

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Oct 13, 2022
@@ -63,25 +63,21 @@ The code snippet below shows how to override the root element of the [`BadgeUnst
```

:::warning
If the root slot is customized with both the `component` and `components` props, then `component` will take precedence.
If the root slot is customized with both the `component` and `slots` props, then `component` will take precedence.
Copy link
Member

Choose a reason for hiding this comment

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

This name change makes statements like this so much easier to understand! 🙌

Copy link
Member

@samuelsycamore samuelsycamore left a comment

Choose a reason for hiding this comment

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

Docs look great! I think these concepts are much easier to grasp as a result of these changes, and it's clear right away when you see the differences in the docs.

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.

👍 The codemod looks good to me.

@michaldudak michaldudak merged commit 9f2711b into mui:master Oct 19, 2022
@michaldudak michaldudak deleted the base-components-api-rename branch October 19, 2022 09:35
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
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants