Giter Site home page Giter Site logo

gurwinder91 / actor-button Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 71 KB

This is a library to listen to button events and perform some common task such as diable button, hide or show loader on button untill async will complete

Home Page: https://stackblitz.com/edit/actor-btn

JavaScript 20.52% TypeScript 79.48%
angular

actor-button's Introduction

Actor Button

This is a lightweight library developed using latest Angular 9 to show or hide loader on button or disable it when we are doing some asynchronous task. StackBlitz Demo

How to install

npm i actor-btn --save

How to use

  • Add below line to your app.module.ts file

import {ActorBtnModule} from 'actor-btn'

  • Add Below line to your component in which you want to use Actor Btn

import { BtnAction, BtnState } from 'actor-btn';

  • Register your event to btnAction property in ngOnInit lifecycle hook. it helps to trigger it when user will click on button.
 ngOnInit() {
   this.btnAction = {
     act: () => of('sucess').pipe(delay(2000)); // Your async operation.
   }
 }

Note: you can also have promise operation. For reference, please visit StackBlitz Demo

  • In Html of the same component refer to below code.

<button class="btn" [actorBtn]="btnAction" (stateChange)="btnState = $event"> Using Promise <img src="/assets/loader.gif" *ngIf="btnState?.clicked"> <!-- You can have your own loader here.--> </button>

Note: you can listen to btnState event to show and hide loader or to do anything else, according to your use case.

Advance Guide

Actor Btn is also exposing header which you can use to show and hide global loader when you are showing loader on your button. Refer below example for that

ngOnInit() {
   this.btnAction = {
     act: options => this.callingService(options);
   }
 }

callingService(headers: {[name: string]: any }){
  return this.httpClient.get('YOUR URL', headers);
}

you can listen these headers in your interceptor and apply your condition, if actorBtn is present in headers then show or hide your global loader.

actor-button's People

Contributors

gurwinder91 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

jagadeeshmk

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.