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/theme-picker

v0.0.12

Published

Button and menu for switching a page between light, dark and system colour schemes. Sets data-theme on a target element and can remember the choice in local or session storage.

Readme

@papit/theme-picker

Button and menu for switching a page between light, dark and system colour schemes. Sets data-theme on a target element and can remember the choice in local or session storage.

Logo


Type Tests NPM version


Installation

npm install @papit/theme-picker

Usage

Import

import "@papit/theme-picker";

The icons load from /icons/sun.svg, /icons/moon.svg and /icons/computer.svg. Serve the package's asset/icons/ folder at /icons/.

Basic example

Switches the theme on <html>. Pair it with @papit/theme, which reads data-theme.

<pap-theme-picker></pap-theme-picker>

Remember the choice

<pap-theme-picker storage="local"></pap-theme-picker>

Theme one part of the page

<section id="preview">…</section>
<pap-theme-picker target="#preview"></pap-theme-picker>

React to changes

const picker = document.querySelector("pap-theme-picker");
picker.addEventListener("change", () => console.log(picker.value));

Attributes / Properties

| Attribute | Property | Type | Default | Description | | --------- | --------- | --------------------------------- | ---------- | ---------------------------------------------------------------------- | | value | value | "light" \| "dark" \| "system" | "system" | Current choice | | target | target | string | "html" | CSS selector of the element that gets the theme | | storage | storage | "local" \| "session" | — | Save the choice under the pap-theme key and restore it on connect |

What happens on the target:

  • light / dark: sets data-theme and style.colorScheme to the value.
  • system: removes data-theme, colorScheme and the theme-light / theme-dark classes.
  • The target is watched: if something else sets data-theme or a theme-light / theme-dark class, value follows.
  • The switch runs inside document.startViewTransition when available. Opening the menu sets --theme-transition-location on the target to the picker's position, which @papit/theme uses for its reveal animation.

Changing storage removes the value saved under the old storage.


Events

| Event | Description | | -------- | ------------------------------------------------------- | | change | Fired whenever the theme is applied, including on setup |


Styling

| Part | Description | | --------- | ---------------------- | | trigger | The icon button |


Keyboard Interaction

The trigger is a pap-button that opens a pap-menu, so keyboard handling is the menu button pattern from @papit/menu:

| Key | Behavior | | ----------------------- | ----------------------------------------- | | Enter / Space | On the button: open the menu. On an item: choose it | | ArrowDown / ArrowUp | Move between Light, Dark and System | | Escape | Close the menu |


Accessibility

Built on @papit/menu, which follows the WAI-ARIA menu button pattern.

Known gaps:

  • The icon button has no accessible name yet, and the built-in tooltip isn't wired to it.
  • The current choice is marked with aria-expanded on its menu item rather than menuitemradio with aria-checked.
  • The labels (Light, Dark, System) aren't translated yet.

Reference: https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/


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