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

@datarose/tailwindcss-theme-colors

v0.1.1

Published

Easily manage multiple themes

Downloads

209

Readme

The package was inspired by the tw-colors package. Its purpose is to enable easy management of custom templates, allowing us to create unique colors using existing color scales. With light and dark themes, we can fully customize the appearance.

Installation

Supports

  • Vite >=5
  • Node >=21
npm install @datarose/tailwindcss-theme-colors --save-dev

Startup

tailwind.config.js

import { createThemes } from '@datarose/tailwindcss-theme-colors'

/** @type {import('tailwindcss').Config} */
export default {
  plugins: [
    createThemes({
      light: {
        primary: '#fff',
        secondary: '#555',
        red: {
          50: '...',
          100: '...',
        },
        green: {
          lighter: '...',
          light: '...',
          dark: '...',
          darker: '...',
          nested: {
            50: '...',
            100: '...',
          },
        },
      },
      dark: {
        primary: '#000',
        secondary: '#ccc',
        red: {
          50: '...',
          100: '...',
        },
        green: {
          lighter: '...',
          light: '...',
          dark: '...',
          darker: '...',
          nested: {
            50: '...',
            100: '...',
          },
        },
      },
      'custom-theme-name': {
        'custom-color-name': 'custom-color-code',
      },
    })
  ],
}

Set default themes

If no template is selected, or the selected template name does not exist, this template will be loaded instead.

createThemes({
  light: {
    primary: '#fff',
    secondary: '#555',
  },
  dark: {
    primary: '#000',
    secondary: '#ccc',
  },
}, {
  defaultTheme: 'dark',
})

Select theme

With class name (can select X theme with .theme-X class-name)

<html class='theme-light'>
  <div>
      <h1 class='text-primary'>...</h1>
      <p class='text-secondary'>...</p>
  </div>
</html>

With data-theme attribute (can select X theme with data-theme="X" class-name)

<html data-theme='light'>
  <div>
    <h1 class='text-primary'>...</h1>
    <p class='text-secondary'>...</p>
  </div>
</html>

Select nested theme

With data-theme attribute

<html data-theme='dark'>
  ...
  <div data-theme='coffee'>...</div>
  <div data-theme='sky'>...</div>
</html>

With class name

For variants to work properly in nested themes, an empty data-theme attribute must be added alongside the nested theme class.

<html class='dark'>
  ...
  <div data-theme class='coffee'>...</div>
  <div data-theme class='sky'>...</div>
</html>

Use prefers-color-scheme: light/dark

By embedding theme objects within the light and dark functions, we can designate them as light or dark themes. If a theme object is embedded in the light function, it is classified as a light-mode theme. If a user who prefers dark mode opens the page, this theme will not work for them.

createThemes(({ light, dark }) => {
  light: light({
    primary: '#fff',
    secondary: '#555',
  }),
  dark: dark({
    primary: '#000',
    secondary: '#ccc',
  }),
})

Set default themes to light and dark modes

This way, even without selecting a theme, we can assign our desired default theme to both light and dark modes.

createThemes(({ light, dark }) => {
  light: light({
    primary: '#fff',
    secondary: '#555',
  }),
  coffee: light({
    primary: '#123456',
    secondary: '#654321',
  }),
  dark: dark({
    primary: '#000',
    secondary: '#ccc',
  }),
  sky: dark({
    primary: '#111',
    secondary: '#333',
  }),
}, {
  defaultTheme: {
    light: coffee, // when `@media (prefers-color-scheme: light)` is matched
    dark: space, // when `@media (prefers-color-scheme: dark)` is matched
  },
})

Variants

Based on the current theme, specific styles can be applied using variants. Note: In the following example the variants would have no effect with data-theme='light'

<!-- Use "serif" font for the dark theme only -->
<div data-theme='dark' class='font-sans theme-dark:font-serif'>
  ...
  <div>Serif font here</div>

  <!-- this button is rounded when the theme is `dark` -->
  <button class='theme-dark:rounded'>Click Me</button>
</div>

Caveat: group-{modifier}

Always use the group variant before the theme variant.

<html class='theme-dark'>
  ...
  <div class='group'>
    <div class='theme-dark:group-hover:bg-red-500'>
      ❌ the group variant does not work
    </div>
    <div class='group-hover:theme-dark:bg-red-500'>
      ✅ the group variant works properly
    </div>
  </div>    
</html>

Configurations

createThemes(({ light, dark }) => {
  // theme list...
}, {
  produceCssVariable: (colorName) => `--custom-color-css-variable-name-${colorName}`, // default: --twtc-${colorName}
  produceThemeClass: (themeName) => `custom-theme-class-name-${themeName}`, // default: theme-${themeName}
  produceThemeVariant: (themeName) => `custom-theme-variant-name-${themeName}`, // default: theme-${themeName}
  defaultTheme: {
    light: coffee, // set default theme to light mode
    dark: space, // set default theme to dark mode
  },
  strict: false, // an error will be thrown when a theme doesn't exist // default: false
})

Early Access

The package is still very primitive, and we have many more plans for the future. We aim to boost our design with easily customizable and interchangeable templates.

Open Source Repository

While we haven't opened the plugin's repository to the public yet, we are actively working towards doing so and fostering an active community to improve the package's quality.

License

All rights reserved as specified in the LICENSE file! This project can be considered reusable, copyable, and/or distributable, provided that the original public repository link is included in the source code and made visible to those who use the product that incorporates this source code/package.