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

storm-toggler

v1.3.4

Published

Accessible UI state toggling

Downloads

47

Readme

Storm Toggler

Build Status codecov.io npm version

Class and ARIA toggle UI state manipulation

Example

https://mjbp.github.io/storm-toggler

Usage

Installation

npm i -S storm-toggler

Global toggle

For document-level state changes such as off-canvas menus

HTML

<a href="#nav" class="js-toggle"></a>
<div id="nav" class="nav"></div>

JS either using es6 import

import Toggler from 'storm-toggler';

Toggler.init('.js-toggle');

or aynchronous browser loading (use the .standalone version in the /dist folder)

import Load from 'storm-load';

Load('/content/js/async/storm-toggler.standalone.js')
    .then(() => {
        StormToggler.init('.js-toggler');
    });

CSS

.nav {
    position:fixed;
    transform:translateX(100%);
    transition: transform 160ms ease;
}
.on--nav .nav {
    transform:translateX(0);
}

Local toggle

To encapsulate a toggle state within part of the document

HTML

<div class="parent">
    <a href="#child-target" class="js-toggle__local"></a>
    <div id="child-target" class="child"></div>
</div>

JS either using es6 import

import Toggler from 'storm-toggler';

Toggler.init('.js-toggle__local', {
    local: true
});

or aynchronous browser loading (use the .standalone version in the /dist folder)

import Load from 'storm-load';

Load('/content/js/async/storm-toggler.standalone.js')
    .then(() => {
        StormToggler.init('.js-toggle__local', {
            local: true
        });
    });

CSS

.child {
    max-height:0;
    overflow:hidden;
    transition: max-width 160ms ease;
}
.parent.active .child {
    max-height:1000px;
}

Options

{
	delay: 0, //duration of animating out of toggled state
	startOpen: false,  //intial toggle state
	local: false, // encapsulate in small part of document
	prehook: false, //function to fire before each toggle
	callback: false, //function to fire after each toggle
	focus: true, //focus on first focusable child node of the target element
	trapTab: false //trap tab in the target element
}

e.g.

Toggler.init('.js-toggler', {
    startOpen: true
});

Tests

npm run test

Browser support

This is module has both es6 and es5 distributions. The es6 version should be used in a workflow that transpiles.

The es5 version depends unpon Object.assign, element.classList, and Promises so all evergreen browsers are supported out of the box, ie9+ is supported with polyfills. ie8+ will work with even more polyfils for Array functions and eventListeners.

Dependencies

None

License

MIT