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

v0.1.5

Published

JS script injection utility for Tailwind CSS

Downloads

15

Readme

minified size license version twitter

tailwindcss-jstool is a plugin for Tailwind CSS that introduces the js directive, a utility that allows you to evaluate JavaScript expressions within your utility classes. This provides a flexible, dynamic approach to defining your styles.

Installation

You can install the plugin via npm:

npm install tailwindcss-jstool

Then, include it in your tailwind.config.js:

module.exports = {
  plugins: [
    require('tailwindcss-jstool'),
  ]
}

or if using a custom context object:

module.exports = {
  plugins: [
    require('tailwindcss-jstool')({
      appName: 'My app',
      // ...other values
    }),
  ]
}

Usage

The plugin provides a js directive, allowing you to use JavaScript expressions within your utility classes:

Basic Usage

For a simple use case, you can use JavaScript expressions directly in your utility classes with the js directive:

<div class="js-[content-['1_+_1_=_#{1+1}']]"></div>

This will output the following content: 1 + 1 = 2

Using Context Values

You can also use values from your context object within your utility classes:

<div class="js-[content-['The_app_name_is_#{appName}']]"></div>

This will output the following content: The app name is My app

Built-In Context Values

In addition to any custom values you pass in, the plugin also provides easy access to both the theme and config functions:

<div class="before:js-[content-['fontSize.2xl_===_#{theme('fontSize.2xl')}']]"></div>

This will output the following content: fontSize.2xl === 1.5rem

Please note that all utilities are built at runtime, so in order for a one-off utility to be random or unique, the utility will need to be unique as well. One way to ensure this is the case—when needed—is to pass some sort of custom identifier to properly seed the utility.

Other (mostly random & unrealistic) examples

<!-- Displaying all registered config keys -->
<div class="before:js-[content-['the_registered_config_keys_are_#{Object.keys(config()).join(',_')}']]"></div>

<!-- Displaying a random digit using a function from the context object -->
<div class="before:js-[content-['A_random_digit_is_#{randomDigit()}']]"></div>

<!-- Using random colors for text and text shadow, once again using a custom function from the context object -->
<div class="js-[[--random-color:#{randomColor()}]] js-[[--random-color-2:#{randomColor()}]] text-[--random-color] font-semibold [text-shadow:1px_2px_0_var(--random-color-2)]">Random_colors_ftw!</div>

<!-- Using random length for text size -->
<div class="js-[[--random-length:#{randomRange(16,22)}px]] text-[length:--random-length]">Random sizes too 🤯</div>

All of these examples can also be seen and tested here on Tailwind Play: https://play.tailwindcss.com/ZID1xrVAra

Why use tailwindcss-jstool

tailwindcss-jstool allows you to bring the power of JavaScript directly into your utility classes, enabling dynamic styles based on logic and state. This opens up endless possibilities for reactive design patterns.

This plugin is…

✨ GREAT for providing dynamic styles based on application state or logic 👏🏼

😬 NOT recommended for complex JavaScript expressions or application logic due to performance concerns 👀


I hope you find tailwindcss-jstool a valuable addition to your projects. If you have any issues or suggestions, don't hesitate to open an issue or pull request.

If you liked this, you might also like my other Tailwind CSS plugins: