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

Button Component: Update styling to avoid relying on Core Styles making it reusable #6562

Merged
merged 3 commits into from
May 21, 2018

Conversation

youknowriad
Copy link
Contributor

Right now, the button component is relying heavily on core styles. This has some issues:

  • The need to add .core-ui to any place where we want to extend the default button styles
  • The components module is not reusable. One of the goals of the Gutenberg modules is to make them reusable in WP Admin and outside WP Admin as well. If we ever want to publish the components module on npm, it needs to define its own styles.
  • In components heavy application, we don't reuse classNames, we reuse components.

This PR copies the styles from Core into the components-button className to solve this.

Notes

I probably need to update the default styles according to the WP theme cc @jasmussen (I might need some help here)

Testing instructions

Navigate in the Gutenberg UI and check that the styling of the different buttons didn't regress.

@youknowriad youknowriad added the [Feature] UI Components Impacts or related to the UI component system label May 3, 2018
@youknowriad youknowriad self-assigned this May 3, 2018
@youknowriad youknowriad requested a review from a team May 3, 2018 13:58
'is-toggled': isToggled,
'is-busy': isBusy,
'is-link': isLink,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are way too many button states here, but this matches Core, we can try to rethink some of them later.

Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to replace all these booleans with a more enum-like API? e.g. <Button style="link">?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know maybe later, let's not change all the buttons today :)

@afercia
Copy link
Contributor

afercia commented May 3, 2018

There's one thing I've noticed also previously and this PR improves it but still a bit weird:

when I try to make an IconButton have also some text, the position of the icon is OK if the button is a real button, but it's not OK when it's actually a link. Seems it happens in Chrome, Firefox is OK. Seems the text-indent: 4px; doesn't work for links in Chrome. See the Preview button I've made it an IconButton for testing purposes:

Chrome:

screen shot 2018-05-03 at 17 42 48

Firefox:

screen shot 2018-05-03 at 17 42 51

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Agree 100% with the motivation behind this change. It seems to cause a few visual regressions, however.

Various icons are misaligned:

screen shot 2018-05-04 at 11 02 08

screen shot 2018-05-04 at 11 03 34

screen shot 2018-05-04 at 11 06 25

There's a thick black border in a button's pressed/active state:

screen shot 2018-05-04 at 11 04 11

@jasmussen
Copy link
Contributor

Thanks for doing this. I'll see if I can get time today to push a few visual fixes directly to this branch to address Roberts notes.

@jasmussen
Copy link
Contributor

Pushed a fix to the alignment issue. Will look at some other issues with focus styles and admin theme colors in a minute.

@afercia

when I try to make an IconButton have also some text, the position of the icon is OK if the button is a real button, but it's not OK when it's actually a link. Seems it happens in Chrome, Firefox is OK. Seems the text-indent: 4px; doesn't work for links in Chrome. See the Preview button I've made it an IconButton for testing purposes:

Is this specific to this PR or was it also an issue before? The text-indent is definitely there to indent the text when there's an icon, and combined with flex it seems to have worked decently well. However if it doesn't work well in all situations or browsers, then I can take a look (as I added this initially). Feel free to create a new issue and assign me, and I'll look at it if it's not specific to this branch.

@jasmussen
Copy link
Contributor

@youknowriad The theme colors regressed in this, because the CSS classes changed and additional specificity is required. That means the red color that the midnight theme applies to buttons with button-primary no longer works.

I can fix that in our _admin-schemes.scss mixin, but this is going to get messy for a variety of reasons, so before I do that, is there any other way we can approach this, so the core WordPress styles can still theme this?

Otherwise we're overriding buttons, and overriding theme styles. We're already doing this in a few places, sure, but if this is the path forward, we might as well detach these buttons as much as possible from the core UI, and see how many !important's we can remove in the process.

One other challenge with overriding the theme styles is additional colors. In the admin schemes mixin I've tried to limit things to two colors, the primary spot color and the secondary spot color. I've then used SCSS darken to create the additional shades necessary for the candy-colored "saving" indicator.

For the primary button I'm going to need all sorts of shades of the spot-color, for the border, for the pressed state, for the shadow, even the text shadow. I can try and re-create these using darken, but that won't be 100% accurate. The alternative is to duplicate every is-primary style for every admin scheme there is — but then we're duplicating yet again.

Is there any way we can keep using the core "button-primary" styles, instead of re-creating the is-primary style?

@youknowriad
Copy link
Contributor Author

youknowriad commented May 4, 2018

Thanks for the fixes @jasmussen :)

we might as well detach these buttons as much as possible from the core UI, and see how many !important's we can remove in the process.

I'm fine with that, that's exactly what this PR is doing, just leaving the same styles for now.

I can fix that in our _admin-schemes.scss mixin,

I think we can make try to automatically generated this mixin in the future. Like browsing our stylesheets and automatically add additional styles when we detect the usage of theme colors (similar to the RTL plugin). I think with good webpack skills (cc @aduth 😄 ), we can achieve that and don't think about these admin styles anymore. The good thing about such approach is that the theme styles would be loaded by stylesheet and not globally in a single stylesheet.

Is there any way we can keep using the core "button-primary" styles, instead of re-creating the is-primary style?

That defeats the purpose of this PR. We'll style rely on Core style in that case which needs specificity and break reusability.

@jasmussen
Copy link
Contributor

I'll keep thinking about this and take a look next week if I have bandwidth.

@youknowriad
Copy link
Contributor Author

Now that the post-css plugin is merged, I rebased this PR and updated the primary buttons styles to use theme colors. They don't match the current buttons perfectly but they're close enough. What do you think @jasmussen

@jasmussen
Copy link
Contributor

I pushed some fixes, Riad. Can you take a look and see how it feels? Otherwise, feels like we're VERY close!

@youknowriad
Copy link
Contributor Author

Looks good to me :) Let's get some eyes and keep this for the next release.

@jasmussen jasmussen added the Needs Design Feedback Needs general design feedback. label May 16, 2018
@jasmussen
Copy link
Contributor

CC: @karmatosed let me know if you'd like some GIFs as the buttons change a little.

@jasmussen
Copy link
Contributor

Also, the focus styles changed, let's make sure these are kosher.

@jasmussen jasmussen added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label May 17, 2018
@karmatosed karmatosed self-requested a review May 17, 2018 22:32
Copy link
Member

@karmatosed karmatosed 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, thanks.

@youknowriad youknowriad force-pushed the update/button-component branch from e587426 to 2465dc4 Compare May 21, 2018 11:49
@youknowriad youknowriad dismissed noisysocks’s stale review May 21, 2018 15:14

Feedback addressed

@youknowriad youknowriad merged commit ce61b59 into master May 21, 2018
@youknowriad youknowriad deleted the update/button-component branch May 21, 2018 15:15
@mtias mtias added this to the 3.0 milestone Jun 4, 2018

/* Buttons that look like links, for a cross of good semantics with the visual */
&.is-link {
margin: 0;
Copy link
Member

@aduth aduth Jun 4, 2018

Choose a reason for hiding this comment

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

Regression: This selector is more specific than (well, equal specific but out of order from) and thus overrides the margin applied from .components-color-palette_clear:

v4.9.2 #6562
v4.9.2 #6562

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, we shouldn't need margin here for the button. The color palette panel shouldn't be doing a negative margin. It should have a container and spread the options via display: flex & align-items: space-between

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants