Coder Social home page Coder Social logo

vue-button-spinner's Introduction

VueButtonSpinner

npm version

Simple VUE 2 component to create a button spinner. The perfect solution for your submit buttons!

alt tag

Features

  • Show an css loader into the button to indicate the request status.
  • Add a custom html inside the component.
  • Pure CSS loaders, no fonts or images have been used.
  • Different styles for each state: loading, success, error.
  • Available props:
    • 'isLoading' (boolean) to show the spinner
    • 'status' (String | Boolean) allow 'success' or true and 'error' or false.
  • Remember use the .native modifier for the events (docs)

Install

npm install vue-button-spinner

Usage

Example:

[Your .vue component (vue-loader with webpack or use vue-cli projects)]

import VueButtonSpinner from 'vue-button-spinner';

export default {
  name: 'events-form',
  data() {
    return {
      isLoading: false,
      status: '',
    }
  },
  components: {	
    VueButtonSpinner
  },
  methods: {
    onSubmit() {
        this.isLoading = true
      $someRequest('/url', 'GET')
      .then(response => {
        this.isLoading = false
        this.status = true // or success
        setTimeout(() => { this.status = '' }, 2000) // to clear the status :)
      })
      .catch(error => {
        console.error(error)
        this.isLoading = false
        this.status = false //or error
      })
    }
  }
}

[Your HTML code]

<vue-button-spinner
  :is-loading="isLoading" 
  :disabled="isLoading"
  :status="status">
  <span>Submit</span>
</vue-button-spinner>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.