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-group-modifier-plugin

v0.1.1

Published

A plugin for Tailwind CSS v3.0+ that allows the grouping of various modifiers:

Downloads

183

Readme

tailwindcss-group-modifier-plugin

A plugin for Tailwind CSS v3.0+ that allows the grouping of various modifiers:

From this:

<input type="text" value="tbone" disabled class="mt-1 block w-full px-3 py-2 bg-white border border-slate-300 
rounded-md text-sm shadow-sm placeholder-slate-400
      focus:outline-none focus:border-sky-500 focus:ring-1 focus:ring-sky-500
      disabled:bg-slate-50 disabled:text-slate-500 disabled:border-slate-200 disabled:shadow-none
      invalid:border-pink-500 invalid:text-pink-600
      focus:invalid:border-pink-500 focus:invalid:ring-pink-500
    "/>

To this:

<input type="text" value="tbone" disabled class="mt-1 block w-full px-3 py-2 bg-white border border-slate-300 
rounded-md text-sm shadow-sm placeholder-slate-400
      focus:x-[outline-none,border-sky-500,ring-1 ring-sky-500]
      disabled:x-[bg-slate-50,text-slate-500,border-slate-200,shadow-none]
      invalid:x-[border-pink-500,text-pink-600]
      focus:invalid:-x[border-pink-500,ring-pink-500]
    "/>

Table of contents

Installation

$ npm i tailwind-css-group-modifier-plugin
$ yarn add tailwind-css-group-modifier-plugin
$ pnpm i tailwind-css-group-modifier-plugin

Usage

// tailwind.config.ts/js
import groupModifierPlugin from "tailwindcss-group-modifier-plugin";
export default {
 // ...
  plugins: [groupModifierPlugin()],
};

Options

prefix

type: string default: x Allows changing the prefix from x to anything else.

default syntax:

<input type="text" required class="invalid:x-[bg-blue-500,outline,shadow-md,shadow-red-500] focus:x-[text-blue-500]" />

with a different prefix:

export default {
 // ...
  plugins: [groupModifierPlugin({prefix: "myPrefix"})],
};
<input type="text" required class="invalid:myPrefix-[bg-blue-500,outline,shadow-md,shadow-red-500] focus:myPrefix-[text-blue-500]" />

How does it work?

The plugin converts the grouped syntax into a single class containing the grouped classes styles within it:

This:

<input type="text" required class="invalid:x-[bg-blue-500,outline,shadow-md,shadow-red-500] focus:x-[text-blue-500]" />

Generates this:


.invalid\:x-\[bg-blue-500\2c outline\2c shadow-md\2c shadow-red-500\]:invalid{
  --tw-bg-opacity: 1;
  background-color: rgb(59 130 246 / var(--tw-bg-opacity));
  --tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
  --tw-shadow-color: #ef4444;
  --tw-shadow: var(--tw-shadow-colored);
  outline-style: solid
}

.focus\:x-\[text-blue-500\]:focus{
  --tw-text-opacity: 1;
  color: rgb(59 130 246 / var(--tw-text-opacity))
}

Constraints

  • Please avoid using whitespaces between the grouped commas as spaces are token separators in css so x-[a, b] will be considered two different classes, i.e x-[a, and b]
  • Avoid using - in your custom prefix name as - is used as a separator between a value and its data
  • Using this plugin will add additional classes to your file.

Credits

A big thanks goes to @wongjn for suggesting a solution for this problem here: https://github.com/tailwindlabs/tailwindcss/discussions/11701#discussioncomment-6569866

Prior art can be found here

My original issue for this thing

A Twitter thread the creator of Tailwind, Adam Wathan

A discussion around natively supporting it