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

@terrahq/collapsify

v0.0.25

Published

Javascript module for accordion/collapse/tabs written in Vanilla js. [> examples](https://collapsify-terra.netlify.app/)

Downloads

220

Readme

@terrahq/collapsify.js

Javascript module for accordion/collapse/tabs written in Vanilla js. > examples

Usage

Install

npm install @terrahq/collapsify

Import

import Collapsify from "@terrahq/collapsify";

Initialize

new Collapsify(options);

Markup

Minimum markup

<!--
    Add data attribute, button/content element.
    Control Button:  data-{namespace}-control="{ID}" * multiple elements
    Toggle Content:  data-{namespace}-content="{ID}" * only one element
 -->
<button type="button" data-collapsify-control="uniqID">Show/Hide Content</button>

<div data-collapsify-content="uniqID">Toggle Content</div>

With aria-* attribute for accessibility

<button type="button" data-collapsify-control="uniqID" aria-expanded="false" aria-controls="contentID">Show/Hide Content</button>

<div id="contentID" data-collapsify-content="uniqID" aria-hidden="true">Toggle Content</div>

Options

| Option Name | Type | Default | Desc | | ----------------- | --------------------------------------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | nameSpace | string | "collapsify" | Set namespace for "toggleButtonAttr", "toggleContentAttr" & "toggleSelectOptionsAttr" | | toggleButtonAttr | string | "data-collapsify-control" | data attribute for Button Element | | toggleContentAttr | string | "data-collapsify-content" | data attribute for Content | | dropdownElement | HTMLSelectElement | - | HTML dropdown element for tablets/mobiles. Stays in sync with the active tab in both directions: selecting from dropdown activates the tab and vice versa. | | isTab | boolean | false | Set to true when using as tabs (prevents closing the active tab) | | activeClass | string | "--is-active" | Suffix added to the element's first class to form the active class (e.g. c--btn-a--is-active) | | isAnimation | boolean | true | Enable animated slide transition | | closeOthers | boolean | true | Close other content panels when one opens | | animationSpeed | number | 400 | CSS transition duration in ms | | cssEasing | string | "ease-in-out" | CSS transition easing (only when isAnimation: true) | | onSlideStart | (isOpen:boolean, contentID:string) => void | Promise<void> | - | Callback fired when open/close animation starts. Supports async/await. | | onSlideEnd | (isOpen:boolean, contentID:string) => void | Promise<void> | - | Callback fired when open/close animation ends. Supports async/await. | | onComplete | () => void | Promise<void> | - | Callback fired after Collapsify finishes initialization. Supports async/await. |

Methods

// Open a content panel
collapsify.open(contentID);

// Close a content panel
collapsify.close(contentID);

// Remove all event listeners
collapsify.destroy();

Samples

Basic accordion

const accordion = new Collapsify({
    nameSpace: "collapsify",
    isAnimation: true,
    closeOthers: true,
    animationSpeed: 400,
    cssEasing: "ease",
    onSlideStart: (isOpen, contentID) => {
        console.log(isOpen, contentID);
    },
    onSlideEnd: (isOpen, contentID) => {
        console.log(isOpen, contentID);
    },
    onComplete: () => {
        console.log('Collapsify is ready!');
    }
});

// Open/close programmatically
accordion.open("content01");
accordion.close("content01");

Tabs with dropdown sync

When dropdownElement is provided, the dropdown and the tab buttons stay in sync automatically — clicking a button updates the dropdown, and selecting from the dropdown activates the corresponding tab.

const tabs = new Collapsify({
    nameSpace: "tab",
    isTab: true,
    closeOthers: true,
    dropdownElement: document.querySelector(".js--tab-select"),
});
<div class="tabs">
    <!-- Tab buttons -->
    <ul>
        <li>
            <button type="button" class="tab__link tab__link--is-active" data-tab-control="tab01" aria-expanded="true">Tab 01</button>
        </li>
        <li>
            <button type="button" class="tab__link" data-tab-control="tab02" aria-expanded="false">Tab 02</button>
        </li>
        <li>
            <button type="button" class="tab__link" data-tab-control="tab03" aria-expanded="false">Tab 03</button>
        </li>
    </ul>

    <!-- Dropdown (mobile) — syncs automatically with active tab -->
    <select class="js--tab-select" aria-label="Tab selector">
        <option value="" disabled>Select</option>
        <option data-tab-dropdown-item="tab01" value="">Tab 01</option>
        <option data-tab-dropdown-item="tab02" value="">Tab 02</option>
        <option data-tab-dropdown-item="tab03" value="">Tab 03</option>
    </select>

    <!-- Tab content -->
    <div class="tab__bd tab__bd--is-active" data-tab-content="tab01" aria-hidden="false">
        <p>Content for Tab 01.</p>
    </div>
    <div class="tab__bd" data-tab-content="tab02" aria-hidden="true">
        <p>Content for Tab 02.</p>
    </div>
    <div class="tab__bd" data-tab-content="tab03" aria-hidden="true">
        <p>Content for Tab 03.</p>
    </div>
</div>

Async/Await callbacks

All callbacks support async/await — useful for API calls, analytics, dynamic content loading, etc.

const collapsify = new Collapsify({
    nameSpace: "collapsify",
    onSlideStart: async (isOpen, contentID) => {
        await fetch('/api/track', {
            method: 'POST',
            body: JSON.stringify({ action: isOpen ? 'open' : 'close', contentID })
        });
    },
    onSlideEnd: async (isOpen, contentID) => {
        if (isOpen) {
            const response = await fetch(`/api/content/${contentID}`);
            const data = await response.json();
            document.querySelector(`[data-collapsify-content='${contentID}']`).innerHTML = data.html;
        }
    },
    onComplete: async () => {
        await someInitTask();
        console.log('Ready!');
    }
});

License