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

[Badge] Create unstyled component & move to emotion #23745

Merged
merged 60 commits into from
Dec 10, 2020

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Nov 27, 2020

This PR creates an unstyled version of the Badge component, and changes the styling engine to @material-ui/styled-engine.

Steps necessary for making the changes:

  1. The Badge's component logic should be moved into a new BadgeUnstyled component. In the BadgeUnstyled component there should not be any styles associated with the component (these will go into the core Badge component). Additional things we need to do:
  • Add a mapping for the classes as done here.
  • Use the components & componentsProps properties for the slots inside the component, instead of the component prop and other potential props associated with different slots.
  • Update the API to contain the new components & componentsProps props and remove the previous component prop.
  1. The styling props logic should be removed from the Unstyled component and moved to the core component.

  2. Export a badgeClasses const containing all utility classes under one object.

  3. Update the core Badge component to simply use the BadgeUnstyled component, providing styled slots for each of the slots of the component. With this conversion, we should update the old JSS styles to the new styled() syntax, and split them into different slots components. Additional things we need to do:

  • Update the typings to extend the typings of the Unstyled version.
  • Add an overridesResolver method that should resolve how the theme overrides will be mapped to the new styles.
  • Update the tests to use the badgeClasses when testing if the correct classes are being applied.
  • Replace the describeConformance with describeConformanceV5.
  1. Update the docs examples for the component to use the v5 overrides proposal (using the styled() API from @material-ui/core/styles) or the sx prop where possible.

  2. Add demo of how to use the BadgeUnstyled component

@mui-pr-bot
Copy link

mui-pr-bot commented Nov 27, 2020

@material-ui/core: parsed: +0.91% , gzip: +0.81%

Details of bundle changes

Generated by 🚫 dangerJS against 733c140

@mnajdova mnajdova changed the title [WIP][Badge] Create unstyled component & move to emotion [Badge] Create unstyled component & move to emotion Nov 30, 2020

let displayValue = '';
const BadgeBadge = styled(
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks really ugly :( I wonder if we should rename the BadgeRoot to BadgeWrapper and the BadgeBadge to BadgeRoot

Copy link
Member Author

@mnajdova mnajdova Nov 30, 2020

Choose a reason for hiding this comment

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

With this we currently have a bug, where the theme's variants go to the Root instead of the badge component, which is wrong with this component..

For example, adding a dashed variants results in the following:

image

Which in my opinion is wrong (it should affect only the badge itself)

Copy link
Member

Choose a reason for hiding this comment

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

From my perspective, the current names are as good as they could get. I think that it surfaces that we could change the composition API of the component. The current approach is a bit weird.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could also leave this for a follow-up PR so that we don't pollute this one

Copy link
Member Author

Choose a reason for hiding this comment

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

I will leave this comment open and we can resolve it after this one is merged, so we will avoid unnecessary changes as part of this PR. Would that work?

Copy link
Member

Choose a reason for hiding this comment

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

💯, the point around the weird API isn't specific to unstyled. It's more about how <Badge> could be a <BadgeContainer>, it's not really a badge as developers can find in other UI libraries.

@mnajdova mnajdova marked this pull request as ready for review November 30, 2020 11:41
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.

Do we miss an unstyled customization demo? Maybe reproduce Ant Design?

packages/material-ui/src/styles/experimentalStyled.js Outdated Show resolved Hide resolved

let displayValue = '';
const BadgeBadge = styled(
Copy link
Member

Choose a reason for hiding this comment

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

From my perspective, the current names are as good as they could get. I think that it surfaces that we could change the composition API of the component. The current approach is a bit weird.

@mnajdova
Copy link
Member Author

Do we miss an unstyled customization demo? Maybe reproduce Ant Design?

Done, let me know if you think we should somehow extend it

@oliviertassinari

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@mnajdova
Copy link
Member Author

There is an issue on RTL

Looks like the styles are not transformed at all.. Will need to debug to see what is the issue...

Should the class name be .css-gd7jph-MuiBadge-root and the styles only applied once?

We can rename the class 👍 , don't have a strong opinion. I don't understand what you are referring to with the styles being applied only once. For each props combination we have one classname. If we have color: "primary", we cannot for example apply the classname you have on the screenshot as the background color would need to be different. I am probably not understanding your point on this one :)

@oliviertassinari

This comment has been minimized.

@@ -317,6 +342,10 @@ Badge.propTypes = {
* @default false
*/
showZero: PropTypes.bool,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
Copy link
Member

Choose a reason for hiding this comment

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

A note for later, I think that it would be great to add a link to the system page of the documentation as we do for the classes prop:

Capture d’écran 2020-12-07 à 16 15 49

It should probably done in the documentation generator to be done once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, we can add it, will leave the comment open for visibility

packages/material-ui/src/Badge/Badge.js Outdated Show resolved Hide resolved
const BadgeRoot = styled(
'span',
{},
{ muiName: 'MuiBadge', overridesResolver },
Copy link
Member

Choose a reason for hiding this comment

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

Would this work?

Suggested change
{ muiName: 'MuiBadge', overridesResolver },
{ muiName: 'MuiBadge-root', overridesResolver },

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used as key for the overrides inside the theme, not sure we want to actually change it. Should we maybe add a new prop for the class suffix we want to have?

Copy link
Member

@oliviertassinari oliviertassinari Dec 7, 2020

Choose a reason for hiding this comment

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

I wouldn't be against adding a second option to isolate the theming and CSS class name tip use cases. I doubt that developers should be able to override MuiBadge-badge with the theme. However, it's likely a topic for a different effort.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried to work around this, the problem is that whatever we pass in the label, will be used for both the component display name and classname suffix. It would feel awkward seeing component names like MuiBadge-root. This is currently on all slots components at the moment. I would even suggest we use as muiName: 'MuiBadge', MuiSlider, MuiSliderTrack etc, to have better display names on the components. The utility classes are anyway added to the components, so people can easily copy them.

Let me know what do you think and I'll update the migrated dcomponents.

Copy link
Member

@oliviertassinari oliviertassinari Dec 11, 2020

Choose a reason for hiding this comment

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

My motivation for the proposal was to mitigate this issue #23841 (review). to make it easier to match the styles seen in the dev tools with the global class name to use to customize them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got ya, created #23964 hopefully it will help to resolve the confusion

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 9, 2020
@mnajdova mnajdova requested review from eps1lon and mbrookes and removed request for mbrookes and eps1lon December 9, 2020 10:31
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 9, 2020
@vercel
Copy link

vercel bot commented Dec 10, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mui-org/material-ui/gdbvtf5a5
✅ Preview: https://material-ui-git-feat-convert-badge-to-v5.mui-org.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: badge This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants