Skip to content

Commit 2cbc915

Browse files
authored
Rename --aspect-ratio-* theme key to --aspect-* (#15365)
This PR renames the `--aspect-ratio` theme key to `--aspect`. This is to match what we've done with other theme keys where they match the utility names, like `--ease` and `--leading`. ```diff @theme { - --aspect-ratio-retro: 4 / 3; + --aspect-retro: 4 / 3; } ``` Additionally, I've also converted the existing `aspect-video` static utility to a theme value. This will allow people to override this utility in their own projects—something that's not possible with static utilities. This change feels appropriate since the video aspect ratio is subjective, unlike other static utilities like `aspect-square`. ```css @theme { --aspect-video: 4 / 3; /* N64 baby! */ } ```
1 parent ea9d700 commit 2cbc915

File tree

11 files changed

+50
-6
lines changed

11 files changed

+50
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Fix missing `shadow-none` suggestion in IntelliSense ([#15342](https://github.com/tailwindlabs/tailwindcss/pull/15342))
1919
- Optimize AST before printing for IntelliSense ([#15347](https://github.com/tailwindlabs/tailwindcss/pull/15347))
2020

21+
### Changed
22+
23+
- Rename `--aspect-ratio-*` theme key to `--aspect-*` ([#15365](https://github.com/tailwindlabs/tailwindcss/pull/15365))
24+
- Derive `aspect-video` utility from theme ([#15365](https://github.com/tailwindlabs/tailwindcss/pull/15365))
25+
2126
## [4.0.0-beta.6] - 2024-12-06
2227

2328
### Fixed
@@ -752,4 +757,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
752757
- Move the CLI into a separate `@tailwindcss/cli` package ([#13095](https://github.com/tailwindlabs/tailwindcss/pull/13095))
753758

754759
## [4.0.0-alpha.1] - 2024-03-06
755-

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
359359
--perspective-normal: 500px;
360360
--perspective-midrange: 800px;
361361
--perspective-distant: 1200px;
362+
--aspect-video: 16 / 9;
362363
--default-transition-duration: .15s;
363364
--default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
364365
--default-font-family: var(--font-sans);

packages/tailwindcss/src/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
358358
--perspective-normal: 500px;
359359
--perspective-midrange: 800px;
360360
--perspective-distant: 1200px;
361+
--aspect-video: 16 / 9;
361362
--default-transition-duration: .15s;
362363
--default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
363364
--default-font-family: var(--font-sans);

packages/tailwindcss/src/compat/apply-config-to-theme.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ test('config values can be merged into the theme', () => {
2323
sm: '1234px',
2424
},
2525

26+
aspectRatio: {
27+
retro: '4 / 3',
28+
},
29+
2630
boxShadow: {
2731
normal: '0 1px 3px black',
2832
},
@@ -75,13 +79,15 @@ test('config values can be merged into the theme', () => {
7579
},
7680
},
7781
base: '/root',
82+
reference: false,
7883
},
7984
])
8085
applyConfigToTheme(design, resolvedConfig, replacedThemeKeys)
8186

8287
expect(theme.resolve('primary', ['--color'])).toEqual('#c0ffee')
8388
expect(theme.resolve('sm', ['--breakpoint'])).toEqual('1234px')
8489
expect(theme.resolve('normal', ['--shadow'])).toEqual('0 1px 3px black')
90+
expect(theme.resolve('retro', ['--aspect'])).toEqual('4 / 3')
8591
expect(theme.resolve('sm', ['--radius'])).toEqual('0.33rem')
8692
expect(theme.resolve('blink', ['--animate'])).toEqual('blink 1s linear infinite')
8793
expect(theme.resolve('red-500', ['--color'])).toEqual('red')

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export function keyPathToCssProperty(path: string[]) {
148148
path = structuredClone(path)
149149

150150
if (path[0] === 'animation') path[0] = 'animate'
151+
if (path[0] === 'aspectRatio') path[0] = 'aspect'
151152
if (path[0] === 'borderRadius') path[0] = 'radius'
152153
if (path[0] === 'boxShadow') path[0] = 'shadow'
153154
if (path[0] === 'colors') path[0] = 'color'

packages/tailwindcss/src/compat/config.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,9 @@ test('old theme values are merged with their renamed counterparts in the CSS the
15341534
--animate-a: 1;
15351535
--animate-b: 2;
15361536
1537+
--aspect-a: 1;
1538+
--aspect-b: 2;
1539+
15371540
--container-a: 1;
15381541
--container-b: 2;
15391542
@@ -1585,6 +1588,14 @@ test('old theme values are merged with their renamed counterparts in the CSS the
15851588
expect(theme('animation.a')).toEqual('1')
15861589
expect(theme('animation.b')).toEqual('2')
15871590

1591+
expect(theme('aspectRatio')).toMatchObject({
1592+
a: '1',
1593+
b: '2',
1594+
})
1595+
1596+
expect(theme('aspectRatio.a')).toEqual('1')
1597+
expect(theme('aspectRatio.b')).toEqual('2')
1598+
15881599
expect(theme('boxShadow')).toMatchObject({
15891600
a: '1',
15901601
b: '2',

packages/tailwindcss/src/compat/config/create-compat-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function createCompatConfig(cssTheme: Theme): UserConfig {
2626
...theme('animate', {}),
2727
}),
2828

29+
aspectRatio: ({ theme }) => ({
30+
...theme('aspect', {}),
31+
}),
32+
2933
borderRadius: ({ theme }) => ({
3034
...theme('radius', {}),
3135
}),

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function loadDesignSystem() {
1111
theme.add('--colors-red-500', 'red')
1212
theme.add('--colors-blue-500', 'blue')
1313
theme.add('--breakpoint-sm', '640px')
14+
theme.add('--aspect-video', '16 / 9')
1415
theme.add('--font-sans', 'sans-serif')
1516
theme.add('--font-weight-superbold', '900')
1617
theme.add('--text-xs', '0.75rem')

packages/tailwindcss/src/utilities.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,8 +2485,22 @@ test('field-sizing', async () => {
24852485
})
24862486

24872487
test('aspect-ratio', async () => {
2488-
expect(await run(['aspect-video', 'aspect-[10/9]', 'aspect-4/3'])).toMatchInlineSnapshot(`
2489-
".aspect-4\\/3 {
2488+
expect(
2489+
await compileCss(
2490+
css`
2491+
@theme {
2492+
--aspect-video: 16 / 9;
2493+
}
2494+
@tailwind utilities;
2495+
`,
2496+
['aspect-video', 'aspect-[10/9]', 'aspect-4/3'],
2497+
),
2498+
).toMatchInlineSnapshot(`
2499+
":root {
2500+
--aspect-video: 16 / 9;
2501+
}
2502+
2503+
.aspect-4\\/3 {
24902504
aspect-ratio: 4 / 3;
24912505
}
24922506
@@ -2495,7 +2509,7 @@ test('aspect-ratio', async () => {
24952509
}
24962510
24972511
.aspect-video {
2498-
aspect-ratio: 16 / 9;
2512+
aspect-ratio: var(--aspect-video);
24992513
}"
25002514
`)
25012515
expect(

packages/tailwindcss/src/utilities.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,8 @@ export function createUtilities(theme: Theme) {
828828
*/
829829
staticUtility('aspect-auto', [['aspect-ratio', 'auto']])
830830
staticUtility('aspect-square', [['aspect-ratio', '1 / 1']])
831-
staticUtility('aspect-video', [['aspect-ratio', '16 / 9']])
832831
functionalUtility('aspect', {
833-
themeKeys: ['--aspect-ratio'],
832+
themeKeys: ['--aspect'],
834833
handleBareValue: ({ fraction }) => {
835834
if (fraction === null) return null
836835
let [lhs, rhs] = segment(fraction, '/')

0 commit comments

Comments
 (0)