Skip to content

Conversation

@mirka
Copy link
Member

@mirka mirka commented Mar 19, 2025

Addresses #100807 (comment)

Proposed Changes

Add a way to override the @wordpress/components secondary Button variant style as frequently done in Calypso.

CleanShot.2025-03-20.at.06.56.15.mp4

Why are these changes being made?

While we may want to abstract this differently in the near future, having this override class available will unblock us quickly for now in a way that's relatively simple to refactor.

Testing Instructions

yarn components:storybook:start and see the documentation for "WP Overrides".

Styles for pseudostates (e.g. :hover) should be looking good for the busy, destructive, disabled, and pressed button states.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@mirka mirka added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it Components Storybook labels Mar 19, 2025
@mirka mirka self-assigned this Mar 19, 2025
@github-actions
Copy link

github-actions bot commented Mar 19, 2025

@matticbot
Copy link
Contributor

matticbot commented Mar 19, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • command-palette-wp-admin
  • help-center
  • notifications
  • odyssey-stats
  • whats-new
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug button-secondary-override on your sandbox.

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@ciampo
Copy link
Contributor

ciampo commented Mar 20, 2025

Better than having many variations of these overrides scattered across the codebase 😓 Do you think we should try to consolidate all those overrides to use this new classname?

@mirka
Copy link
Member Author

mirka commented Mar 20, 2025

Do you think we should try to consolidate all those overrides to use this new classname?

@ciampo From a quick skim, I estimate the number of @wordpress/components secondary Button overrides in the codebase to be less than 20. So it is doable.

However I think the bigger problem is that the standard @automattic/components Button style is basically what this override is trying to emulate. So my estimate here is that we have like 500–800 counts of these now deprecated A8C Buttons in the codebase. These cannot be mass migrated to this flimsy CSS class on top of WP Button 😂 We need a solid commitment to whatever design system we're moving to, and we need a more robust component setup to support it. @Automattic/dotcom-design Let's figure out a plan on Linear.

@mirka mirka marked this pull request as ready for review March 20, 2025 21:44
@mirka mirka requested a review from ciampo March 20, 2025 21:45
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 20, 2025
@mirka mirka requested review from a team and adamwoodnz March 20, 2025 21:46
*/
const meta: Meta< typeof Button > = {
title: 'packages/components/WP Overrides/Button',
component: Button,
Copy link
Member Author

Choose a reason for hiding this comment

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

@ciampo Aside: Apparently react-docgen-typescript doesn't pull types from external dependencies, which WP Button is in this case. It could be that there are config tweaks we could do to make that happen, but I didn't go down that rabbit hole for now. Anyway, that's why the full props table is not showing in Storybook.

Copy link
Contributor

Choose a reason for hiding this comment

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

Mhh, definitely not ideal — maybe we can create, only for the purpose of Storybook, a Button component that more explicitly defines prop types (something like props: React.ComponentProps< typeof Button >, or any other technique) ?

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 kind of thing didn't work either 🫤 I also tried some of these tricks on Storybook 8, but didn't work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, it's annoying but I figured out some workarounds. Will update.


.a8c-components-wp-button {
&.is-secondary:not(:disabled, [aria-disabled="true"], [aria-pressed="true"]) {
box-shadow: inset 0 0 0 $border-width theme.$components-color-gray-300;
Copy link
Member Author

Choose a reason for hiding this comment

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

@ciampo Are the $components-color- variables too much? They're not strictly necessary but I thought some consistency here could be helpful since we're seeing some ad hoc CSS variable-based theming starting to happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the idea because it can quickly spread across the codebase and become really hard to migrate away from.

I honestly think more and more that we should spend some time to create the theming engine that we've been long discussed about. It could live in @automattic/theme-provider and be general enough that, if/when needed, it can be ported to Gutenberg with virtually zero changes.

Copy link
Member

@jasmussen jasmussen Mar 25, 2025

Choose a reason for hiding this comment

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

CC: @jameskoster @youknowriad. Would love to see if parts of this can be reused. Also connecting some dots to this conversation: pgle0O-7K-p2#comment-193

Copy link
Contributor

Choose a reason for hiding this comment

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

We can definitely reuse parts of Saxon's exploratory work — from my point of view, it's mostly a matter of prioritisation and resource assignment.

Copy link
Contributor

@adamwoodnz adamwoodnz left a comment

Choose a reason for hiding this comment

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

Thanks for this!

I've rebased my social buttons PR on this branch again today and it's still working well. I've stripped back the styles on those buttons to the bare minimum; font size and layout rules for the internals. There are still overrides for some heavily branded buttons (eg. Woo, Gravatar), but otherwise it's mostly just theming using --color-accent.

Storybook works for me.

LGTM

@jasmussen
Copy link
Member

jasmussen commented Mar 21, 2025

We need a solid commitment to whatever design system we're moving to, and we need a more robust component setup to support it. Let's figure out a plan on Linear.

Will you ping us there? I'm doing some Linear work today to hopefully set up some ping-groups, probably a design-system related one. But otherwise, just let me know if there was a specific action item, such as feedback on this particular PR. Visualyl this is solid, I'll defer to engineering on the technical side of things. But as-is, the existing Calypso/a8c button component does not seem superior to the core Button, as far as keeping around.

I don't think a manual search/replace of the entire codebase, with the sole purpose of replacing one component with another, is an effort we should undertake. I think the legacy instances can exist until that section gets organically revisited for some other purpose. This is also to say, between completing untangling work, and work on an improved hosting dashboard, there will both be many such opportunities, but there will also be cases where the entire context disappears, gets retired, or deleted.

@mirka mirka merged commit d918707 into trunk Mar 21, 2025
14 checks passed
@mirka mirka deleted the button-secondary-override branch March 21, 2025 11:54
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 21, 2025
@mirka
Copy link
Member Author

mirka commented Mar 21, 2025

@Automattic/team-calypso I'm going to merge now so we don't keep @adamwoodnz in rebase hell, but please leave any comments so I can address them as follow-up 🙏

claudiucelfilip pushed a commit that referenced this pull request Mar 25, 2025
* Button: Support secondary style override

* Rejigger

* Add to tsconfig

* Add decorator for sans-serif font

* Fix up

* Improve theming support

* Fix for destructive and disabled states
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Components Storybook [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants