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

tailwindcss-color-mix

v0.0.8

Published

A plugin for TailwindCSS to build new colors by mixing two existing ones.

Downloads

5,193

Readme

tailwindcss-color-mix

Banner

Live demo

A plugin for TailwindCSS to build new colors by mixing two existing ones.

Use bg-red-500 bg-mix-black bg-mix-amount-50 to partially overlay black over the red-500 shade.

This is achieved with native CSS color-mix, so all colors in the palette can be mixed with each other.

Installation

First, install the package:

npm install --save tailwindcss-color-mix

Then, import it in tailwind.config.js:

  const colorMix = require('tailwindcss-color-mix');

  module.exports = {
    ...
    plugins: [
      ...,
      colorMix()
    ]
  }

Usage

  • bg-red bg-mix-black bg-mix-amount-50 will mix 50% black into red.
    • In CSS terms, the result will be color-mix(in srgb, black 50%, red).

You can also use arbitrary percentage values for amount such as bg-mix-amount-[42%].

The default mix amount is zero.

Interpolation method

Default interpolation method is srgb but you can also use hsl shorter hue or hsl longer-hue with the bg-mix-method-shorter-hue and bg-mix-method-longer-hue utilities.

Example: interaction states

The plugin is usage-agnostic, but the original motivation behind it is the state layers concept from the Material Design system.

The system defines interactive surfaces given their background color and their text color. When hovered or pressed, the background on an interacive surface is overlayed with a predetermined opacity of its text color. This helps to create consistent interaction states with no extra effort.

In vanilla Tailwind syntax, that would force us to define extra shades for every combination of background and text colors we need.

With this plugin, an interactive surface can be defined as bg-red-800 text-white bg-mix-white hover:bg-mix-amount-8 active:bg-mix-amount-12, if 8 and 12 exist in the background opacity theme config.

Plugin options

You can customize the generated utility names by passing options to the plugin, like this:

tailwind.config.js:

  const colorMix = require('tailwindcss-color-mix');

  module.exports = {
    ...
    plugins: [
      ...,
      colorMix({
        bgMix: 'bg-overlay',
        bgMixAmount: 'overlay-amount',
        bgMixMethod: 'overlay-method'
      })
    ]
  }

With the above configuration, instead of bg-mix-black bg-mix-50 bg-mix-method-shorter-hue, you would use bg-overlay-black overlay-amount-50 overlay-method-shorter-hue.

Other color properties

I haven't found the need to extend this library to other properties such as text color, border, fill, stroke, ring... but it shouldn't be hard to do so. Feel free to open a feature request if you need color mixing on one or more specific properties.