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

luna-toggle

v1.0.6

Published

Toggle function for 93digital's Luna starter theme

Readme

Luna Toggle

LunaToggle adds basic toggle functionality to elements across your application, from dropdowns, accordions and modals. The idea behind luna-toggle.js is to create a simple solution that allows developers to take full control over styling and animations.

Example

There are a few data attributes you need to set up toggle correctly. The data-luna-toggle will be applied to your button elements and a single element with the data-luna-toggle-target attribute. Please note that there should only be one data-luna-toggle-target.

Within both data-luna-toggle and data-luna-toggle-target you should apply a unique name that connects the two elements.

There is also a data-luna-toggle-close attribute which once clicked will remove the active state from the assigned toggle elements.

<button type="button" data-luna-toggle="search">Open Search</button>
<form data-luna-toggle-target="search">
  ...
  <button type="button" data-luna-toggle-close="search">Close Search</button>
</form>

Include LunaToggle

  1. Firstly install the LunaToggle package via npm.
npm install luna-toggle
  1. Import the class.
import LunaToggle from 'luna-toggle';
  1. Initialise the class.
// Initialize all toggle elements by data attribute.
const elements = document.querySelectorAll('[data-luna-toggle-target]');

elements.forEach(element => {
  const toggleElement = new LunaToggle(element);
});

// Initialize a specific element.
const searchEl = document.querySelector('[data-luna-toggle-target="search"]');
const searchToggle = new LunaToggle(searchEl);

Toggle will apply an is-active class to both the button element and the target element. It will also apply an is-active-{uniqueId} class to the body, this will allow developers to apply additional styling to elements when a specific element is being toggled.

A simple reveal animation for a modal could be as follows:

[data-luna-toggle-target] {
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;

  &.is-active {
    opacity: 1;
    pointer-events: all;
  }
}

EventListeners

The class comes with two events, open & close. This allows additional functionality to be added when toggling. This can be useful to focus on inputs, or add custom in & out animations after each state.

const searchToggle = document.querySelector('[data-luna-toggle-target="search"]');
const searchInput = document.querySelector('input.search-input');

searchToggle.addEventListener('open', () => {
  searchInput.focus();
});

searchToggle.addEventListener('close', () => {
  searchInput.blur();
});