Create Button with Spinner component
See original GitHub issueFeature Description
Implement the Button with Spinner component.
The Button with Spinner component will look like a regular button, but with an activity spinner embedded within it.
- Design Doc: https://docs.google.com/document/d/1DeWo38lcV7lvLFfcmt-mQ0iaxzB4qfiPArs_yZzYkIM/edit#heading=h.vpcddsd4qdav
- Figma: https://www.figma.com/file/vMaCWwr6lpk4PrJWb7jIpz/GA4-Banner-Input?node-id=1082%3A1550
Acceptance criteria
- A component should be created which implements a button with an embedded spinner, as per the design.
- Note: the design doc specifies creating a new component. If possible, updating the existing Button component to incude a
loadingprop that rendered the spinner would be a nice, reusable API. But this should only be done if straightforward in practice.
- Note: the design doc specifies creating a new component. If possible, updating the existing Button component to incude a
- The visibility of the spinner should be controllable (via a prop).
- The component should be present in Storybook.
Implementation Brief
- Create a new
SpinnerButtoncomponent in theassets/js/componentsfolder. This component should the following:- Render the regular button component using the
Spinnercomponent in thetrailingIconproperty. - Proxy all props passed to the component down to the
Buttonelement. - Define a new state variable
processingwithfalseas the default value. - Define a new callback
onClickthat sets theprocessingstate totrue, calls theonClickfunction passed via props, and resets theprocessingvalue back tofalseafter the passedonClickcallback is executed.- Use the
async/awaitapproach to call the passedonClickcallback to make sure that we reset theprocessingstate only when the callback has finished working.
- Use the
- Set the
processingvariable toisSavingproperty of theSpinnerelement.
- Render the regular button component using the
- Add a corresponding storybook story for the new component.
Test Coverage
- N/A
QA Brief
- Go to this storybook story: https://google.github.io/site-kit-wp/storybook/develop/?path=/story/components-spinnerbutton--default-button
- Verify that the spinner button shows the spinner for 5 seconds when you click on it.
Changelog entry
- Add a “button with spinner” component.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Create a Button with a Loading Spinner in HTML & CSS
In today's post I'll be showing you how to use HTML and CSS to create an awesome looking button that features a loading...
Read more >How To Create Loading Buttons - W3Schools
How To Style Loading Buttons. Step 1) Add HTML: Add an icon library, such as Font Awesome, and append icons to HTML buttons:...
Read more >Spinners - Bootstrap
Bootstrap “spinners” can be used to show the loading state in your projects. They're built only with HTML and CSS, meaning you don't...
Read more >How to Create Loading Spinner Button in ReactJS
The loading spinner button is simply a ReactJS component that lets you show an ongoing process. The event triggers when the user clicks...
Read more >Button with loading spinner in reactjs - CodeSandbox
Create Sandbox Sign in. Sandbox Info. Button with loading spinner in reactjs. Adding a loading spinner to your buttons in reactjs.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @eugene-manuilov, that sounds fine to me and it would be compatible with the specced out usage of it in https://github.com/google/site-kit-wp/issues/5277, so I am happy to give this IB a
:white_check_mark:.I guess if we do find a need for a more declarative API then we can always add a
loadingprop in future which could override the internalprocessingstate when set (or something along those lines). But we can cross that bridge if/when we come to it.IB ✅
I think that last phrasing is probably fine. My preference is to integrate it into the existing
Buttoncomponent because this would be a feature that would be useful for many buttons that cause a blocking/loading state. But if—in practice—that complicates the component too much then I’m fine if we don’t.