{"id":22547849,"url":"https://github.com/toolwind/js","last_synced_at":"2025-07-26T12:12:51.591Z","repository":{"id":175277604,"uuid":"653613173","full_name":"toolwind/js","owner":"toolwind","description":"Interpolate JS values inline in Tailwind CSS utility values. The use cases are few, but it sure is neat 👏🏼","archived":false,"fork":false,"pushed_at":"2024-05-12T12:53:40.000Z","size":623,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T09:29:50.843Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toolwind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-14T11:40:42.000Z","updated_at":"2025-07-03T22:23:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"e40a5882-b825-46c7-a9ab-bf1a5c99f15f","html_url":"https://github.com/toolwind/js","commit_stats":null,"previous_names":["brandonmcconnell/jstool-for-tailwindcss","brandonmcconnell/tailwindcss-jstool","brandonmcconnell/tailwindcss-js","brandonmcconnell/tailwindcss-js-context","toolwind/js"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/toolwind/js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolwind%2Fjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolwind%2Fjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolwind%2Fjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolwind%2Fjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolwind","download_url":"https://codeload.github.com/toolwind/js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolwind%2Fjs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266760906,"owners_count":23980279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T15:13:11.545Z","updated_at":"2025-07-26T12:12:51.351Z","avatar_url":"https://github.com/toolwind.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003eJS Context for Tailwind CSS\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![minified size](https://img.shields.io/bundlephobia/min/tailwindcss-js-context)](https://bundlephobia.com/package/tailwindcss-js-context)\n[![license](https://img.shields.io/github/license/brandonmcconnell/tailwindcss-js-context?label=license)](https://github.com/brandonmcconnell/tailwindcss-js-context/blob/main/LICENSE)\n[![version](https://img.shields.io/npm/v/tailwindcss-js-context)](https://www.npmjs.com/package/tailwindcss-js-context)\n[![twitter](https://img.shields.io/twitter/follow/branmcconnell)](https://twitter.com/branmcconnell)\n\n\u003c/div\u003e\n\n`tailwindcss-js-context` 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.\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Usage](#basic-usage)\n  - [Using Context Values](#using-context-values)\n  - [Built-In Context Values](#built-in-context-values)\n  - [Other (mostly random \\\u0026 unrealistic) examples](#other-mostly-random--unrealistic-examples)\n- [Why use `tailwindcss-js-context`](#why-use-tailwindcss-js-context)\n- [New syntax explanation](#new-syntax-explanation)\n\n\u003e [!WARNING]\n\u003e **Syntax change:** The value between the brackets in the `js` directive must now be quoted, due to a breaking change introduced in Tailwind CSS v3.3.6.\n\u003e ```\n\u003e ❌ js-[content-['1_+_1_=_#{1+1}']]\n\u003e ✅ js-['content-['1_+_1_=_#{1+1}']']\n\u003e        ^                          ^\n\u003e ```\n\u003e See the [New syntax explanation](#new-syntax-explanation) section for more information.\n\n## Installation\n\nYou can install the plugin via npm:\n\n```bash\nnpm install tailwindcss-js-context\n```\n\nThen, include it in your `tailwind.config.js`:\n\n```js\nmodule.exports = {\n  plugins: [\n    require('tailwindcss-js-context'),\n  ]\n}\n```\n\nor if using a custom context object:\n\n```js\nmodule.exports = {\n  plugins: [\n    require('tailwindcss-js-context')({\n      // ...any values, e.g.\n      appName: 'My app',\n    }),\n  ]\n}\n```\n\n## Usage\n\nThe plugin provides a `js` directive, allowing you to use JavaScript expressions within your utility classes:\n\n### Basic Usage\n\nFor a simple use case, you can use JavaScript expressions directly in your utility classes with the `js` directive:\n\n```html\n\u003cdiv class=\"before:js-['content-['1_+_1_=_#{1+1}']']\"\u003e\u003c/div\u003e\n```\n\nThis will output the following content: `1 + 1 = 2`\n\n### Using Context Values\n\nYou can also use values from your context object within your utility classes:\n\n```html\n\u003cdiv class=\"before:js-['content-['The_app_name_is_#{appName}']']\"\u003e\u003c/div\u003e\n```\n\nThis will output the following content: `The app name is My app`\n\n### Built-In Context Values\n\nIn addition to any custom values you pass in, the plugin also provides easy access to both the `theme` and `config` functions:\n\n```html\n\u003cdiv class=\"before:js-['content-['fontSize.2xl_===_#{theme('fontSize.2xl')}']']\"\u003e\u003c/div\u003e\n```\n\nThis will output the following content: `fontSize.2xl === 1.5rem`\n\nPlease 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.\n\n### Other (mostly random \u0026 unrealistic) examples\n\n```html\n\u003c!-- Checking equality of values --\u003e\n\u003cdiv class=\"before:js-['content-['fontSize.2xl_===_#{theme('fontSize.2xl')}']']\"\u003e\u003c/div\u003e\n\n\u003c!-- Displaying all registered config keys --\u003e\n\u003cdiv class=\"before:js-['content-['the_registered_config_keys_are_#{Object.keys(config()).join(',_')}']']\"\u003e\u003c/div\u003e\n\n\u003c!-- Displaying a random digit using a function from the context object --\u003e\n\u003cdiv class=\"before:js-['content-['A_random_digit_is_#{randomDigit()}']']\"\u003e\u003c/div\u003e\n\n\u003c!-- Using random colors for text and text shadow, once again using a custom function from the context object --\u003e\n\u003cdiv class=\"font-semibold text-[--random-color] js-['[--random-color-2:#{randomColor()}]'] js-['[--random-color:#{randomColor()}]'] [text-shadow:1px_2px_0_var(--random-color-2)]\"\u003eRandom_colors_ftw!\u003c/div\u003e\n\n\u003c!-- Using random length for text size --\u003e\n\u003cdiv class=\"text-[length:--random-length] js-['[--random-length:#{randomRange(16,22)}px]']\"\u003eRandom sizes too 🤯\u003c/div\u003e\n```\n\u003csup\u003e[View this example on Tailwind Play](https://play.tailwindcss.com/l4VSXZP2gd)\u003c/sup\u003e\n\n## Why use `tailwindcss-js-context`\n\n`tailwindcss-js-context` 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.\n\nThis plugin is…\n\n✨ GREAT for providing dynamic styles based on application state or logic 👏🏼\n\n😬 NOT recommended for complex JavaScript expressions or application logic due to performance concerns 👀\n\n## New syntax explanation\n\n```html\n\u003c!-- ❌ before --\u003e\n\u003cdiv class=\"before:js-content-['1_+_1_=_#{1+1}']]\"\u003e\u003c/div\u003e\n\n\u003c!-- ✅ after --\u003e\n\u003cdiv class=\"before:js-['content-['1_+_1_=_#{1+1}']']\"\u003e\u003c/div\u003e\n```\n\u003csup\u003e[View a similar example on Tailwind Play](https://play.tailwindcss.com/SSN6P4Vcme)\u003c/sup\u003e\n\nThe release of [Tailwind CSS v3.3.6](https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.3.6) (on Dec 4, 2023) introduced breaking changes that made the original syntax of JS for Tailwind CSS incompatible with newer versions of Tailwind CSS.\n\nSee [tailwindlabs/tailwindcss#13473](https://github.com/tailwindlabs/tailwindcss/issues/13473) for the discussion that led to this new syntax.\n\nThis change required a slight tweak to the syntax of the `js` directive. Instead of `js-[...]`, use `js-['...']` (with a quoted value between the brackets) to pass the grouped utilities together as a string.\n\nVersions of Tailwind CSS thereafter (v3.3.6+) are now incompatible with versions of the original unquoted syntax for this plugin (pre-v0.2.0). Update to `@latest` to ensure compatibility. This new version syntax is reverse-compatible with versions of Tailwind CSS prior to v3.3.6 as well.\n\nPassing the joined strings together as a string allows the Tailwind CSS parser (again, in Tailwind CSS v3.3.6+) to see the value as a valid CSS value and process it as expected.\n\n---\n\nI hope you find `tailwindcss-js-context` a valuable addition to your projects. If you have any issues or suggestions, don't hesitate to open an issue or pull request.\n\nIf you liked this, you might also like my other Tailwind CSS plugins:\n* [tailwindcss-multi](https://github.com/brandonmcconnell/tailwindcss-multi): Group utilities together by variant\n* [tailwindcss-signals](https://github.com/brandonmcconnell/tailwindcss-signals): Apply styles based on parent or ancestor state, a state-driven alterative to groups\n* [tailwindcss-members](https://github.com/brandonmcconnell/tailwindcss-members): Apply styles based on child or descendant state, the inverse of groups\n* [tailwindcss-mixins](https://github.com/brandonmcconnell/tailwindcss-mixins): Construct reusable \u0026 aliased sets of utilities inline\n* [tailwindcss-selector-patterns](https://github.com/brandonmcconnell/tailwindcss-selector-patterns): Dynamic CSS selector patterns\n* [tailwindcss-directional-shadows](https://github.com/brandonmcconnell/tailwindcss-directional-shadows): Supercharge your shadow utilities with added directional support (includes directional `shadow-border` utilities too ✨)\n* [tailwindcss-default-shades](https://github.com/brandonmcconnell/tailwindcss-default-shades): Default shades for simpler color utility classes\n* [tailwind-lerp-colors](https://github.com/brandonmcconnell/tailwind-lerp-colors): Expand your color horizons and take the fuss out of generating new—or expanding existing—color palettes","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolwind%2Fjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolwind%2Fjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolwind%2Fjs/lists"}