-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Conversation
@material-ui/core: parsed: +0.91% , gzip: +0.81% |
|
||
let displayValue = ''; | ||
const BadgeBadge = styled( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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-unstyled/src/BadgeUnstyled/BadgeUnstyled.test.js
Outdated
Show resolved
Hide resolved
packages/material-ui-unstyled/src/BadgeUnstyled/BadgeUnstyled.test.js
Outdated
Show resolved
Hide resolved
|
||
let displayValue = ''; | ||
const BadgeBadge = styled( |
There was a problem hiding this comment.
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.
Done, let me know if you think we should somehow extend it |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Looks like the styles are not transformed at all.. Will need to debug to see what is the issue...
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 |
This comment has been minimized.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
const BadgeRoot = styled( | ||
'span', | ||
{}, | ||
{ muiName: 'MuiBadge', overridesResolver }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work?
{ muiName: 'MuiBadge', overridesResolver }, | |
{ muiName: 'MuiBadge-root', overridesResolver }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mui-org/material-ui/gdbvtf5a5 |
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:
Badge
's component logic should be moved into a newBadgeUnstyled
component. In theBadgeUnstyled
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:components
&componentsProps
properties for the slots inside the component, instead of thecomponent
prop and other potential props associated with different slots.components
&componentsProps
props and remove the previouscomponent
prop.The styling props logic should be removed from the Unstyled component and moved to the core component.
Export a
badgeClasses
const containing all utility classes under one object.Update the core
Badge
component to simply use theBadgeUnstyled
component, providing styled slots for each of the slots of the component. With this conversion, we should update the old JSS styles to the newstyled()
syntax, and split them into different slots components. Additional things we need to do:Unstyled
version.overridesResolver
method that should resolve how the theme overrides will be mapped to the new styles.badgeClasses
when testing if the correct classes are being applied.describeConformance
withdescribeConformanceV5
.Update the docs examples for the component to use the v5 overrides proposal (using the
styled()
API from @material-ui/core/styles) or thesx
prop where possible.Add demo of how to use the
BadgeUnstyled
component