Skip to content

Commit

Permalink
Use inline and block for x/y utilities (#14805)
Browse files Browse the repository at this point in the history
This PR updates all of our x/y named utilities (like `px-*`, `my-*`,
`inset-y-*`, `scroll-px-*`, etc.) to use logical properties like
`padding-inline` instead of separate `padding-left` and `padding-right`
properties.

We held off on this originally for a while because `inline` doesn't
really mean _horizontal_ like the "x" in `px-*` implies, but I think in
practice this change is fine — I'm comfortable with "x" meaning "in the
inline direction" and "y" meaning "in the block direction" in Tailwind.

This is technically a breaking change if anyone was depending on the
fact that `px-*` for instance was always explicitly setting
`padding-left` and `padding-right` even when building something in a
vertical writing mode, but I kinda doubt there's a single real project
on the internet that will actually be affected, so not too worried about
it.

If someone _really_ wants to set `padding-left` and `padding-right` they
can always use `pl-4 pr-4` instead of `px-4`.

Nice thing about this change is it produces quite a bit less CSS.

To test this change, I re-generated all of the snapshots and made sure
none of the generated utilities changed position or anything in the
output (initially they did before I updated `property-order.ts` to add
some missing properties).

I also created a little demo locally in the Vite playground to test
things manually and make sure I didn't make any obvious typos or
anything that could slip through the snapshots:

<img width="1223" alt="image"
src="https://github.com/user-attachments/assets/0e9854ba-2b5b-4c8c-87b6-6eb7b7da84f2">

<details>
<summary>Show code for playground demo</summary>

```jsx
import React from 'react'

export function App() {
  return (
    <div className="p-12 gap-10 grid grid-cols-2 items-start">
      <div className="grid grid-cols-1 gap-10 justify-start">
        <div className="space-y-6">
          <p className="font-semibold mb-6">Border Width</p>
          <div className="border-x w-48 h-12 flex items-center justify-center">border-x</div>
          <div className="border-y w-48 h-12 flex items-center justify-center">border-y</div>
        </div>
        <div className="space-y-6">
          <p className="font-semibold mb-6">Border Color</p>
          <div className="border-2 border-x-red-500 w-48 h-12 flex items-center justify-center">
            border-x-red-500
          </div>
          <div className="border-2 border-y-red-500 w-48 h-12 flex items-center justify-center">
            border-y-red-500
          </div>
        </div>
        <div className="space-y-6">
          <p className="font-semibold mb-6">Padding</p>
          <div>
            <div className="px-8 bg-yellow-300 inline-flex items-center justify-center">px-8</div>
          </div>
          <div>
            <div className="py-8 bg-yellow-300 inline-flex items-center justify-center">py-8</div>
          </div>
        </div>
      </div>
      <div className="grid grid-cols-1 gap-10 justify-start">
        <div className="space-y-6">
          <p className="font-semibold mb-6">Margin</p>
          <div>
            <div className="bg-red-400 inline-flex">
              <div className="mx-8 bg-yellow-300 inline-flex items-center justify-center">mx-8</div>
            </div>
          </div>
          <div>
            <div className="bg-red-400 inline-flex">
              <div className="my-8 bg-yellow-300 inline-flex items-center justify-center">my-8</div>
            </div>
          </div>
        </div>
        <div className="space-y-6">
          <p className="font-semibold mb-6">Inset</p>
          <div className="relative bg-red-400 w-48 h-48">
            <div className="inset-x-8 absolute bg-yellow-300 inline-flex items-center justify-center">
              inset-x-8
            </div>
          </div>
          <div className="relative bg-red-400 w-48 h-48">
            <div className="inset-y-8 absolute bg-yellow-300 inline-flex items-center justify-center">
              inset-y-8
            </div>
          </div>
        </div>
      </div>
    </div>
  )
}
```

</details>

I didn't manually test the scroll padding or scroll margin utilities
because they are more annoying to set up, but I probably should.

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
  • Loading branch information
adamwathan and adamwathan authored Oct 28, 2024
1 parent e14ab1f commit 289c25f
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 312 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support calling `config()` with no arguments in plugin API ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799))

### Changed

- Use logical `*-inline` and `*-block` properties for all x/y utilities like `px-*`, `my-*`, `scroll-px-*`, and `inset-y-*` ([#14805](https://github.com/tailwindlabs/tailwindcss/pull/14805))

## [4.0.0-alpha.30] - 2024-10-24

### Added
Expand Down
192 changes: 64 additions & 128 deletions packages/tailwindcss/src/__snapshots__/utilities.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -856,133 +856,101 @@ exports[`border-x-* 1`] = `
}
.border-x {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 1px;
border-right-width: 1px;
border-inline-style: var(--tw-border-style);
border-inline-width: 1px;
}
.border-x-0 {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 0;
border-right-width: 0;
border-inline-style: var(--tw-border-style);
border-inline-width: 0;
}
.border-x-2 {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 2px;
border-right-width: 2px;
border-inline-style: var(--tw-border-style);
border-inline-width: 2px;
}
.border-x-4 {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 4px;
border-right-width: 4px;
border-inline-style: var(--tw-border-style);
border-inline-width: 4px;
}
.border-x-123 {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 123px;
border-right-width: 123px;
border-inline-style: var(--tw-border-style);
border-inline-width: 123px;
}
.border-x-\\[12px\\] {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: 12px;
border-right-width: 12px;
border-inline-style: var(--tw-border-style);
border-inline-width: 12px;
}
.border-x-\\[length\\:var\\(--my-width\\)\\], .border-x-\\[line-width\\:var\\(--my-width\\)\\] {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: var(--my-width);
border-right-width: var(--my-width);
border-inline-style: var(--tw-border-style);
border-inline-width: var(--my-width);
}
.border-x-\\[medium\\] {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: medium;
border-right-width: medium;
border-inline-style: var(--tw-border-style);
border-inline-width: medium;
}
.border-x-\\[thick\\] {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: thick;
border-right-width: thick;
border-inline-style: var(--tw-border-style);
border-inline-width: thick;
}
.border-x-\\[thin\\] {
border-left-style: var(--tw-border-style);
border-right-style: var(--tw-border-style);
border-left-width: thin;
border-right-width: thin;
border-inline-style: var(--tw-border-style);
border-inline-width: thin;
}
.border-x-\\[\\#0088cc\\] {
border-left-color: #08c;
border-right-color: #08c;
border-inline-color: #08c;
}
.border-x-\\[\\#0088cc\\]\\/50 {
border-left-color: oklch(59.9824% .14119 241.555 / .5);
border-right-color: oklch(59.9824% .14119 241.555 / .5);
border-inline-color: oklch(59.9824% .14119 241.555 / .5);
}
.border-x-\\[color\\:var\\(--my-color\\)\\] {
border-left-color: var(--my-color);
border-right-color: var(--my-color);
border-inline-color: var(--my-color);
}
.border-x-\\[color\\:var\\(--my-color\\)\\]\\/50 {
border-left-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-right-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-inline-color: color-mix(in oklch, var(--my-color) 50%, transparent);
}
.border-x-\\[var\\(--my-color\\)\\] {
border-left-color: var(--my-color);
border-right-color: var(--my-color);
border-inline-color: var(--my-color);
}
.border-x-\\[var\\(--my-color\\)\\]\\/50 {
border-left-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-right-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-inline-color: color-mix(in oklch, var(--my-color) 50%, transparent);
}
.border-x-current {
border-left-color: currentColor;
border-right-color: currentColor;
border-inline-color: currentColor;
}
.border-x-current\\/50 {
border-left-color: color-mix(in oklch, currentColor 50%, transparent);
border-right-color: color-mix(in oklch, currentColor 50%, transparent);
border-inline-color: color-mix(in oklch, currentColor 50%, transparent);
}
.border-x-inherit {
border-left-color: inherit;
border-right-color: inherit;
border-inline-color: inherit;
}
.border-x-red-500 {
border-left-color: var(--color-red-500, #ef4444);
border-right-color: var(--color-red-500, #ef4444);
border-inline-color: var(--color-red-500, #ef4444);
}
.border-x-red-500\\/50 {
border-left-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
border-right-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
border-inline-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
}
.border-x-transparent {
border-left-color: #0000;
border-right-color: #0000;
border-inline-color: #0000;
}
@supports (-moz-orient: inline) {
Expand All @@ -1009,133 +977,101 @@ exports[`border-y-* 1`] = `
}
.border-y {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 1px;
border-bottom-width: 1px;
border-block-style: var(--tw-border-style);
border-block-width: 1px;
}
.border-y-0 {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 0;
border-bottom-width: 0;
border-block-style: var(--tw-border-style);
border-block-width: 0;
}
.border-y-2 {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 2px;
border-bottom-width: 2px;
border-block-style: var(--tw-border-style);
border-block-width: 2px;
}
.border-y-4 {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 4px;
border-bottom-width: 4px;
border-block-style: var(--tw-border-style);
border-block-width: 4px;
}
.border-y-123 {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 123px;
border-bottom-width: 123px;
border-block-style: var(--tw-border-style);
border-block-width: 123px;
}
.border-y-\\[12px\\] {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: 12px;
border-bottom-width: 12px;
border-block-style: var(--tw-border-style);
border-block-width: 12px;
}
.border-y-\\[length\\:var\\(--my-width\\)\\], .border-y-\\[line-width\\:var\\(--my-width\\)\\] {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: var(--my-width);
border-bottom-width: var(--my-width);
border-block-style: var(--tw-border-style);
border-block-width: var(--my-width);
}
.border-y-\\[medium\\] {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: medium;
border-bottom-width: medium;
border-block-style: var(--tw-border-style);
border-block-width: medium;
}
.border-y-\\[thick\\] {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: thick;
border-bottom-width: thick;
border-block-style: var(--tw-border-style);
border-block-width: thick;
}
.border-y-\\[thin\\] {
border-top-style: var(--tw-border-style);
border-bottom-style: var(--tw-border-style);
border-top-width: thin;
border-bottom-width: thin;
border-block-style: var(--tw-border-style);
border-block-width: thin;
}
.border-y-\\[\\#0088cc\\] {
border-top-color: #08c;
border-bottom-color: #08c;
border-block-color: #08c;
}
.border-y-\\[\\#0088cc\\]\\/50 {
border-top-color: oklch(59.9824% .14119 241.555 / .5);
border-bottom-color: oklch(59.9824% .14119 241.555 / .5);
border-block-color: oklch(59.9824% .14119 241.555 / .5);
}
.border-y-\\[color\\:var\\(--my-color\\)\\] {
border-top-color: var(--my-color);
border-bottom-color: var(--my-color);
border-block-color: var(--my-color);
}
.border-y-\\[color\\:var\\(--my-color\\)\\]\\/50 {
border-top-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-bottom-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-block-color: color-mix(in oklch, var(--my-color) 50%, transparent);
}
.border-y-\\[var\\(--my-color\\)\\] {
border-top-color: var(--my-color);
border-bottom-color: var(--my-color);
border-block-color: var(--my-color);
}
.border-y-\\[var\\(--my-color\\)\\]\\/50 {
border-top-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-bottom-color: color-mix(in oklch, var(--my-color) 50%, transparent);
border-block-color: color-mix(in oklch, var(--my-color) 50%, transparent);
}
.border-y-current {
border-top-color: currentColor;
border-bottom-color: currentColor;
border-block-color: currentColor;
}
.border-y-current\\/50 {
border-top-color: color-mix(in oklch, currentColor 50%, transparent);
border-bottom-color: color-mix(in oklch, currentColor 50%, transparent);
border-block-color: color-mix(in oklch, currentColor 50%, transparent);
}
.border-y-inherit {
border-top-color: inherit;
border-bottom-color: inherit;
border-block-color: inherit;
}
.border-y-red-500 {
border-top-color: var(--color-red-500, #ef4444);
border-bottom-color: var(--color-red-500, #ef4444);
border-block-color: var(--color-red-500, #ef4444);
}
.border-y-red-500\\/50 {
border-top-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
border-bottom-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
border-block-color: color-mix(in oklch, var(--color-red-500, #ef4444) 50%, transparent);
}
.border-y-transparent {
border-top-color: #0000;
border-bottom-color: #0000;
border-block-color: #0000;
}
@supports (-moz-orient: inline) {
Expand Down
Loading

0 comments on commit 289c25f

Please sign in to comment.