-
Notifications
You must be signed in to change notification settings - Fork 535
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
Button: Make button visuals overridable by sx #3683
Button: Make button visuals overridable by sx #3683
Conversation
🦋 Changeset detectedLatest commit: ff416d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
src/Button/Button.tsx
Outdated
if (props.leadingIcon) cssSelectorList.push(`& [data-component="leadingVisual"]`) | ||
if (props.trailingIcon) cssSelectorList.push(`& [data-component="trailingVisual"]`) | ||
if (props.trailingAction) cssSelectorList.push(`& [data-component="trailingAction"]`) |
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.
These lines are repetitive and I am happy to take into a loop but thought keeping this way makes them more readable. Let me know if you have any feedback!
a89b0dd
to
2d39e3f
Compare
c687771
to
2c05542
Compare
Thanks @broccolinisoup! Will take a look at the tests 👀 Wanted to ask you a quick question, is it possible at all to use a CSS Custom Property when const ButtonComponent = forwardRef(({children, sx: sxProp = defaultSxProp, ...props}, forwardedRef): JSX.Element => {
let sxStyles = sxProp
// grap the button props that have associated data attributes in the styles
const {block, size, leadingIcon, trailingIcon, trailingAction} = props
const style = {};
if (sxProp !== null && Object.keys(sxProp).length > 0) {
sxStyles = generateCustomSxProp({block, size, leadingIcon, trailingIcon, trailingAction}, sxProp)
if (sxProp.color) {
style['--button-color'] = sxProp.color;
}
}
return (
<ButtonBase ref={forwardedRef} as="button" sx={sxStyles} type="button" style={style} {...props}>
{children}
</ButtonBase>
)
}) as PolymorphicForwardRefComponent<'button', ButtonProps> And then in the styles we use it like:
Or would this not really work out the same way? Just was thinking of a simple way we could explicitly opt in things to this value but totally understand if it's not really the same thing at all as the custom sx prop seems to be doing a ton. |
Hey @joshblack that totally works for the
For example to make sure sx styles are applied properly to the
Thanks again, I appreciate your input 🙏🏻 |
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 love to see how this works out over in dotcom 🤞 Let me know if I missed anything since the last time we spoke.
@joshblack All looking good! Checks are green and tested in review lab to see the button that is originally reported as an issue https://github.com/github/github/pull/291667 I'm merging this - let me know if you have any concern! |
As described in the issue, a regression introduced in #3447 where the icon colors became not overridable by the sx prop in Button.
This issue originally goes back to introducing data-attributes selectors to Button (#2792) and it came with some challenges with overriding styles with sx. At the time, we wrote a custom CSS selector to take data attributes into account while applying the sx styles. However, the new icon styles that are introduced in #3447, are not included in the custom selectors.
Note: We won't have to use this css selectors when we move to css modules ✨ but for now, it seems to be doing what we want.
All that said, I am always open to any kinds of feedback 🙏🏻
Closes https://github.com/github/primer/issues/2576
Screenshots
Before
After
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.