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

@oom/tab

v1.1.0

Published

Tab panel with progressive enhancement in mind

Downloads

6

Readme

@oom/tab

Tab panel component with the following features:

  • No dependencies
  • Light: Aprox 200 lines of code (including comments and spaces)
  • Follows the progressive enhancement strategy:
    • Works with just html
    • Works better with html and css
    • Works much better with html, css and js
    • Works much much better when js polyfills are not needed
  • No styles or themes are provided with this package. You decide how the tabs must look.
  • Support for touch devices
  • Support for keyboard
  • Fully accessible
  • Build with modern javascript, using ES6 modules and custom elements

Install

Requirements:

npm install @oom/tab
npm install @webcomponents/custom-elements

Usage

HTML

Let's start with the following html code:

<my-tabs role="region">
     <ul role="tablist">
        <li role="presentation">
            <a href="#section1" role="tab" id="tab1" aria-selected="true">
                Section 1
            </a>
        </li>
        <li role="presentation">
            <a href="#section2" role="tab" id="tab2">
                Section 2
            </a>
        </li>
        <li role="presentation">
            <a href="#section3" role="tab" id="tab3">
                Section 3
            </a>
        </li>
    </ul>

    <section id="section1" aria-labelledby="tab1" role="tabpanel">
        Content section 1
    </section>

    <section id="section2" aria-labelledby="tab2" role="tabpanel">
        Content section 2
    </section>

    <section id="section3" aria-labelledby="tab3" role="tabpanel">
        Content section 3
    </section>
</my-tabs>

CSS

Use css to define the tab panel appearance:

/* This makes the tabs works without javascript */
section:not(:target) {
    display: none;
}

[role="tablist"] {
    display: flex;
    list-style: none;
    padding: 0;
}

JS

And finally use javascript for a complete experience:

import Tab from "./tab/tab.js";

//Register the custom element
customElements.define("my-tabs", Tab);

API

This is a custom element that extends HtmlElement, so it innerit the same api of a standard html element with the following additions:

//Select the element
const element = document.querySelector("my-tabs");

//Change the tab state
element.setState("#section2");

//Get the currently selected tabpanel element
console.log(element.panel);

//Get the currently selected tab element
console.log(element.tab);

Demo and tests

  • Demo: https://oom-components.github.io/tab/demo/
  • Tests: https://oom-components.github.io/tab/tests/

To run the demo locally, just clone this repository, enter in the directory and execute:

npm install
npm start

You should see something in the following urls:

  • Demo: http://localhost:8080/demo
  • Test: http://localhost:8080/tests