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

@nosirjonov/dark-mode

v1.0.5

Published

A simple dark mode web component

Readme

@nosirjonov/dark-mode

A simple, customizable dark mode web component that allows you to toggle between dark and light themes in your web applications. The component automatically detects the system's theme preference and can store the user's selection in localStorage.

Features

  • Toggle between light and dark modes.

  • Automatically detects system color scheme preference.

  • Saves the theme preference in localStorage for persistent theming.

  • Customizable icons for both light and dark themes.

  • Supports custom CSS styling for dark and light modes.

Installation

You can install the package via npm:

yarn add @nosirjonov/dark-mode

pnpm add @nosirjonov/dark-mode

npm install @nosirjonov/dark-mode

Alternatively, you can include it via a script tag directly in your HTML file:

<script src="https://unpkg.com/@nosirjonov/dark-mode"></script>

Usage

To use the dark mode toggle in your HTML, simply add the component.

Basic Example

HTML

<body>
  <dark-mode></dark-mode>
</body>

Or in a React or other JSX environment:

import '@nosirjonov/dark-mode';

const ToggleMode () => {
  return (
    <dark-mode></dark-mode>
  )
}

Or in a Vue environment:

import '@nosirjonov/dark-mode';

<template>
  <dark-mode></dark-mode>
</template>

Attributes

  • light-icon (optional): Set the SVG or text for the icon displayed when light mode is active.

  • dark-icon (optional): Set the SVG or text for the icon displayed when dark mode is active.

<dark-mode 
  light-icon="<svg>...</svg>" 
  dark-icon="<svg>...</svg>"
  >
</dark-mode>

Note: Safe SVGs without XSS attacks

By default, the component will show 🌞 for light mode and 🌒 for dark mode if no icons are provided.

Customizing Styles

To customize the dark and light modes, you can add your own CSS rules targeting the data-theme attribute on the document.documentElement.

[data-theme="dark"] {    
  background-color: #0d1117;    
  color: #c9d1d9;  
}  

[data-theme="light"] {    
  background-color: #ffffff;    
  color: #24292f;  
}

API

Properties

  • mode: The current theme, either 'light' or 'dark'. You can get and set this property to manually switch between themes.

Methods

  • toggleMode(): Toggle between dark and light modes. When the mode changes, it updates the localStorage and the page's theme.

Events

  • themeChanged: Fired when the theme is changed, either by user interaction or system preference.

Example: Integrating with Your Web App

HTML

<script src="https://unpkg.com/@nosirjonov/dark-mode"></script>

JavaScript (Optional)

If you want to manually control the theme, you can access the component instance:

const darkModeToggle = document.querySelector('dark-mode'); 
darkModeToggle.toggleMode(); // Toggle the theme manually

Contributing

Feel free to fork the project and submit issues or pull requests. Contributions are always welcome!

License

This project is licensed under the ISC License.# dark-mode-component