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

dynamic-tabs

v2.0.0

Published

A lightweight JavaScript library for tab UI elements, styled (somewhat) by material design principles.

Downloads

25

Readme

DynamicTabs

This is a lightweight JavaScript library for tab UI elements, styled loosely by material design principles.

Demo: opensource.widerwebs.com/dynamic-tabs

Usage

Install with npm:

npm install dynamic-tabs

In your code, import the main JavaScript file:

import DynamicTabs from "dynamic-tabs" // the DynamicTabs identifier can be anything

and the required CSS file:

import "dynamic-tabs/dist/tabs.css"

The tabs component requires HTML markup with this kind of layout and these CSS classes:

<div id="section-tabs" class="dynamic-tabs">
    <div class="dynamic-tabs-arrow"></div>
    <div class="dynamic-tabs-framer">
        <nav class="dynamic-tabs-list">
            <div class="dynamic-tab">FIRST</div>
            <div class="dynamic-tab">THE SECOND</div>
            <div class="dynamic-tab">THIRD THING</div>
            <div class="dynamic-tab">FOURTH</div>
            <div class="dynamic-tab">FIVE</div>
            <div class="dynamic-tab">ELEMENT SIX</div>
            <div class="dynamic-tab">SEVENTH</div>
        </nav>
        <div class="dynamic-tabs-indicator"><div class="dt-indicator-bar"></div></div>
    </div>
    <div class="dynamic-tabs-arrow"></div>
</div>

There needs to be a wrapping element with a dynamic-tabs class; an element as shown with class dynamic-tabs-arrow; a wrapper of the tabs with class dynamic-tabs-list containing children each with the class dynamic-tab; and after (and outside) that a <div class="dynamic-tabs-indicator"><div class="dt-indicator-bar"></div></div> element; and then outside of that an element as shown with the class dynamic-tabs-arrow.

To register the container of the tabs (here it is the div with id="section-tabs"), create the tabs object using the new keyword:

const myTabs = new DynamicTabs(container-ID); // Or instead of the container ID pass in an HTMLElement.

Create any number of tab elements inside the dynamic-tabs-list element, and make sure each tab has the class dynamic-tab. Each tab needs to be registered (you may use registerAllTabs) to appear in the layout and be used.

Look at the file at docs/index.html for an example of how you can set up the tabs.

Complete documentation is available at docs/docs.md

Some methods of the DynamicTabs class are marked as private within the code (such as refreshLayout and scrollLeft); they are used internally by the class to implement all the cool dynamic magic. If you find yourself needing to use any of these, please file an issue.

Goal and Features

This library is intended to be extremely lightweight so that it loads fast and works smoothly on all devices. The required HTML is fairly minimal, and the animations are kept at the CSS level where possible to ensure that the JavaScript thread is not used as much. Needless to say, the tabs are fully responsive on all screens and work on all popular browsers.

Why use the word dynamic in the name? It's not just about how the switching between the tabs works with the indicator bar sliding with a smooth animation from tab to tab. The point is that the entire tabs component dynamically reacts to changes in its size, such as when the window's or the container's parent element's width changes.