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

hold-to-confirm-vanilla

v0.1.0

Published

Dependency-free hold-to-confirm buttons for vanilla JavaScript, D3, and Svelte.

Readme

hold-to-confirm-vanilla

Dependency-free hold-to-confirm buttons for vanilla JavaScript, D3, and Svelte/SvelteKit. The package is buildless ESM, safe to import during SSR, and automatically injects its small default stylesheet in the browser. TypeScript declarations are included.

Hold-to-confirm button demonstration

Install

npm install hold-to-confirm-vanilla

Vanilla JavaScript

import { holdButton } from 'hold-to-confirm-vanilla';

const control = holdButton(document.querySelectorAll('.delete-button'), {
  duration: 2000,
  variant: 'danger',
  onComplete(element, event, data) {
    element.closest('.item').remove();
  }
});

// Allow the controls to be used again, or remove all listeners.
control.reset();
control.destroy();

The original positional signature also works:

holdButton(document.querySelectorAll('.hold-btn'), onComplete, 2000);

Targets may be a DOM element, selector, iterable/NodeList, or D3 selection. Each control completes only once until reset() is called.

Prefer a native <button> so focus, keyboard behavior, and disabled state work for everyone. If you attach the behavior to another element, your application is responsible for giving it equivalent semantics.

D3

The package understands a D3 selection but does not depend on D3. Bound data is passed as the third callback argument.

import { holdButton } from 'hold-to-confirm-vanilla';

const buttons = d3.selectAll('.delete-button');
const control = holdButton(buttons, (element, event, datum) => {
  console.log('delete', datum);
}, 1500);

control.reset();

Svelte / SvelteKit

The package exports a Svelte action without importing Svelte, so it adds no framework code to your bundle. Importing it during server rendering is safe.

<script>
  import { holdToConfirm } from 'hold-to-confirm-vanilla';

  export let item;
  const remove = () => console.log('delete', item.id);
</script>

<button
  use:holdToConfirm={{
    duration: 1800,
    variant: 'danger',
    onComplete: remove
  }}
>
  Hold to delete
</button>

When the action parameters change, Svelte calls the action's update method. All event listeners and element-level styling are restored on unmount.

Colors and styles

Set CSS custom properties in application CSS:

.delete-button {
  --hold-danger-color: rgb(225 29 72 / 35%);
  --hold-indicator-color: #e11d48;
  --hold-surface-color: white;
}

Or configure them from JavaScript:

holdButton('.delete-button', {
  variant: 'danger',
  colors: {
    danger: 'rgb(225 29 72 / 35%)',
    indicator: '#e11d48',
    surface: 'white'
  },
  onComplete: remove
});

Available color keys / variables are:

| Option | CSS custom property | | --- | --- | | progress | --hold-progress-color | | danger | --hold-danger-color | | success | --hold-success-color | | indicator | --hold-indicator-color | | surface | --hold-surface-color |

The danger variant also recognizes the legacy .delete class. The success variant recognizes .addnew.

Styles are injected once per document by default. To let your bundler load the CSS instead:

import 'hold-to-confirm-vanilla/styles.css';

holdButton('.delete-button', {
  injectStyles: false,
  onComplete: remove
});

For strict CSP configurations, use that explicit CSS import. The stylesheet is also available as the exported holdButtonStyles string, and injectHoldButtonStyles(document) can inject it manually.

Options

| Option | Default | Description | | --- | --- | --- | | duration | 1000 | Required hold time in milliseconds. | | variant | none | danger, success, or an app-defined data variant. | | colors | none | Element-level custom-property values shown above. | | keyboard | true | Enable holding Space or Enter. | | injectStyles | true | Inject the default styles once per document. | | onStart | none | Called when a valid hold begins. | | onCancel | none | Called when a hold ends early. | | onComplete | none | Called after the full duration. |

Callbacks receive (element, event, datum). onCancel also receives a fourth reason argument (cancelled or blurred). Disabled controls and controls with aria-disabled="true" do not start.

Local development

npm test
npm run demo

Then open http://localhost:4173.

License

MIT