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 🙏

© 2024 – Pkg Stats / Ryan Hefner

classtoggler

v1.4.2

Published

A simple css class toggler for all kind of dropdowns, accordions, menus, optional form elements also with a grouping option.

Downloads

92

Readme

A simple css class toggler for all kind of dropdowns, accordions, menus, optional form collapsing elements also with a grouping option.

Demo

check out the DEMO

Usage

Import & initiate

1. npm i classtoggler
2. import { classtoggler, classtogglerRemoveClassByGroup, classtogglerUpdate, classtogglerForm } from 'classtoggler';
3. classtoggler();
4. if you need to close the group use: classtogglerRemoveClassByGroup('your-group-name');
5. if you need to update the classtoggler use classtogglerUpdate();
6. if you need the form control use classtogglerForm('#unique-form-selector')

Markup Options

  1. data-toggler-target - target the element
  2. data-toggler-class - define the css class name
  3. data-toggler-group - define the group
  4. data-toggler-form-target - use for targeting elements via radio & checkbox inputs

Default active classes

   <a href="#" data-toggler-target="#sub-menu">Item 1</a>
   <ul class="sub-menu" id="sub-menu">
      <li><a href="#">Sub-item 1</a></li>
      <li><a href="#">Sub-item 2</a></li>
      <li><a href="#">Sub-item 3</a></li>
   </ul>

Custom css class

   <a href="#" data-toggler-target="#sub-menu" data-toggler-class="test-class">Item 1</a>
   <ul class="sub-menu" id="sub-menu">
      <li><a href="#">Sub-item 1</a></li>
      <li><a href="#">Sub-item 2</a></li>
      <li><a href="#">Sub-item 3</a></li>
   </ul>

Grouping

the grouped elements will be holding the active css class only one at the time. (good for dropdowns, accordions..)

   <ul>
      <li>
         <a href="#" data-toggler-target="#sub-menu-1" data-toggler-group="navigation">Item 1</a>
         <ul class="sub-menu" id="sub-menu-1">
            <li><a href="#">Sub-item 1</a></li>
            <li><a href="#">Sub-item 2</a></li>
            <li><a href="#">Sub-item 3</a></li>
         </ul>
      </li>
      <li>
   		<a href="#" data-toggler-target="#sub-menu-2" data-toggler-group="navigation">Item 2</a>
   		<ul class="sub-menu" id="sub-menu-2">
            <li><a href="#">Sub-item 1</a></li>
            <li><a href="#">Sub-item 2</a></li>
            <li><a href="#">Sub-item 3</a></li>
         </ul>
   	</li>
   </ul>

Chaining

One element controlling two (or more) containers


   <p class="text-center">
      <a class="btn" href="#" data-toggler-target="#section-1, #section-4">Red</a>
      <a class="btn btn-blue" href="#" data-toggler-target="#section-2, #section-3">Blue</a>
   </p>
   <div class="row">
      <div id="section-1" class="col-md-6 collapse active">
         <div class="card red">
            <h2>Red</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
         </div>
      </div>
      <div id="section-2" class="col-md-6 collapse active">
         <div class="card blue">
            <h2>Blue</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
         </div>
      </div>
      <div id="section-3" class="col-md-6 collapse active">
         <div class="card blue">
            <h2>Blue</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
         </div>
      </div>
      <div id="section-4" class="col-md-6 collapse active">
         <div class="card red">
            <h2>Red</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
         </div>
      </div>
   </div>

Chaining classes

   <p>
      <a href="#" class="btn btn-blue" data-toggler-target="#my-button" data-toggler-class="btn, btn-blue">Toggle classes</a>
   </p>
   <p>
      <a href="#" id="my-button">My button</a>
   </p>

Remove Class by a group name

Great for closing menus, dropdowns etc.. on a custom event.

Imagine the following scenario: You opened a navigation via the classtoggler. Without closing it, you start interacting with the content. F.ex. you clicked on a button somewhere in the text. You expect the menu to get closed automaticaly.

   <ul>
      <li>
         <a href="#" data-toggler-target="#sub-menu-1" data-toggler-group="navigation">Item 1</a>
         <ul class="sub-menu" id="sub-menu-1">
            <li><a href="#">Sub-item 1</a></li>
            <li><a href="#">Sub-item 2</a></li>
            <li><a href="#">Sub-item 3</a></li>
         </ul>
      </li>
      <li>
         <a href="#" data-toggler-target="#sub-menu-2" data-toggler-group="navigation">Item 2</a>
         <ul class="sub-menu" id="sub-menu-2">
            <li><a href="#">Sub-item 1</a></li>
            <li><a href="#">Sub-item 2</a></li>
            <li><a href="#">Sub-item 3</a></li>
         </ul>
      </li>
   </ul>

   classtogglerRemoveClassByGroup('navigation');

Update the classtoggler after dynamic elements were added to the DOM


   classtogglerUpdate();