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

@figliolia/galena-dark-mode

v1.0.6

Published

A Dark Mode Manager for Galena Apps

Downloads

430

Readme

Galena Dark Mode

A Dark Mode manager for Galena Apps. Effortlessly manage dark/light mode themes!

Installation

npm i @figliolia/galena @figliolia/galena-dark-mode
# or
yarn add @figliolia/galena @figliolia/galena-dark-mode

Basic Usage

// Theme.ts
import { DarkModeManager } from "@figliolia/galena-dark-mode";

export const Theme = new DarkModeManager(theme => {
  // Optional callback to execute when theme changes
});

// Begin listening for changes to user operating system preferences
Theme.initialize();

// Toggle between Dark and Light Theme
Theme.toggle();

// Set Dark or Light Mode
Theme.set("<dark | light>");

// Listen for changes
Theme.subscribe(({ theme }) => {
  // Your logic
})

// Clean up and remove operating system listeners
Theme.destroy();

Targetting Your Theme with CSS

By default, the DarkModeManager will add a [data-theme] attribute to the HTML document whenever the theme changes. The value associated with [data-theme] will be 'light' or 'dark'.

[data-theme] can be targetted in your CSS using:

:root {
  --background: #fff;
  --text-color: #292929;
 /* ...and so on */
}

html[data-theme='dark'] {
  --background: #292929;
  --text-color: #fff;
  /* ...and so on */
}

Integrating With React Apps

Installation

npm i @figliolia/react-galena
# or
yarn add @figliolia/react-galena

Basc Usage

The when calling new DarkModeManager(), a State instance is returned. You can generate useState and useMutation hooks using:

// Theme.ts

import { DarkModeManager } from "@figliolia/galena-dark-mode";
import { createUseState, createUseMutation } from "@figliolia/react-galena";

export const Theme = new DarkModeManager();
export const useTheme = createUseState(Theme);
export const useThemeMutation = createUseMutation(Theme);

You can also initialize and destroy your theme instance in your root component:

// App.tsx

import { memo } from "react";
import { useSetup } from "@figliolia/galena-dark-mode";
import { Theme, useTheme } from "./Theme";

export const App = memo(function App() {
  // Initialize!
  useSetup(Theme);

  // Get the current theme
  const theme = useTheme(({ theme }) => theme);

  return (
    <>
      <p>The Current Theme: {theme}</p>
      <button onClick={Theme.toggle}>
        Go {theme === "dark" ? "Light" : "Dark"}
      </button>
    </>
  );
})

Demo

The following demo uses CSS Custom properties for a smooth transition between themes. This feature is not available in all browsers, but baseline support is growing.

Demo