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][material-next] Add Badge component #37850

Merged
merged 26 commits into from
Jul 26, 2023

Conversation

DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Jul 6, 2023

Badge issue: #37835
Material You umbrella issue: #29345

Closes #37835

Changes

  • Copy Badge from material
  • Migrate to Typescript
  • Remove deprecated components and componentsProps
  • Drop ThemeProvider in favor of CssVarsProvider
  • Implement Material You design specs
  • Add component playground to v5 docs
  • Refactor styles to use component CSS Variables

Breaking changes

https://github.com/mui/material-ui/pull/37850/files#diff-9548901bac6f3274c402a36fad9b83afe49cf663499e51d9fe306195d149a4a1

CSS Variables

I was heavily inspired by Joy Badge's variables, but didn't use exactly the same. As naming convention, I followed Material You's token convention in which component variables have the --md-comp prefix followed by the component's name, so in this case it is: --md-comp-badge

Playground

Link: https://deploy-preview-37850--material-ui.netlify.app/material-ui/react-badge/#material-you-version

Screen.Recording.2023-07-13.at.12.53.41.mov

@DiegoAndai DiegoAndai added design: material This is about Material Design, please involve a visual or UX designer in the process component: badge This is the name of the generic UI component, not the React module! v6.x design: material you labels Jul 6, 2023
@DiegoAndai DiegoAndai self-assigned this Jul 6, 2023
@mui-bot
Copy link

mui-bot commented Jul 6, 2023

Netlify deploy preview

@mui/material-next: parsed: +2.36% , gzip: +1.55%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 257dac5

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 11, 2023
Signed-off-by: Diego Andai <diego@mui.com>
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 11, 2023
@DiegoAndai DiegoAndai marked this pull request as ready for review July 13, 2023 16:32
@DiegoAndai DiegoAndai marked this pull request as draft July 13, 2023 18:16
@DiegoAndai DiegoAndai marked this pull request as ready for review July 14, 2023 22:11
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Looks great, left few comments for consideration.


Color options were changed to match Material You:

- `"default"`, `"info"`, `"success"`, and `"warning"` were removed and are no longer supported out-of-the-box
Copy link
Member

Choose a reason for hiding this comment

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

Should we still keep these? We dsicussed that it may be useful to define these in the team. cc @danilo-leal

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 discussed with @danilo-leal and we will work on a Material UI Material You theme that makes upgrading smoother (for example, having these colors) and that makes sense with the Material You color system.

I'll be working on developing this, but there are still things to figure out, like for example which would be the default theme, the Material You default theme, or the Material UI MY theme.

I don't want to block the components progress while we figure out the Material UI MY theme, so for now I think we should continue the work using the Material You default theme (which doesn't have these colors) and when we have more clarity we can go back to this. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

My worry with this is that we would introduce a breaking change and later add back these values. It could be frustrating for people to have to do some changes, and revert them later.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, what we should do then is add the "info", "success", and "warning" to the palette following Material You's custom colors guidelines: https://m3.material.io/styles/color/the-color-system/custom-colors.

Regarding the "default" color, that's not really a color but rather the badge has no background:

Screenshot 2023-07-21 at 08 44 32

Do you think we should keep that one as well?

I'll work with @zanivan on this.

Copy link
Member

Choose a reason for hiding this comment

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

In v5 we started with removing "default" from the color values, I wonder why it is still there in the Badge. The reasoning for it was that default is not a color, we should use as default some valid color value. I propose we drop it.

Comment on lines 46 to 47
- `standard` renamed to `large`, which is still the default
- `dot` renamed to `small`
Copy link
Member

Choose a reason for hiding this comment

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

We use size as a name for the sizes. I propose keeping all variant values as deprecated to easy up the migration, and use a new size prop for this instead. We can deprecate the whole variant prop with an appropriate deprecation message.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mnajdova I agree with naming the prop size.

About keeping the variant prop, I think it would be better to remove it right away, because:

  • Migrating can be covered with a codemod
  • Keeping it would complicate and bloat the code

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we can likely get more people to try it early if we don't introduce many breaking changes with the first version, but happy to experiment with what you suggest.

I see two ways going forward:

  • deprecate props and move forward with minimal breaking changes
  • introduce breaking changes together with a codemod for them at the moment they are implemented

So we should either, add a codemod now, or deprication, one of these two needs to be implemented.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, I'll look into both options and let you know which one I think is better.

@DiegoAndai
Copy link
Member Author

DiegoAndai commented Jul 24, 2023

Hey @mnajdova I rolled back both deprecations 😊:

  • Bring back the variant prop with a deprecation message
  • Bring back "info", "warning", "success", and "default" color options. I did maintain the change that "error" is the new default though as that's the only color used in the Material You specs.

You can check the new colors in the playground: https://deploy-preview-37850--material-ui.netlify.app/material-ui/react-badge/#material-you-version

@zanivan the colors are looking great! 🎉 here's a picture of them being used in the badges (in order: "primary", "error", "info", "warning", and "success"):

badges

A couple of questions regarding the colors:

  • May we use the tone 20 for the on dark tokens? (onInfo, onWarning, onSuccess). In Figma, the tone 15 is used, but all the other colors in Material You use tone 20. Doing this would make the implementation a little easier and the color usage more consistent. The picture is using the tone 20 of each color, I think it looks nice 👍🏼
  • The warning color on light mode is the only one that I think might need a little improving, I think it looks a little too brown and it should look more yellow or orange

@zanivan
Copy link
Contributor

zanivan commented Jul 24, 2023

May we use the tone 20 for the on dark tokens?

Yep, absolutely! I'll update it on Figma.

The warning color on light mode is the only one that I think might need a little improving, I think it looks a little too brown and it should look more yellow or orange

I'll change the Hue a bit—I wouldn't saturate it, though. MY seems less saturate, so yellow or orange could be tricky and look a bit off from the others, since those are colors with more perceived light.

@DiegoAndai
Copy link
Member Author

@mnajdova another question, regarding this comment, should we just remove the classes or is there anything else to do?

'colorTertiary',
'overlapRectangular',
'overlapCircular',
// TODO: v6 remove the overlap value from these class keys
Copy link
Member

Choose a reason for hiding this comment

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

@DiegoAndai we don't want to have in v6 combination of props in the classes. If someone wants to combine these two, they can create selector containing both classes. Each of the keys in classes should define one prop + value combination.

@zanivan
Copy link
Contributor

zanivan commented Jul 25, 2023

@DiegoAndai I tried to bump the warning colors a bit to the yellow tones, I believe it works. Here's the Figma link

image

@DiegoAndai
Copy link
Member Author

@mnajdova I removed the combined classes, added the corresponding migration section, and updated tests. Here's a sandbox of the new usage creating a CSS selector to combine anchorOrigin and overlap classes: https://codesandbox.io/s/next-badge-overlap-anchor-class-k7vwf7?file=/src/App.tsx

@zanivan updated the warning color 🙌🏼:

badges-2

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Looks good, left few final comments, nothing big. Well done! The PR description is very detailed, love it!

packages/mui-material-next/migration.md Outdated Show resolved Hide resolved
packages/mui-material-next/src/Badge/Badge.tsx Outdated Show resolved Hide resolved
@DiegoAndai DiegoAndai merged commit 579fe2d into mui:master Jul 26, 2023
21 checks passed
@DiegoAndai DiegoAndai deleted the material-you-badge branch July 26, 2023 17:02
@DiegoAndai DiegoAndai added v7.x and removed v6.x labels Dec 26, 2023
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! design: material you design: material This is about Material Design, please involve a visual or UX designer in the process v7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Badge][material-next] Add Badge component
4 participants