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

lux-toggle

v1.2.1

Published

A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

Downloads

11

Readme

LUX TOGGLE

Demo: https://jesschampion.github.io/lux-toggle/

A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's toggle utility but without the overhead. Implemented in vanillaJS in a functional style. The utility has baked in animation and accessibility support/

Set the toggle button by adding the attribute data-lux-toggle, with the value being the ID of the element to be toggled.

The following classes will be added to the target to indicate current state.

  • open: toggle--open,
  • opening: toggle--opening,
  • closing: toggle--closing

CSS will need to be coded to define the display state, as the script only modifies the elements classes.

Any clicks outside the toggle button or target will cause the target to close automatically.

Four other optional attributes can be added to the toggle element to customise its behaviour.

  • data-lux-toggle-group can be set with a string representing the group name. Whenever a toggle in a group is opened it will check if there are other siblings open in the group, and delay the opening animation for the current toggle to allow the closing animation for the sibling.

  • data-lux-toggle-close set the value to the ID of any element inside the toggle target. The element will function as a close button.

  • data-lux-toggle-mode configure the closing behaviour of the toggle section. Options:

    • manual: close only when clicking toggle, by keyboard or close area. (DEFAULT)
    • group: close siblings when another in the same group is opened.
    • outside: always close on click outside
  • data-lux-toggle-menu set true , (defaults to false) to indicate that the toggle expands a menu. This adds the extra aria tag aria-haspopup which indicates a popup menu to screen readers. This should only be used where the target is a menu, it may cause accessibility issues

Accessibility support includes: - Keyboard navigation - Automatic applications of tabindex=0 to toggles and close button if not manually specified. - Automatic application of aria-expanded and aria-controls tags to target and toggles. - Supports menu mode to set aria-haspopup on menus

Installation & Usage

Installation

lux-toggle can be installed from NPM yarn add lux-toggle

Usage

Import into your main javascript package

import luxToggle from 'lux-toggle';
   
luxToggle();

Define toggles and targets in html using the given data attributes

<span data-lux-toggle="myTarget"
      data-lux-toggle-close="closeButton"
      data-lux-toggle-mode="outside">
  Toggle button
</span>

<div id="myTarget">
    <span id="closeButton"></span>
    <div>toggleable contents</div>
</div>

Development

Scripts

  • install dependencies: yarn

  • development build: yarn build or yarn watch

  • run linters: yarn lint

  • push dist/demo sub folder to github pages branch: yarn deploy:demo

Build TODO - update

Running locally

  1. Build by running yarn build oryarn watch
  2. Open lux-toggle/dist/demo/index.html in a browser

Demo build

  1. Build yarn build
  2. Commit changes git commit -am"V X.Y.Z"
  3. Push to gh-pages branch yarn deploy-demo
  4. Update version number in package.json and push to master

Production build

  1. Build yarn build
  2. Update version number in package.json
  3. Commit changes git commit -am"V X.Y.Z"
  4. Deploy to npm npm publish

Code Style

There are linters set up to enforce code style, run with yarn lint.

Tests

JavaScript unit tests are implemented with Jest The specs are located in /test and can be run with yarn test Test coverage can be reported by running yarn test:coverage

Enhancement Backlog

  • Make config actually configurable