Skip to content

Refactor Button component. #10824

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

ankitrox
Copy link
Collaborator

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented May 26, 2025

Build files for d06317f are ready:

Copy link

github-actions bot commented May 26, 2025

Size Change: +3.55 kB (+0.17%)

Total Size: 2.13 MB

ℹ️ View Unchanged
Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 62.8 kB 0 B
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB 0 B
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B 0 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.47 kB 0 B
./dist/assets/js/32-********************.js 2.76 kB 0 B
./dist/assets/js/33-********************.js 2.25 kB 0 B
./dist/assets/js/34-********************.js 3.64 kB 0 B
./dist/assets/js/35-********************.js 936 B 0 B
./dist/assets/js/36-********************.js 893 B 0 B
./dist/assets/js/37-********************.js 1.83 kB 0 B
./dist/assets/js/38-********************.js 3.12 kB 0 B
./dist/assets/js/analytics-advanced-tracking-********************.js 903 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/index.js 8.42 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/index.js 9.47 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 8.95 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/index.js 9.47 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 8.96 kB 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/sign-in-with-google/index.js 18.1 kB 0 B
./dist/assets/js/googlesitekit-activation-********************.js 24.3 kB -6 B (-0.02%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 57.9 kB -16 B (-0.03%)
./dist/assets/js/googlesitekit-adminbar-********************.js 37.1 kB +7 B (+0.02%)
./dist/assets/js/googlesitekit-api-********************.js 10.4 kB -2 B (-0.02%)
./dist/assets/js/googlesitekit-components-********************.js 6.81 kB +335 B (+5.18%) 🔍
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB 0 B
./dist/assets/js/googlesitekit-data-********************.js 2.38 kB +1 B (+0.04%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.13 kB -2 B (-0.02%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB -1 B (-0.05%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.9 kB -1 B (0%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10.2 kB 0 B
./dist/assets/js/googlesitekit-datastore-user-********************.js 27.2 kB -1 B (0%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 68.6 kB -18 B (-0.03%)
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B 0 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 977 B 0 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B 0 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 717 B 0 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B 0 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B 0 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 1.36 kB 0 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B 0 B
./dist/assets/js/googlesitekit-i18n-********************.js 4.16 kB 0 B
./dist/assets/js/googlesitekit-main-dashboard-********************.js 150 kB +570 B (+0.38%)
./dist/assets/js/googlesitekit-metric-selection-********************.js 56 kB +6 B (+0.01%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 52.8 kB -37 B (-0.07%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 134 kB +9 B (+0.01%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 210 kB +548 B (+0.26%)
./dist/assets/js/googlesitekit-modules-********************.js 24.1 kB -3 B (-0.01%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 26.6 kB +12 B (+0.05%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 48.9 kB -15 B (-0.03%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 75.2 kB +13 B (+0.02%)
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 36.4 kB +106 B (+0.29%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 33.1 kB -5 B (-0.02%)
./dist/assets/js/googlesitekit-notifications-********************.js 56 kB +451 B (+0.81%)
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B 0 B
./dist/assets/js/googlesitekit-settings-********************.js 137 kB +520 B (+0.38%)
./dist/assets/js/googlesitekit-splash-********************.js 75.1 kB -44 B (-0.06%)
./dist/assets/js/googlesitekit-user-input-********************.js 48.9 kB +432 B (+0.89%)
./dist/assets/js/googlesitekit-vendor-********************.js 313 kB +156 B (+0.05%)
./dist/assets/js/googlesitekit-widgets-********************.js 113 kB +514 B (+0.46%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 65.3 kB +21 B (+0.03%)
./dist/assets/js/runtime-********************.js 1.32 kB 0 B

compressed-size-action

Copy link
Collaborator

@nfmohit nfmohit left a comment

Choose a reason for hiding this comment

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

Brilliant work here, thank you @ankitrox!

I've left a few minor comments for your consideration. Please let me if you have any questions or concerns, thank you!

@ankitrox
Copy link
Collaborator Author

Thank you @nfmohit for reviewing the PR and adding your valuable suggestions.

I've addressed the feedback and sending it your way to review those.

Thanks again!

Copy link
Collaborator

@nfmohit nfmohit left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my feedback, @ankitrox!

I've left a few last-minute comments for your consideration. Please let me know if you have any questions or concerns, thank you!

Comment on lines 66 to 72
MaybeTooltip.defaultProps = {
disabled: false,
tooltip: false,
tooltipTitle: null,
hasIconOnly: false,
tooltipEnterDelayInMS: 100,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use default parameters in the exported function, as defaultProps on functional components will eventually be deprecated (see RFC).

With that said, as we're already refactoring, we should apply this refactor to the parent component too, if capacity permits, thank you!

}
);

SemanticButton.displayName = 'SemanticButton';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for not flagging this earlier, but I don't think the displayName property is necessary here, as it should ideally only be used when the component should be labelled differently than the exported function.

This should also be removed from the parent component, IMO.

Comment on lines 81 to 101
SemanticButton.propTypes = {
children: PropTypes.node,
href: PropTypes.string,
text: PropTypes.bool,
className: PropTypes.string,
danger: PropTypes.bool,
disabled: PropTypes.bool,
target: PropTypes.string,
icon: PropTypes.element,
trailingIcon: PropTypes.element,
'aria-label': PropTypes.string,
inverse: PropTypes.bool,
tertiary: PropTypes.bool,
callout: PropTypes.bool,
calloutStyle: PropTypes.oneOf( [ 'primary', 'warning', 'error' ] ),
title: PropTypes.string,
customizedTooltip: PropTypes.element,
tooltip: PropTypes.bool,
hideTooltipTitle: PropTypes.bool,
tooltipEnterDelayInMS: PropTypes.number,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think icon, trailingIcon, title, customizedTooltip, tooltip, hideTooltipTitle, and tooltipEnterDelayInMS are valid props for this component.

Suggested change
SemanticButton.propTypes = {
children: PropTypes.node,
href: PropTypes.string,
text: PropTypes.bool,
className: PropTypes.string,
danger: PropTypes.bool,
disabled: PropTypes.bool,
target: PropTypes.string,
icon: PropTypes.element,
trailingIcon: PropTypes.element,
'aria-label': PropTypes.string,
inverse: PropTypes.bool,
tertiary: PropTypes.bool,
callout: PropTypes.bool,
calloutStyle: PropTypes.oneOf( [ 'primary', 'warning', 'error' ] ),
title: PropTypes.string,
customizedTooltip: PropTypes.element,
tooltip: PropTypes.bool,
hideTooltipTitle: PropTypes.bool,
tooltipEnterDelayInMS: PropTypes.number,
};
SemanticButton.propTypes = {
children: PropTypes.node,
href: PropTypes.string,
text: PropTypes.bool,
className: PropTypes.string,
danger: PropTypes.bool,
disabled: PropTypes.bool,
target: PropTypes.string,
'aria-label': PropTypes.string,
inverse: PropTypes.bool,
tertiary: PropTypes.bool,
callout: PropTypes.bool,
calloutStyle: PropTypes.oneOf( [ 'primary', 'warning', 'error' ] ),
};

@ankitrox
Copy link
Collaborator Author

Thanks @nfmohit, I have made the changes suggested above. Assigning this to you for another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants