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

theme-switcher-compostrap

v1.0.3

Published

Bootstrap 5 theme switcher with optional icon and label support.

Downloads

677

Readme

Theme Switcher

Bootstrap 5.3 theme switcher with optional icon and label support.

License: MIT npm version Build status

Installation

npm install theme-switcher-compostrap

Usage

import 'theme-switcher-compostrap/theme-switcher.css';
import { ThemeSwitcher } from 'theme-switcher-compostrap';

new ThemeSwitcher().initialize();

Use a simple text switch:

<button type="button" class="btn btn-link theme-switcher" data-theme-switcher>
	<span data-theme-switcher-label>Dark mode</span>
</button>

Or add an icon from any icon library used by your project:

<button
	type="button"
	class="btn btn-link theme-switcher"
	data-theme-switcher
	data-theme-light-icon="fa-solid fa-sun"
	data-theme-dark-icon="fa-solid fa-moon"
>
	<i data-theme-switcher-icon></i>
	<span data-theme-switcher-label>Dark mode</span>
</button>

The package does not install an icon library. Use Font Awesome, Bootstrap Icons, or any other icon set. Labels and icon classes can be configured directly in HTML with data-* attributes or globally in JavaScript options.

Built on

Introduction

The switcher updates Bootstrap's global theme by changing data-bs-theme on the <html> element. The selected theme is stored in localStorage, so it is remembered on subsequent visits.

<html lang="en" data-bs-theme="light">

Styles

Import the bundled CSS:

import 'theme-switcher-compostrap/theme-switcher.css';

Or import the SCSS source in your Sass entry point:

@import "theme-switcher-compostrap/src/scss/theme-switcher";

The bundled CSS only aligns the optional icon and label. Colors should come from your layout, for example Bootstrap nav-link classes or your own navbar styles.

Custom labels

Use data attributes when the text should be translated by your application or template system:

<button
	type="button"
	data-theme-switcher
	data-theme-light-label="Light mode"
	data-theme-dark-label="Dark mode"
>
	<span data-theme-switcher-label></span>
</button>

data-theme-light-label is shown when the current theme is dark and the button switches to light mode. data-theme-dark-label is shown when the current theme is light and the button switches to dark mode.

The shorter data-light-label and data-dark-label attributes are also supported.

You can also configure labels from JavaScript:

<button type="button" data-theme-switcher>
	<span data-theme-switcher-label></span>
</button>
new ThemeSwitcher({
	lightLabel: 'Light mode',
	darkLabel: 'Dark mode',
}).initialize();

Custom icons

Icons are optional. Add an element with data-theme-switcher-icon only when your project loads an icon library.

Set icon classes in HTML:

<button
	type="button"
	data-theme-switcher
	data-theme-light-icon="fa-solid fa-sun"
	data-theme-dark-icon="fa-solid fa-moon"
>
	<i data-theme-switcher-icon></i>
	<span data-theme-switcher-label></span>
</button>

Or configure icon classes from JavaScript:

<button type="button" data-theme-switcher>
	<i data-theme-switcher-icon></i>
	<span data-theme-switcher-label></span>
</button>
new ThemeSwitcher({
	lightIcon: 'fa-solid fa-sun',
	darkIcon: 'fa-solid fa-moon',
}).initialize();

Bootstrap Icons work the same way:

<button
	type="button"
	data-theme-switcher
	data-theme-light-icon="bi bi-sun-fill"
	data-theme-dark-icon="bi bi-moon-fill"
>
	<i data-theme-switcher-icon></i>
	<span data-theme-switcher-label></span>
</button>

The shorter data-light-icon and data-dark-icon attributes are also supported.

Options

new ThemeSwitcher({
	selector: '[data-theme-switcher]',
	storageKey: 'bootstrap-theme',
	defaultTheme: 'light',
	lightIcon: '',
	darkIcon: '',
	lightLabel: 'Light mode',
	darkLabel: 'Dark mode',
}).initialize();

Events

The switcher dispatches a theme-switcher:change event on window after each theme update:

window.addEventListener('theme-switcher:change', (event) => {
	console.log(event.detail.theme);
});