tailwindcss/packages/@tailwindcss-upgrade/src/codemods
Adam Wathan c50de9384a
Replace default explicit spacing scale with multiplier system (#14857)
This PR replaces the default spacing scale (`--spacing-*`) with a
generative system based on a default spacing _unit_.

Instead of the default theme containing values like `--spacing-4`,
`--spacing-6`, `--spacing-8`, etc., instead we just define a single
`--spacing` value:

```css
@theme {
  --spacing: 0.25rem;
}
```

Utilities like `px-4` are derived from this unit by multiplying it by
the value in the utility (4 in this case):

```css
.px-4 {
  padding-inline: calc(var(--spacing) * 4);
}
```

The biggest consequence of this change is that every value is available
now, rather than just the explicitly configured values.

This means utilities like `px-42` will work now, whereas prior to this
PR only `px-40` and `px-44` were valid utilities. I personally found it
very difficult to know which values actually existed at the higher end
of the scale without IntelliSense, and in practice even when working
with a skilled designer like [Steve](https://x.com/steveschoger) who
helped design Tailwind's default spacing scale, I'd very often need to
break out of it to implement a design, and trying to round to a value
that was in the scale made the design worse, not better.

This PR allows you to use any whole number, as well as decimal numbers
that are multiples of `0.25` to ensure classes like `px-1.5` continue to
work. While this means you can now technically do things like
`pt-97.25`, I think the presence of the fractional value will be enough
of a signal to developers that they are doing something a little
unusual, and they can use their judgment as to whether they are making
the right decision or not.

I'll update this PR with a lot more detail when I have a chance, as
there are a few other things to explain like:

- Unifying all of the values for
width/min-width/max-width/height/min-height/max-height utilities
- Deriving numeric line-height values from the spacing multiplier
instead of a separate line-height scale
- Using `--spacing: initial` to disable the multiplier
- How you can still use an explicit spacing scale and ignore this change
- How we plan to use IntelliSense to surface a more curated set of
spacing values even if smaller increments work when you type them
explicitly

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-11-05 15:22:50 -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 Add CSS codemod for missing @layer (#14504) 2024-09-24 16:32:50 +00:00
format-nodes.ts Migrate static plugins with options to CSS (#14700) 2024-10-18 15:16:27 +02:00
migrate-at-apply.test.ts Ensure upgrade tool has access to a JS config (#14597) 2024-10-07 18:02:28 +02:00
migrate-at-apply.ts Ensure upgrade tool has access to a JS config (#14597) 2024-10-07 18:02:28 +02:00
migrate-at-layer-utilities.test.ts Migrate static plugins with options to CSS (#14700) 2024-10-18 15:16:27 +02:00
migrate-at-layer-utilities.ts Migrate utilities in CSS files imported into layers (#14617) 2024-10-10 15:44:04 +02:00
migrate-border-compatibility.test.ts Only generate Preflight compatibility styles when Preflight is used (#14773) 2024-10-24 13:19:56 -04:00
migrate-border-compatibility.ts Only generate Preflight compatibility styles when Preflight is used (#14773) 2024-10-24 13:19:56 -04:00
migrate-config.ts Support migrating projects with multiple config files (#14863) 2024-11-04 16:52:11 +00:00
migrate-import.test.ts Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
migrate-import.ts Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
migrate-media-screen.test.ts Add codemod for migrating the @screen directive (#14749) 2024-10-22 16:09:56 +00:00
migrate-media-screen.ts Add codemod for migrating the @screen directive (#14749) 2024-10-22 16:09:56 +00:00
migrate-missing-layers.test.ts Ensure layer(…) on @import is only removed when @utility is present (#14783) 2024-10-24 14:33:10 -04:00
migrate-missing-layers.ts Inject @config "..." when a tailwind.config.{js,ts,...} is detected (#14635) 2024-10-10 14:02:42 +00:00
migrate-tailwind-directives.test.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +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 Replace default explicit spacing scale with multiplier system (#14857) 2024-11-05 15:22:50 -05: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 Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-variants-directive.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00