npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

spinonsubmitjs

v4.0.0

Published

SpinOnSubmitJS is a compact JavaScript library that enhances your form submit buttons with a visual loading spinner, providing immediate and intuitive feedback to users upon submission

Readme

SpinOnSubmitJS

npm version npm npm version npm downloads

SpinOnSubmitJS is a lightweight JavaScript library that enhances form submission buttons with loading indicators, success/error states, and animations. It provides an intuitive way to handle asynchronous actions while providing visual feedback to users.

Installation

Install via npm:

npm install spinonsubmitjs

Features

SpinOnSubmitJS includes:

  • Loading spinner with customizable appearance
  • Success and error states with icons
  • Multiple animation options (checkmark, pulse, shake, fade)
  • Custom loading text/HTML support
  • Automatic form reset capability
  • Flexible positioning and styling
  • CSS variables for easy theming
  • ARIA attributes for accessibility

Usage

1. Import the library:

import { createSpinnerButton } from 'spinonsubmitjs';

2. Create a button and form in your HTML:

<form id="myForm">
   <input type="text" name="firstName" />
   <input type="text" name="lastName" />
   <button id="submitBtn">Submit</button>
</form>

3. Initialize the button:

createSpinnerButton(
   'submitBtn',
   'myForm',
   async (data) => {
       // Your submission logic here
       await submitData(data);
   },
   (error) => {
       console.error('Submission failed:', error);
   },
   {
       spinnerColor: '#3498db',
       position: 'right',
       hideLabelWhileLoading: true,
       showSuccessState: true,
       successAnimation: 'checkmark',
       showErrorState: true,
       errorAnimation: 'shake',
       loadingText: 'Submitting...',
       resetForm: true,
       onLoadingStart: () => console.log('Loading started'),
       onLoadingFinished: () => console.log('Loading finished')
   }
);

Configuration Options

The spinnerOptions object accepts the following properties:

| Option | Type | Default | Description | |--------|------|---------|-------------| | spinnerColor | string | '' | Color of the spinner | | position | string | 'left' | Position of spinner ('left' or 'right') | | hideLabelWhileLoading | boolean | true | Hide button text during loading | | showLabel | boolean | true | Show button label | | loadingText | string | undefined | Text to show during loading | | loadingHtml | string | undefined | HTML to show during loading | | showSuccessState | boolean | false | Show success icon after completion | | showErrorState | boolean | false | Show error icon on failure | | successAnimation | string | 'checkmark' | Success animation type ('checkmark' or 'pulse') | | errorAnimation | string | 'shake' | Error animation type ('shake' or 'fade') | | resetForm | boolean | false | Reset form after error | | onLoadingStart | function | undefined | Callback when loading starts | | onLoadingFinished | function | undefined | Callback when loading ends |

Styling

The library includes CSS variables for easy customization:

:root {
   --sos-spinner-size: 20px;
   --sos-spinner-border-color-light: #f3f3f3;
   --sos-spinner-border-top-color: #3498db;
   --sos-spinner-margin-right: 5px;
   --sos-icon-size: 20px;
   --sos-icon-stroke: 3px;
   --color-success: green;
   --color-danger: red;
}

Events

The button emits a 'loadingFinished' event when the submission process completes:

button.addEventListener('loadingFinished', (event) => {
   const hasError = event.detail.error;
   console.log('Loading finished with error:', hasError);
});

Examples

Here's a complete example showing various features:

createSpinnerButton(
   'submitBtn',
   'myForm',
   (data) => {
       return new Promise((resolve, reject) => {
           setTimeout(() => {
               if (data.firstName && data.lastName) {
                   resolve();
               } else {
                   reject('All fields must be filled!');
               }
           }, 2000);
       });
   },
   (error) => {
       console.error('Error:', error);
   },
   {
       spinnerColor: '#3498db',
       position: 'right',
       hideLabelWhileLoading: true,
       showSuccessState: true,
       successAnimation: 'checkmark',
       loadingText: 'Processing...',
       onLoadingFinished: () => {
           console.log('Form submission completed');
       }
   }
);

License

SpinOnSubmitJS is released under the MIT license. You are free to use, modify, and distribute this software for any purpose, commercial or non-commercial, with proper attribution.