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

astro-color-scheme

v1.1.5

Published

Perfect dark mode for Astro in few lines of code. Theme Toggle for Dark, Light & Auto (system)

Downloads

538

Readme

Astro Color Scheme

Astro Color Scheme is a fully headless dark mode theme toggle for Astro.

Live Demo on Stackblitz →

Live Demo on Stablo Template →

Installation

npm install astro-color-scheme
# or
pnpm add astro-color-scheme

Basic Usage

You can toggle the theme using button, select, checkbox or radio inside the <ThemeSwitch>.

---
import { ThemeSwitch } from "astro-color-scheme";
---

<div>
  <ThemeSwitch strategy="button">
    <button>Toggle Theme</button>
  </ThemeSwitch>
</div>

Using Select:

---
import { ThemeSwitch } from "astro-color-scheme";
---

<div>
  <ThemeSwitch strategy="select" defaultTheme="system">
    <select>
      <option value="system">System</option>
      <option value="dark">Dark</option>
      <option value="light">Light</option>
    </select>
  </ThemeSwitch>
</div>

Using Radio:

---
import { ThemeSwitch } from "astro-color-scheme";
---

<div>
  <ThemeSwitch strategy="radio" defaultTheme="system" as="div">
    <form>
      <label><input type="radio" name="theme" value="system" />System</label>
      <label><input type="radio" name="theme" value="dark" />Dark</label>
      <label><input type="radio" name="theme" value="light" />Light</label>
    </form>
  </ThemeSwitch>
</div>
---
import { ThemeSwitch } from "astro-color-scheme";
---

<div>
  <ThemeSwitch defaultTheme="dark"/>
</div>

Options

Options for ThemeSwitch

| option | required | notes | | -------------- | ---------------------------- | --------------------------------------------------------------- | | strategy | required if you use toggle | Possible values: button, checkbox, select or radio | | defaultTheme | optional | Default: system, Possible values: light, dark or system | | as | optional | Default: span, Possible values: div, span |

The as option lets you select what wrapper element to use for the ThemeSwitch. Elements Allowed for Toggle inside ThemeSwitch are <button>, <input type=checkbox>, <select>, <form>.

<!-- Button -->
<button>Toggle Theme</button>

<!-- Checkbox -->
<input type="checkbox" />

<!-- Select -->
<select>
  <option value="system">System</option>
  <option value="dark">Dark</option>
  <option value="light">Light</option>
</select>

Customizations

As a headless plugin, You are free to add your own styles and icons based on the theme.

Here's an example on how to add custom styles using css variables.

<style>
  html {
    --background-color: white;
    --text-color: black;
    color: var(--text-color);
    background-color: var(--background-color);
  }
  .dark {
    --background-color: black;
    --text-color: white;
  }
  /* OR */
  [data-theme="dark"] {
    --background-color: black;
    --text-color: white;
  }
</style>

Here's an example shows usage of Astro Icon.

---
import { Icon } from "astro-icon";
import { ThemeSwitch } from "astro-color-scheme";
---

<div>
  <ThemeSwitch strategy="button">
    <button>
      <span class="sr-only">Toggle Theme</span>
      <Icon class="dark:hidden" name="heroicons-outline:sun" />
      <Icon class="hidden dark:block" name="heroicons-outline:moon" />
    </button>
  </ThemeSwitch>
</div>

This plugin also supports custom checkbox switch with animations. Just use strategy="checkbox" and add your content. By default we add dark/light class into the html as well as data-theme attribute. Here's how it would look like:

<html lang="en" class="dark" data-theme="dark"></html>

Tailwind CSS

This plugin should work well with regular CSS as well as Tailwind CSS. You can style the dark mode using dark: modifier to add custom icon based on the chosen theme. Make sure you change the darkMode to class to make this work.

// tailwind.config.cjs
 darkMode: "class",

Contribute

Please create an issue.

Credits

Copyright ©️ 2023-2099. Surjith S M.