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

@papit/switch

v0.1.3

Published

A binary on/off toggle control that participates in forms just like a checkbox. Prefer it over a checkbox when the semantics of "on / off" better describe the intent of the interface — e.g. "Notifications on" reads more naturally than "Notifications check

Downloads

385

Readme

@papit/switch

A binary on/off toggle control implemented as a Web Component. Use a switch instead of a checkbox when the meaning is stateful rather than selection — for example “Notifications on” reads more naturally than “Notifications checked”.

The component follows the WAI-ARIA Switch Pattern, supports keyboard interaction, and participates in HTML forms like a native input.

See the pattern: https://www.w3.org/WAI/ARIA/apg/patterns/switch/

Logo


Type Tests NPM version


Installation

npm install @papit/switch

Usage

Import

import "@papit/switch";

Basic example

<pap-switch></pap-switch>

With label

<label>
  Notifications
  <pap-switch></pap-switch>
</label>

Default checked

<pap-switch defaultchecked></pap-switch>

Form Support

pap-switch participates in forms using ElementInternals.

When the switch is on, it submits "true" as its form value.

<form>
  <pap-switch name="notifications"></pap-switch>

  <button type="submit">Submit</button>
</form>

Example submitted data:

{
  "notifications": "true"
}

If the switch is off, no value is submitted — the same behavior as a native checkbox.


Attributes / Properties

| Attribute | Property | Type | Description | | ---------------- | ---------------- | --------- | ------------------------------------- | | checked | checked | boolean | Current state of the switch | | defaultchecked | defaultChecked | boolean | Initial state used when a form resets | | disabled | disabled | boolean | Prevents interaction | | readonly | — | boolean | Prevents toggling but allows focus |


Events

| Event | Description | | -------- | --------------------------------------- | | change | Fired whenever the switch state changes |

Example:

const el = document.querySelector("pap-switch");

el.addEventListener("change", () => {
  console.log("Switch state:", el.checked);
});

Keyboard Interaction

| Key | Behavior | | ------- | ----------------- | | Space | Toggle the switch | | Enter | Toggle the switch |

During keyboard press the component temporarily exposes an internal active state for styling.


Accessibility

This component implements the ARIA Switch Pattern and automatically manages:

  • role="switch"
  • aria-checked
  • keyboard interaction
  • focus behavior

Reference:

https://www.w3.org/WAI/ARIA/apg/patterns/switch/


Styling

The component uses a constructed stylesheet and exposes internal states that can be styled:

pap-switch:state(checked) {
  /* some style goes here */
}

pap-switch:state(active) {
  /* some style goes here */
}

Example:

pap-switch:state(checked) {
  background: green;
}

Contributing

Contributions are welcome.

Please ensure:

  • tests pass
  • linting passes
  • behavior follows the ARIA switch pattern

Submit pull requests through the GitHub repository.


License

Licensed under the @Papit License 1.0 Copyright (c) 2024 Henry Pap (@onkelhoy)

Key points

  • ✅ Free to use in commercial projects
  • ✅ Free to modify and distribute
  • ✅ Attribution required
  • ❌ Cannot resell the component itself as a standalone product

See the LICENSE file for full details.


Related Components


Support

For issues, questions, or contributions, please visit the GitHub repository.