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

@tailwind-plugin/expose-colors

v1.1.8

Published

Tailwind CSS plugin that exposes Tailwind colors as custom CSS properties

Downloads

2,475

Readme

Introduction

This is a pretty much straight-forward Tailwind plugin that allows you to expose Tailwind's colors and their shades, including any custom ones included in your own theme, as custom CSS properties on the :root element. This can be useful for maintaining a consistent color theme across your project and easily accessing Tailwind colors in your stylesheets.

Requirements

This plugin is built upon TailwindCSS. Therefore, TailwindCSS v3.0.0 is at least required. Get started here.

It's also recommended that you have a basic understanding of CSS and how to install Tailwind plugins. Learn more about Tailwind plugins here.

Install

Install the plugin from npm:

npm i -D @tailwind-plugin/expose-colors

Then add the plugin to your tailwind.config.js file:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwind-plugin/expose-colors'),
    // ...
  ],
}

Usage options

extract

| Option | Type | Default | Description | | --------- | ----------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | extract | string \| Array | 'all' | Specify the color keys as an array to extract. Use 'all' to extract all colors or provide an array of all color keys. |

📌 You can extract colors from Tailwind's default color palette, or your custom ones declared in your theme.

⚠️ Exposing 'all' Tailwind's colors, will increase the filesize of your bundled CSS file by 7.76 kB

Example:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    colors: {
      // your custom colors
      midnight: '#121063',
      tahiti: {
        100: '#cffafe',
        200: '#a5f3fc',
        300: '#67e8f9',
        // ...
      },
    },
    // ...
  },
  plugins: [
    require('@tailwind-plugin/expose-colors')({
      extract: ['yellow', 'blue', 'midnight', 'tahiti'],
    }),
    // ...
  ],
}

Exposed colors:

  ::root {
    --tw-yellow-50: #FEFCE8;
    --tw-yellow-100: #FEF9C3;
    --tw-yellow-200: #FEF08A;
    ...
    --tw-midnight: #121063;
    --tw-tahiti-100: #CFFAFE;
    --tw-tahiti-200: #A5F3FC;
    --tw-tahiti-300: #67E8F9;
    ...
  }

prefix

| Option | Type | Default | Description | | -------- | -------- | ------- | ------------------------------------------------------------------- | | prefix | string | --tw | Customize the prefix for CSS variables. The default prefix is --tw. |

Example:

/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  plugins: [
    require('@tailwind-plugin/expose-colors')({
      prefix: '--color',
    }),
  ],
}

Exposed colors:

  ::root {
    --color-midnight: #121063;
    --color-tahiti-100: #CFFAFE;
    --color-tahiti-200: #A5F3FC;
    --color-tahiti-300: #67E8F9;
    ...
  }

mode

| Option | Type | Default | Description | | ------ | ---------------- | ------- | ----------------------------------------------------------------------------------------------------- | | mode | 'hex' \| 'rgb' | hex | Choose the color mode for extracted colors. Use 'hex' for hexadecimal colors or 'rgb' for RGB colors. |

Example:

/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  plugins: [
    require('@tailwind-plugin/expose-colors')({
      mode: 'rgb',
    }),
  ],
}

Exposed colors:

  ::root {
    --tw-midnight: 18, 16, 99;
    --tw-tahiti-100: 207, 250, 254;
    --tw-tahiti-200: 165, 243, 252;
    --tw-tahiti-300: 103, 232, 249;
    ...
  }

The exposed variable colors will be in 'rgb' format so you can use them like so:

.myclass {
  background: rgba(var(--tw-tahiti-500), 0.8);
}

Authors

Based on Merott Movahedi's and Rafael R. Camargo's snippet. Developed, modified and maintained by George Cht.

License

MIT License