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

cooldown-btn

v0.0.3

Published

An Angular directive that prevents button spam by adding a cooldown period after a specified number of clicks. Perfect for preventing duplicate form submissions, API calls, or any action that shouldn't be triggered too frequently.

Readme

Cooldown Button Directive

An Angular directive that prevents button spam by adding a cooldown period after a specified number of clicks. Perfect for preventing duplicate form submissions, API calls, or any action that shouldn't be triggered too frequently.

Features

Click Limiting - Set maximum clicks before cooldown activates Customizable Cooldown - Configure cooldown duration in milliseconds State Tracking - Emit events when entering/exiting cooldown state Accessibility - Automatically handles disabled attribute and ARIA states Framework Agnostic - Works with any HTML element (buttons, anchors, divs, etc.) Memory Safe - Automatically cleans up timers on component destruction

Installation

npm install cooldown-btn

Usage

Import the Directive

Standalone Components (Angular 14+)

For standalone components, import CooldownBtnDirective directly:

import { Component } from '@angular/core';
import { CooldownBtnDirective } from 'cooldown-btn';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [CooldownBtnDirective],
  templateUrl: './example.component.html'
})
export class ExampleComponent {
  // Your component logic
}

NgModule-Based (Angular 14+)

For module-based applications, import into your module:

import { NgModule } from '@angular/core';
import { CooldownBtnDirective } from 'cooldown-btn';

@NgModule({
  imports: [CooldownBtnDirective],
  declarations: [ExampleComponent],
})
export class ExampleModule { }

Basic Example

<button CooldownBtn>
  Click Me
</button>

This applies a default cooldown of 1 second after 1 click.

Customized Cooldown

<button 
  CooldownBtn 
  [maxClicks]="3" 
  [coolDownTime]="2000"
  (coolDownState)="onCooldownChange($event)">
  Click Me (3 max, 2s cooldown)
</button>
export class ExampleComponent {
  onCooldownChange(isInCooldown: boolean) {
    console.log('Cooldown active:', isInCooldown);
  }
}

Real-World Examples

Prevent Double Form Submission

<button 
  CooldownBtn 
  [maxClicks]="1" 
  [coolDownTime]="3000"
  (click)="submitForm()">
  Submit Form
</button>

Rate-Limited Action

<button 
  CooldownBtn 
  [maxClicks]="5" 
  [coolDownTime]="10000"
  (coolDownState)="updateUI($event)">
  Refresh Data
</button>

Visual Feedback Example

export class MyComponent {
  clicks = 0;
  isCooldown = false;

  onClick() {
    this.clicks++;
  }

  coolDownState(state: boolean) {
    this.isCooldown = state;
  }
}
<button 
  CooldownBtn 
  [maxClicks]="3" 
  [coolDownTime]="2000"
  (click)="onClick()"
  (coolDownState)="coolDownState($event)"
  [class.cooldown-active]="isCooldown">
  Clicked: {{ clicks }}
</button>
.cooldown-active {
  opacity: 0.5;
  cursor: not-allowed;
}

API Reference

Inputs

| Input | Type | Default | Description | |-------|------|---------|-------------| | maxClicks | number | 1 | Maximum number of clicks allowed before cooldown activates | | coolDownTime | number | 1000 | Cooldown duration in milliseconds |

Outputs

| Output | Type | Description | |--------|------|-------------| | coolDownState | EventEmitter<boolean> | Emits true when cooldown starts, false when it ends |

Behavior

  1. Click Tracking: The directive counts clicks on the element
  2. Cooldown Activation: After maxClicks is reached, the element enters cooldown
  3. Element Disabling:
    • For buttons: Sets disabled property to true
    • For other elements: Sets aria-disabled="true" and pointer-events: none
  4. Event Prevention: During cooldown, click events are prevented and stopped from propagating
  5. Cooldown Exit: After coolDownTime milliseconds, the element is re-enabled and click count resets

Use Cases

  • Form Submissions - Prevent duplicate submissions
  • API Calls - Rate limit expensive operations
  • Game Actions - Implement cooldown mechanics
  • Social Interactions - Prevent spam liking/favoriting
  • Data Refresh - Limit how often users can refresh data

Browser Support

Works with all modern browsers that support Angular 14+.

Requirements

  • Angular 14+
  • TypeScript 4.6+