An open API service indexing awesome lists of open source software.

https://github.com/toolwind/tagged-combinators


https://github.com/toolwind/tagged-combinators

Last synced: 9 days ago
JSON representation

Awesome Lists containing this project

README

          

Tagged Combinators for Tailwind CSS

[![minified size](https://img.shields.io/bundlephobia/min/@toolwind/tagged-combinators)](https://bundlephobia.com/package/@toolwind/tagged-combinators)
[![license](https://img.shields.io/github/license/brandonmcconnell/@toolwind/tagged-combinators?label=license)](https://github.com/brandonmcconnell/@toolwind/tagged-combinators/blob/main/LICENSE)
[![version](https://img.shields.io/npm/v/@toolwind/tagged-combinators)](https://www.npmjs.com/package/@toolwind/tagged-combinators)
[![twitter](https://img.shields.io/twitter/follow/branmcconnell)](https://twitter.com/branmcconnell)

This plugin adds slash-modifier tagging support to Tailwind’s built-in child (`*:`) and descendant (`**:`) variants. Keep using them as usual, and optionally filter which children/descendants match using a plain selector via `/selector` — no arbitrary variants needed.

Examples: `*/option`, `**/.active`, `*/button[aria-label]`.

```html



  • CSS

  • Good



  1. Tailwind

  2. Better




test


test

```
Open this example in Tailwind Play: https://play.tailwindcss.com/0AXQLqxOqW

## Installation

First, install the package:

```bash
npm install @toolwind/tagged-combinators
```

Then add it to your Tailwind config:

  Tailwind v4 (globals.css)

```css
@plugin "@toolwind/tagged-combinators";
```

  Tailwind v3 (tailwind.config.js)

```js
module.exports = {
plugins: [require('@toolwind/tagged-combinators')],
}
```

## Why not just use arbitrary variants?

You can do this with Tailwind’s arbitrary variants, but the syntax is noisier:

```html


```

## Usage

### Basics

```html





```

You can tag most selectors (no bracket syntax required): tags, classes, attributes, etc.

```html



```

One exception is pseudo classes, as the `:` conflicts with Tailwind's own variant syntax.

## Notes

- Without a tag, `*:` compiles to `& > *` and `**:` compiles to `& *`. This syntax is built into Tailwind natively and this plugin preserves it without any conflicts.
- Tag using the slash modifier — no brackets needed: `*/button`, `**/.active`, `*/button:hover`.

---

I hope you find `@toolwind/tagged-combinators` 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:
* [@toolwind/signals](https://github.com/@toolwind/signals): Apply styles based on parent or ancestor state, a state-driven alterative to groups
* [@toolwind/multi](https://github.com/@toolwind/multi): Group utilities together by variant
* [@toolwind/mixins](https://github.com/@toolwind/mixins): Construct reusable & aliased sets of utilities inline
* [@toolwind/selector-patterns](https://github.com/@toolwind/selector-patterns): Dynamic CSS selector patterns
* [@toolwind/js](https://github.com/@toolwind/js): Effortless build-time JS script injection
* [@toolwind/directional-shadows](https://github.com/@toolwind/directional-shadows): Supercharge your shadow utilities with added directional support (includes directional `shadow-border` utilities too ✨)
* [@toolwind/default-shades](https://github.com/@toolwind/default-shades): Default shades for simpler color utility classes
* [@toolwind/lerp-colors](https://github.com/@toolwind/lerp-colors): Expand your color horizons and take the fuss out of generating new—or expanding existing—color palettes