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

basic-trigger

v0.0.8

Published

Some html toggle event implementation.

Downloads

4

Readme

Basic Trigger

Some html toggle event implementation.

Bind all elements

import { bindAll } 'basic-trigger'

bindAll()

Dialog

Basic structure

<button aria-controls="dialog">open dialog</button>

<dialog id="dialog" data-active-class="optional" data-unactive-class="optional">
	<button data-dialog-event="close"></button> <!-- dialog default close event -->
	<button data-dialog-event="reset">reset</button> <!-- dialog:reset event -->
	<button data-dialog-event="confirm">confirm</button> <!-- dialog:confirm event -->
	<button data-dialog-event="custom-name">confirm</button> <!-- dialog:custom-name event -->
</dialog>

Custom Events

import { bind } 'basic-trigger'

bind('dialog')
const $dialog = document.querySelector('dialog')
$dialog.addEventListener('dialog:show', () => {
	console.info('This will trigger when dialog appear')
})

$dialog.addEventListener('dialog:CUSTOM_NAME', () => {
	console.info('data-dialog-event will be your CUSTOM_NAME, except close')
})

Tablist

Basic structure

<!-- data classes will toogle in tab role -->
<ul role="tablist" data-active-class="optional" data-unactive-class="optional">
	<li role="tab" aria-controls="firstPanel" aria-selected="true">first tab</li>
	<li role="tab" aria-controls="secondPanel">second tab</li>
	<li role="tab" aria-controls="thirdPanel">third tab</li>
</ul>

<div id="firstPanel" role="tabpanel">first panel</div>
<div id="secondPanel" role="tabpanel" hidden>second panel</div>
<div id="thirdPanel" role="tabpanel" hidden>third panel</div>

Custom Events

import { bind } from 'basic-trigger'

bind('tablist')
const $tablist = document.querySelector('[role=tablist]')
$tablist.addEventListener('tab:selected', ({ detail }) => {
	const { $tab, $panel } = detail
})

Press Button

Basic structure

<button aria-pressed="false" data-active-class="optional" data-unactive-class="optional">button</button>

Custom Events

import { bind } from 'basic-trigger'

bind('pressButton')
const $btn = document.querySelector('button')
$btn.addEventListener('btn:pressed', () => {})
$btn.addEventListener('btn:unpressed', () => {})

Checklist

Basic structure

<!-- This is custom role -->
<div role="checklist">
	<label for="checkbox1">
		<input type="checkbox" id="checkbox1" value="1">
		checkbox 1
	</label>
	<label for="checkbox2">
		<input type="checkbox" id="checkbox2" value="2">
		checkbox 2
	</label>
	<label for="checkbox3">
		<input type="checkbox" id="checkbox3" value="3">
		checkbox 3
	</label>
	<label for="checkbox4">
		<input type="checkbox" id="checkbox4" value="4">
		checkbox 4
	</label>
	<label for="checkbox5">
		<input type="checkbox" id="checkbox5" value="5">
		checkbox 5
	</label>
</div>

Custom Events

import { bind } from 'basic-trigger'

bind('checklist')
const $checklist = document.querySelector('[role=checklist]')
$checklist.addEventListener('checklist:change', ({ detail }) => {
	const { value, checked } = detail
})