-
Notifications
You must be signed in to change notification settings - Fork 309
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
base: develop
Are you sure you want to change the base?
Refactor Button component. #10824
Conversation
Build files for 93cfaef are ready:
|
Size Change: +2.97 kB (+0.14%) Total Size: 2.13 MB ℹ️ View Unchanged
|
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.
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!
? title || customizedTooltip || ariaLabel | ||
: null; | ||
|
||
const buttonComponent = ( |
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.
Since this variable is not reused anymore, we should get rid of it and render the component inline. What do you think?
*/ | ||
import Tooltip from '../Tooltip'; | ||
|
||
const MaybeTooltip = ( { |
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.
Our convention is to define components using the function
keyword. Let's do that here.
Example:
export default function MaybeTooltip
*/ | ||
import Tooltip from '../Tooltip'; | ||
|
||
const MaybeTooltip = ( { |
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.
Let's define prop types for this component.
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
const SemanticButton = forwardRef( |
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.
Let's define prop types for this component, or somehow reuse from the parent component. While we're at it, it would be nice to update any outdated prop types.
/** | ||
* MaybeTooltip tests. | ||
* | ||
* Site Kit by Google, Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
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.
Looks like this was duplicated.
/** | |
* MaybeTooltip tests. | |
* | |
* Site Kit by Google, Copyright 2021 Google LLC | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* https://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ |
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.
Solid tests here, thank you!
A very nitpicky observation: We seem to be capitalising "Tooltip" in the test case names, which I think we shouldn't. Please let me know what you think, thanks!
/** | ||
* SemanticButton tests. | ||
* | ||
* Site Kit by Google, Copyright 2021 Google LLC |
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.
* Site Kit by Google, Copyright 2021 Google LLC | |
* Site Kit by Google, Copyright 2025 Google LLC |
it( 'should apply danger class when danger prop is true', () => { | ||
const { container } = render( | ||
<SemanticButton danger>Test</SemanticButton> | ||
); | ||
expect( container.firstChild ).toHaveClass( 'mdc-button--danger' ); | ||
} ); | ||
|
||
it( 'should apply inverse class when 8000 inverse prop is true', () => { | ||
const { container } = render( | ||
<SemanticButton inverse>Test</SemanticButton> | ||
); | ||
expect( container.firstChild ).toHaveClass( 'mdc-button--inverse' ); | ||
} ); | ||
|
||
it( 'should apply tertiary class when tertiary prop is true', () => { | ||
const { container } = render( | ||
<SemanticButton tertiary>Test</SemanticButton> | ||
); | ||
expect( container.firstChild ).toHaveClass( 'mdc-button--tertiary' ); | ||
} ); | ||
|
||
it( 'should apply callout classes when callout props are set', () => { | ||
const { container } = render( | ||
<SemanticButton callout calloutStyle="warning"> | ||
Test | ||
</SemanticButton> | ||
); | ||
expect( container.firstChild ).toHaveClass( 'mdc-button--callout' ); | ||
expect( container.firstChild ).toHaveClass( | ||
'mdc-button--callout-warning' | ||
); | ||
} ); |
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.
Not very important, but this could be a nice spot to use it.each
.
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! |
Summary
Addresses issue:
assets/js/googlesitekit/components-gm2/Button.js
#10357Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist