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

@degjs/expander

v1.0.0

Published

A plugin to handle functionality and accessibility for expanding elements.

Downloads

3

Readme

expander

Run Tests

A re-usable plugin to manage functionality and accessibility of expanding elements

Install

expander is an ES6 module. Consequently, you'll need an ES^ transpiler (Babel is a nice one) as part of your Javascript workflow.

If you're already using NPM for your project, you can install expander with the following command:

$ npm install @degjs/expander

Usage

The expander plugin will handle listening and responding to click events on a trigger button. It also handles accessibility associated with this (see accessibility section below). Finally, there is built-in support for animation when expanding or collapsing. It will dispatch custom events that the application can listen and respond to.

Note: the expander plugin exports a variable called events to help standardize event names that the app can listen for.

import expander, { events } from '@degjs/expander';

let expanderInst;

const init = () => {
    expanderInst = expander(containerEl);

    containerEl.addEventListener(events.beforeExpand, onBeforeExpand);
};

const destroy = () => {
    expanderInst.destroy();
};

Options

| Property Name | Type | Default | Description | | ------------------ | --------- | ----------------- | ----------------------------------------------------------------------------------------------------- | | isExpanded | Boolean | false | Describes if the content is expanded on init | | toggleSelector | String | "button" | The selector string to find the toggle trigger element | | controlsId | String | null | The id of the content element that is controlled by the toggle button | | expandingCssClass | String | "is-expanding" | The css class to be added when and element is in the process of expanding | | collapsingCssClass | String | "is-collapsing" | The css class to be added when and element is in the process of collapsing | | expandedCssClass | String | "is-expanded" | The css class to be added when and element is fully expanded | | collapsedCssClass | String | "is-collapsed" | The css class to be added when and element is fully collapsed | | animationTargetEl | Element | null | The element to add the animation classes to | | animationEvent | String | "animationend" | The animation event name to listen for. When it is fired, the expand or collapse action will commence |

Methods

getElement()

The getElement method returns the container element used by expander.

Returns

| Type | Description | | ------- | -------------------------------------------------------------- | | Element | the element that contains the trigger and content for expander |

expand()

A way to manually trigger the expand functionality of expander.

collapse()

A way to manually trigger the collapse functionality of expander.

getOptions()

The getOptions method returns the current expander settings.

Returns

| Type | Description | | ------ | ---------------------------------------------------------------------------- | | Object | the current settings for expander (defaults and user-set options combined) |

setOptions(newOptions)

The setOptions method allows changes to the current expander settings. This method performs a merge of the original settings and the new ones.

Arguments

| Type | Description | | ------ | -------------------------------------- | | Object | new settings for the expander plugin |

Returns

Nothing

destroy()

This method removes any aria-attributes it created and cleans up any event listeners it created.

Accessibility Features

aria-controls

The aria-controls attribute details a relationships between two elements in the DOM. In this module, the aria-controls attribute is added to the toggle element if an element id is provided in the expander options.

It is recommended that the controlsId is passed as an option if the element shown/hidden by the toggle does not immediately follow the toggle in DOM order.

aria-expanded

The aria-expanded attribute details whether a collapsible region is expanded or collapsed.

The expander module will set the aria-expanded attribute to the appropriate value whenever content is expanded or collapsed.

Browser Support

expander depends on the following browser APIs:

To support legacy browsers, you'll need to include polyfills for the above APIs.