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

@19h47/tabs

v8.0.1

Published

Tabs

Downloads

50

Readme

@19h47/tabs

Tabulation partout, tabulation nulle part

Installation

yarn add @19h47/tabs

Usage

import Tabs from '@19h47/tabs';

const $element = document.querySelector('.js-tabs');
const tabs = new Tabs($element);

tabs.init();

Tablist

The element that serves as a container for the set of tabs. The role="tablist" attribute is required.
The aria-label="" attribute provides a label that describes the purpose of the set of tabs.

<ul role="tablist" aria-label="navigation">
	<li>
		<button
			type="button"
			class="is-active"
			role="tab"
			aria-selected="true"
			aria-controls="home-tab"
			id="home"
		>
			Home
		</button>
	</li>
	<li>
		<button
			type="button"
			role="tab"
			aria-selected="false"
			aria-controls="project-tab"
			id="project"
			tabindex="-1"
		>
			Project
		</button>
	</li>
	<li>
		<button
			type="button"
			role="tab"
			aria-selected="false"
			aria-controls="contact-tab"
			id="contact"
			tabindex="-1"
			data-deletable=""
		>
			Contact
		</button>
	</li>
</ul>

Tab

An element in the tab list that serves as a label for one of the tab panels and can be activated to display that panel.

<button
	type="button"
	role="tab"
	aria-selected="false"
	aria-controls="foo-tab"
	id="foo"
	tabindex="-1"
>
	Project
</button>

The role="tab" attribute is required.

The aria-controls="foo-tab" refers to the id of the tabpanel element associated with the tab.

Since an HTML button element is used for the tab, it is not necessary to set tabindex="0" on the selected (active) tab element.

Is the tabulation deletable ? You can set up this option by adding the data-deletable attribute on button.

To active the button on first load, add a is-active class to the button, remove the tabindex attribute and switch to true the aria-selected attribute.

Tabpanel

The element that contains the content associated with a tab.

<section tabindex="0" role="tabpanel" aria-labelledby="foo" id="foo-tab">
	<p>
		Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil hic, vero. Fugiat voluptas
		ex consequatur hic nemo officia iure placeat non, pariatur, dolore natus nobis, tempore
		dolores dicta nisi inventore.
	</p>
</section>

To active panel on first load, add a is-active class to it.

Keyboard support

| Key | Function | | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Tab | When focus moves into the tab list, places focus on the active tab elementWhen the tab list contains the focus, moves focus to the next element in the tab sequence, which is the tabpanel element. | | EnterSpace | When a tab has focus, activates the tab, causing its associated panel to be displayed. | | Right Arrow | When a tab has focus:Moves focus to the next tab.If focus is on the last tab, moves focus to the first tab. | | Left Arrow | When a tab has focus:Moves focus to the previous tab.If focus is on the first tab, moves focus to the last tab. | | Homefn + left arrow | When a tab has focus, moves focus to the first tab. | | Endfn + right arrow | When a tab has focus, moves focus to the last tab. | | Delete | When focus is on the Contact tab, removes the tab from the tab list and places focus on the previous tab. |

Options

| Option | Type | Default | Description | | -------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | delay | integer | 0 | Determine whether there should be a delay when user navigates with the arrow keys | | hash | boolean | true | | | callback | function | () => {} | A callback fired right before Tab.activate event. Useful for animation or to fetch data for instance. Don't use arrow function if you need to access this. |

import Tabs from '@19h47/tabs';

const $element = document.querySelector('.js-tabs');
const tabs = new Tabs($el, {
	callback() {
		return new Promise(resolve => {
			// animate, fetch data, use this, do your stuff, etc.
			resolve();
		});
	},
});

tabs.init();

Events

| Event | Arguments | Description | | ------------ | --------- | ----------------------------------------------------------------------------- | | Tab.activate | event | Detail object containing current controls id, and current DOM element | | Tab.delete | event | Detail object containing current controls id, and current DOM element |

import Tabs from '@19h47/tabs';

const $element = document.querySelector('.js-tabs');
const tabs = new Tabs($element);

tabs.init();

tabs.tabs.forEach($tab => {
	$tab.el.addEventListener('Tab.activate', ({ detail }) => {
		const { controls, element } = detail;
		console.log(controls, element);
	});
	$tab.el.addEventListener('Tab.delete', ({ detail }) => {
		const { controls, element } = detail;
		console.log(controls, element);
	});
});

Methods

| Method | | | ----------- | ------- | | destroy() | Destroy | | init() | Create | | create() | Create |

Build Setup


# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn start

# build for production
$ yarn prod

Example

An example is located right here, see sources.

Acknowledgments