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

@mmargauxx/cookie-banner

v0.1.0

Published

Tiny, framework-agnostic cookie consent banner (vanilla JS + Tailwind). Configurable copy, classes, and callbacks; returns open/close/reset handles.

Downloads

21

Readme

@mmargauxx/cookie-banner

A tiny, framework-agnostic cookie consent banner in vanilla JS/TS, styled with Tailwind. Everything is configurable — copy, links, callbacks, and the classes on every element — and initCookieBanner returns { open, close, reset } handles so you can re-open it later (e.g. from a footer "cookie settings" link) without relying on a global.

  • No runtime dependencies. ~1 kB.
  • Consent-Mode-v2 friendly. You decide what onAccept enables.
  • Themeable. Stock Tailwind palette defaults; override any class.
  • Typed. Ships ESM + CJS + .d.ts.
npm install @mmargauxx/cookie-banner

Usage

import { initCookieBanner } from '@mmargauxx/cookie-banner';

const banner = initCookieBanner({
  text: 'We use analytics cookies to improve your visit.',
  policyHref: '/cookies',
  acceptLabel: 'Accept',
  declineLabel: 'Decline',
  onAccept: enableAnalytics,
});

// re-open from a footer link / policy page:
footerLink.addEventListener('click', banner.open);

The banner mounts itself to document.body, and only opens automatically when no decision has been stored yet. The choice is saved to localStorage under storageKey.

Options

| Option | Type | Default | | --- | --- | --- | | onAccept | () => void \| null | null | | onDecline | () => void \| null | null | | storageKey | string | 'cookie_consent' | | text | string (HTML allowed) | 'We use analytics cookies to improve your visit.' | | policyHref | string \| null | '/cookies' — pass null/'' to omit the link | | policyLabel | string | 'Learn more' | | acceptLabel | string | 'Accept' | | declineLabel | string | 'Decline' | | classes | Partial<CookieBannerClasses> | stock Tailwind (see below) |

Returns — CookieBannerHandle

| Handle | Effect | | --- | --- | | open() | Show the banner. | | close() | Hide the banner. | | reset() | Clear the stored decision and re-open. |

createCookieBanner(opts) → string

Also exported: returns the banner's HTML as a string (no DOM side effects) if you want to control where/when it's inserted, or render it server-side.

Styling

The defaults use stock Tailwind palette classes (slate / emerald), so the banner looks right in any project that runs Tailwind. Override any subset:

initCookieBanner({
  classes: {
    accept: 'flex-1 bg-indigo-600 text-white hover:bg-indigo-700 px-5 py-2.5 rounded-full text-sm font-medium cursor-pointer',
    // wrapper, text, link, actions, decline are kept at their defaults
  },
});

Overridable keys: wrapper, text, link, actions, decline, accept.

⚠️ Tailwind purging. The classes live inside this package's JS, so Tailwind won't see them when scanning your source and will purge them. Add the package to your content globs:

// tailwind.config.js
export default {
  content: [
    './src/**/*.{html,js,ts,jsx,tsx}',
    './node_modules/@mmargauxx/cookie-banner/dist/**/*.js',
  ],
};

If you override all the classes with your own (already-scanned) utilities, this isn't needed. Not using Tailwind at all? Pass your own classes, or your own plain CSS class names and ship the CSS yourself.

Wiring up analytics (Consent Mode v2)

Two pieces live in your app, not in this package.

1. Set the Consent Mode v2 default in your document <head>, before GA loads, so Google respects consent from the first paint:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  gtag('js', new Date());
  gtag('consent', 'default', {
    ad_storage: 'denied', ad_user_data: 'denied',
    ad_personalization: 'denied', analytics_storage: 'denied',
    wait_for_update: 500,
  });
  gtag('config', 'G-XXXX', { send_page_view: false });
</script>

2. Flip consent on accept (and re-enable on return visits):

import { initCookieBanner } from '@mmargauxx/cookie-banner';
import Clarity from '@microsoft/clarity';

function enableAnalytics() {
  if (typeof window.gtag === 'function') {
    window.gtag('consent', 'update', { analytics_storage: 'granted' });
  }
  Clarity.init('YOUR_CLARITY_ID');
}

if (localStorage.getItem('cookie_consent') === 'accepted') enableAnalytics();
initCookieBanner({ onAccept: enableAnalytics });

Development

npm install
npm run example     # vite demo at http://localhost:5173
npm run build       # dist/ (esm + cjs + d.ts) via tsup
npm run typecheck
npm test            # vitest (jsdom)

Publishing

npm run build
npm publish         # scoped package; publishConfig.access is already "public"

License

MIT