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

@halcyoninno/accordion

v0.2.0

Published

Minimal Vanilla JS accordion feature, supporting nested accordions for building menus, submenus, etc.

Downloads

138

Readme

Accordion effect (vanilla JS)

Minimal, dependency-free accordion behavior for any element pair you describe in JavaScript. The library attaches click handlers to your triggers, applies height transitions to the targets, and cleans itself up when a media query stops matching.

Features

  • Pure JavaScript, no markup requirements beyond element ids
  • Optional media-query activation with automatic deactivation
  • Supports nested accordions (menu/submenu scenarios)
  • Starts expanded or collapsed per option
  • Adds expanded / collapsed classes to both trigger and target for easy styling
  • Customizable transition duration, easing, and click preventDefault

Installation

npm install @halcyoninno/accordion

The source ships as an ES module. Import the module directly:

import { accordionEffect } from '@halcyoninno/accordion/src/accordion.mjs';

Or load it with a module script tag in plain HTML:

<script type="module">
  import { accordionEffect } from './src/accordion.mjs';
  // ... call accordionEffect below ...
</script>

Quick start

Attach each trigger to a target element by id inside relations.

<div id="faq-answer">
  <p>This panel expands and collapses.</p>
</div>
<button id="faq-toggle">Toggle FAQ</button>

<script type="module">
  import { accordionEffect } from './src/accordion.mjs';

  accordionEffect({
    relations: [
      { targetId: 'faq-answer', triggerId: 'faq-toggle' }
    ]
  });
</script>

Media-query activated accordion

Only enable the accordion effect when a media query matches (for example, compress a nav on small screens). When the query stops matching, event listeners and inline styles are removed.

accordionEffect({
  relations: [
    { targetId: 'nav-links', triggerId: 'nav-toggle' }
  ],
  options: {
    activationMediaQuery: '(max-width: 700px)',
    startCollapsed: true
  }
});

Nested accordion example

<div id="outer-panel">
  <p>Outer content</p>
  <div id="inner-panel">
    <p>Inner content</p>
  </div>
  <button id="inner-trigger">Toggle inner</button>
</div>
<button id="outer-trigger">Toggle outer</button>

<script type="module">
  import { accordionEffect } from './src/accordion.mjs';

  accordionEffect({
    relations: [
      { targetId: 'outer-panel', triggerId: 'outer-trigger' },
      { targetId: 'inner-panel', triggerId: 'inner-trigger' }
    ],
    options: {
      startCollapsed: true,
      transitionDuration: '.3s',
      easingFunction: 'ease-in-out'
    }
  });
</script>

Options

All options are optional. Defaults are shown in parentheses.

  • activationMediaQuery (undefined): CSS media query string. Only runs while it matches, removing listeners and styles when it does not.
  • startCollapsed (false): Start all targets collapsed on initialization.
  • transitionDuration ('.5s'): CSS duration for the height transition.
  • easingFunction ('ease'): CSS timing function for the transition.
  • preventDefault (true): Call event.preventDefault() on trigger clicks.

Each target and trigger receives expanded/collapsed classes as the accordion animates, so you can style them as needed.

Notes on borders and padding

Animating height on an element with padding or borders can look off without a wrapper. If your target has padding, wrap it in a zero-padding container before applying the accordion effect to avoid layout surprises.