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-shorthand

v1.0.3

Published

Useful tailwindcss shorthand classes and variants to boost productivity

Downloads

74

Readme

Useful tailwindcss shorthand classes and variants to boost productivity

Installation

// NPM
npm install tailwindcss-shorthand --save-dev

// YARN
yarn add tailwindcss-shorthand -D

// PNPM
pnpm add tailwindcss-shorthand -D
// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [require("tailwindcss-shorthand")()],
};

Utilities

a-$wx$h

// Before
<div class="w-5 h-10"></div>

// After
<div class="a-5x10"></div>

Arbitrary values

<div class="a-[5rem]"></div>

<div class="a-[5remx100%]"></div>

If you feel like the built-in size-5 is long, you can do a-5.

p-$yx$x

Extends the built-in p-* to declare shorthand padding.

// Before
<div class="py-5 px-10"></div>

// After
<div class="p-5x10"></div>

Note: You can still use the built-in padding utilities p-5 and p-[5rem].

m-$yx$x

Extends the built-in m-* to declare shorthand margin.

// Before
<div class="my-5 mx-10"></div>

// After
<div class="m-5x10"></div>

Note: You can still use the built-in margin utilities m-5 and m-[5rem].

gap-$yx$x

Extends the built-in gap-* to declare shorthand gap.

// Before
<div class="gap-y-5 gap-x-10"></div>

// After
<div class="gap-5x10"></div>

Note: You can still use the built-in gap utilities gap-5 and gap-[5rem].

z-*

Extend the built-in z-*.

// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [
    require("tailwindcss-shorthand")({
      // Default ["5", "10", "15", "20", "25", "30", "35", "40", "45", "50"]
      zIndexes: new Array(50).fill(null).map((_, i) => i + 1),
    }),
  ],
};

Flex alignments

// Before
<div class="justify-start items-start"></div>
<div class="justify-center items-center"></div>
<div class="justify-end items-end"></div>
<div class="justify-stretch items-stretch"></div>

// After
<div class="flex-start"></div>
<div class="flex-center"></div>
<div class="flex-end"></div>
<div class="flex-stretch"></div>

Variants

state-*:

// Before
<div className={`${isOn ? "bg-green-600" : "bg-slate-800"}`}></div>
<div data-state={ isOn ? "on" : "off" } className="bg-slate-800 data-[state=on]:bg-green-600"></div>

// After
<div data-state={ isOn ? "on" : "off" } className="bg-slate-800 state-on:bg-green-600"></div>
<div data-state={ isOn ? "on" : "off" } className="bg-slate-800 state-on:bg-green-600"></div>

You can also use the group-state-* & peer-state-* modifiers. To add custom states, see here.

$dataName-$dataValue

This is a extended version of the state-* variant.

// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [
    require("tailwindcss-shorthand")({
      // Default {}
      data: {
        align: ["left", "center", "women"],
      },
    }),
  ],
};
// Before
<div data-align={alignment} class="data-[align=left]:left-0 data-[align=top]:top-0" ></div>

// After
<div data-align={alignment} class="align-left:left-0 align-top:top-0" ></div>

1st, 2nd, 3rd, ..., 10th

// Before
<div className={`${index === 1 ? "col-span-4" : index === 2 ? "col-span-3" : "col-span-1"}`}></div>

// After
<div className="1st:col-span-4 2nd:col-span-3 col-span-1"></div>

To use the nth-of-type selector please use 1st-of, 2nd-of, 3rd-of, ..., 10th-of.

You can also use the group-1st* & peer-1st* modifiers. To add custom nths, see here.

Options

nths

Use this option to override the default child selectors.

// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [
    require("tailwindcss-shorthand")({
      // Default [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      nths: [11, 99],
    }),
  ],
};
<div class="11th:w-10"></div>
<div class="11th-of:w-10"></div>

states

Use this option to override the default states variants.

// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [
    require("tailwindcss-shorthand")({
      // Default ["open", "closed", "active", "inactive", "on", "off", "checked", "unchecked", "visible", "hidden", "expanded", "collapsed", "loading", "loaded", "selected", "success", "error", "enabled", "disabled"]
      states: ["pending"],
    }),
  ],
};
<div class="state-pending:w-10"></div>

separator

Use the separator option to override the default separator(x) in shorthand utilities.

// tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [
    require("tailwindcss-shorthand")({
      // Default "x"
      separator: "-",
    }),
  ],
};
<div class="a-5-10"></div>
<div class="a-[5rem-10rem]"></div>