tailwindcss/packages/@tailwindcss-upgrade/src/codemods
Robin Malfait 4035ab0b76
Implement @variant (#15663)
This PR replaces `@variant` with `@custom-variant` for registering
custom variants via your CSS.

In addition, this PR introduces `@variant` that can be used in your CSS
to use a variant while writing custom CSS.

E.g.:

```css
.btn {
  background: white;

  @variant dark {
    background: black;
  }
}
```

Compiles to:

```css
.btn {
  background: white;
}

@media (prefers-color-scheme: dark) {
  .btn {
    background: black;
  }
}
```

For backwards compatibility, the `@variant` rules that don't have a body
and are
defined inline:

```css
@variant hocus (&:hover, &:focus);
```

And `@variant` rules that are defined with a body and a `@slot`:

```css
@variant hocus {
  &:hover, &:focus {
    @slot;
  }
}
```

Will automatically be upgraded to `@custom-variant` internally, so no
breaking changes are introduced with this PR.

---

TODO:
- [x] ~~Decide whether we want to allow multiple variants and if so,
what syntax should be used. If not, nesting `@variant <variant> {}` will
be the way to go.~~ Only a single `@variant <variant>` can be used, if
you want to use multiple, nesting should be used:

```css
.foo {
  @variant hover {
    @variant focus {
      color: red;
    }
  }
}
```
2025-01-21 10:20:35 -05:00
..
fixtures Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
format-nodes.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
format-nodes.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-at-apply.test.ts Ensure clients pin the tailwindcss version (#15011) 2024-11-15 17:18:48 +01:00
migrate-at-apply.ts Ensure clients pin the tailwindcss version (#15011) 2024-11-15 17:18:48 +01:00
migrate-at-layer-utilities.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-at-layer-utilities.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-config.ts Ensure @config is injected in common ancestor sheet (#14989) 2024-11-14 11:48:31 +01:00
migrate-import.test.ts Upgrade: don't show error during upgrade when analyzing external URL import (#15040) 2024-11-19 15:52:30 +01:00
migrate-import.ts Upgrade: don't show error during upgrade when analyzing external URL import (#15040) 2024-11-19 15:52:30 +01:00
migrate-media-screen.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-media-screen.ts Ensure clients pin the tailwindcss version (#15011) 2024-11-15 17:18:48 +01:00
migrate-missing-layers.test.ts Always add layer(…) as the first param to @import (#15102) 2024-11-22 14:09:26 +00:00
migrate-missing-layers.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00
migrate-preflight.test.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00
migrate-preflight.ts Revert new default form styles (#15100) 2024-11-22 08:55:05 -05:00
migrate-tailwind-directives.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-tailwind-directives.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-theme-to-var.test.ts Migrate theme(…) to --theme(…), migrate calc(var(--spacing)*x) to --spacing(x) (#15579) 2025-01-09 17:17:07 +01:00
migrate-theme-to-var.ts Migrate theme(…) to var(…) in CSS (#14695) 2024-10-17 11:50:27 +02:00
migrate-variants-directive.test.ts Sort upgraded CSS (#14866) 2024-11-07 12:04:52 +00:00
migrate-variants-directive.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
sort-buckets.ts Implement @variant (#15663) 2025-01-21 10:20:35 -05:00