question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create Button with Spinner component

See original GitHub issue

Feature 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.


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 loading prop that rendered the spinner would be a nice, reusable API. But this should only be done if straightforward in practice.
  • The visibility of the spinner should be controllable (via a prop).
  • The component should be present in Storybook.

Implementation Brief

  • Create a new SpinnerButton component in the assets/js/components folder. This component should the following:
    • Render the regular button component using the Spinner component in the trailingIcon property.
    • Proxy all props passed to the component down to the Button element.
    • Define a new state variable processing with false as the default value.
    • Define a new callback onClick that sets the processing state to true, calls the onClick function passed via props, and resets the processing value back to false after the passed onClick callback is executed.
      • Use the async/await approach to call the passed onClick callback to make sure that we reset the processing state only when the callback has finished working.
    • Set the processing variable to isSaving property of the Spinner element.
  • Add a corresponding storybook story for the new component.

Test Coverage

  • N/A

QA Brief

Changelog entry

  • Add a “button with spinner” component.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
techanvilcommented, Aug 11, 2022

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 loading prop in future which could override the internal processing state when set (or something along those lines). But we can cross that bridge if/when we come to it.

IB ✅

1reaction
tofumattcommented, Aug 10, 2022

I think that last phrasing is probably fine. My preference is to integrate it into the existing Button component 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found