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

stimulus-toggle-kit

v1.1.0

Published

A Stimulus controller for dynamic element toggling based on user input. Supports dropdowns, checkboxes, and radio buttons to show or hide elements based on configured data attributes.

Readme

Toggle Controller

A lightweight Stimulus controller to dynamically toggle the visibility of elements based on the value of user inputs such as dropdowns, checkboxes, and radio buttons. It uses data attributes to define toggle sets and conditions.

Features

  • Supports dropdowns, checkboxes, and radio buttons.
  • Easily configurable with data-* attributes.
  • Handles toggling for grouped or individual elements.
  • Supports a11y by toggling aria-hidden attribute, setting aria-controls on the toggle controls, as well as aria-expanded when necessary.

Installation

Install via npm:

npm add stimulus-toggle-kit

Usage

  1. Import the controller into your Stimulus setup:
import { Application } from "@hotwired/stimulus";
import ToggleController from "toggle-controller";

const application = Application.start();
application.register("toggle", ToggleController);
  1. Configure your HTML with the required data-* attributes.

Basic example:

<div data-controller="toggle">
    <!-- select controller target -->
    <select data-toggle-target="select" data-action="toggle#changed">
        <option>Select an option</option>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
    </select>

    <!-- checkbox controller target -->
    <input type="checkbox" data-toggle-target="checkbox" data-action="toggle#changed" value="option3">

    <!-- radio controller target -->
    <div data-toggle-target="radio">
        <label>
          <input type="radio" data-action="toggle#changed" name="option" value="option4">
          Option 4
        </label>
        <label>
          <input type="radio" data-action="toggle#changed" name="option" value="option5">
          Option 5
        </label>
    </div>

    <!-- element controller targets -->
    <div data-toggle-target="element" data-values="option1,option3,option4">
        Content for options 1, 3 or 4
    </div>
    <div data-toggle-target="element" data-values="option2,option5">
        Content for options 2 or 5
    </div>
</div>

More advanced example, using multiple toggle sets:

<div data-controller="toggle">
  <!-- set1 controller targets -->
  <select data-toggle-target="select" data-action="toggle#changed" data-toggle-set="set1">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
  </select>
  <input type="checkbox" data-toggle-target="checkbox" data-action="toggle#changed" value="option3" data-toggle-set="set1">

  <!-- set2 controller targets -->
  <select data-toggle-target="select" data-action="toggle#changed" data-toggle-set="set2">
    <option value="option4">Option 4</option>
    <option value="option5">Option 5</option>
  </select>
  <input type="checkbox" data-toggle-target="checkbox" data-action="toggle#changed" value="option6" data-toggle-set="set2">

  <!-- element controller targets -->
  <div data-toggle-target="element" data-values="option1,option3" data-toggle-set="set1">
    Content for Option 1 or 3 from set1
  </div>
  <div data-toggle-target="element" data-values="option2" data-toggle-set="set1">
    Content for Option 2 from set1
  </div>
  <div data-toggle-target="element" data-values="option4,option6" data-toggle-set="set2">
    Content for Option 4 or 6 from set2
  </div>
  <div data-toggle-target="element" data-values="option5" data-toggle-set="set2">
    Content for Option 5 from set2
  </div>
</div>

Data Attribute Reference

  • data-toggle-set (optional)
    • Specifies the toggle set(s) the element belongs to. Comma-separated for multiple sets.
  • data-values
    • Defines the value(s) that should make the element visible. Comma-separated for multiple values.
  • data-toggle-target
    • Indicates the target type
    • element - this will make the element a toggle target
    • select - this will make the select element a toggle control
    • checkbox - this will make the checkbox element a toggle control
    • radio - this will make the radio elements within the parent element toggle controls
      • Please note, all of the radio buttons of the same name should be wrapped in a containing div with the data-toggle-target="radio" attribute. See example above.