Skip to content

Commit 90a2373

Browse files
authored
add zoom-* utilities (#20020)
This PR adds new `zoom-*` utilities. The `zoom-*` utilities accept bare values that are transformed into `%` based values, and arbitrary values: | Class | CSS | | -- | -- | | `zoom-50` | `zoom: 50%;` | | `zoom-[1.1]` | `zoom: 1.1;` | | `zoom-(--value)` | `zoom: var(--value);` | This also adds the `zoom` property after the `transform` related properties. Initially I added it right after `scale`, because logically they are close together. But then `zoom-*` would sit between `scale` and other tranfsorm related properties which is a bit weird. Instead, I moved it after `transform`. ## Test plan 1. Added new zoom based tests 2. All other tests still pass
1 parent 2e1ccf7 commit 90a2373

5 files changed

Lines changed: 56 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Allow using `@variant` with stacked variants (e.g. `@variant hover:focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
1515
- Allow using `@variant` with compound variants (e.g. `@variant hover, focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
1616
- Support `--default(…)` in `--value(…)` and `--modifier(…)` for functional `@utility` definitions ([#19989](https://github.com/tailwindlabs/tailwindcss/pull/19989))
17+
- Add `zoom-*` utilities ([#20020](https://github.com/tailwindlabs/tailwindcss/pull/20020))
1718
- Add `scrollbar-gutter-*` utilities ([#20018](https://github.com/tailwindlabs/tailwindcss/pull/20018))
1819

1920
### Fixed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12247,6 +12247,16 @@ exports[`getClassList 1`] = `
1224712247
"z-40",
1224812248
"z-50",
1224912249
"z-auto",
12250+
"zoom-50",
12251+
"zoom-75",
12252+
"zoom-90",
12253+
"zoom-95",
12254+
"zoom-100",
12255+
"zoom-105",
12256+
"zoom-110",
12257+
"zoom-125",
12258+
"zoom-150",
12259+
"zoom-200",
1225012260
]
1225112261
`;
1225212262

packages/tailwindcss/src/property-order.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export default [
9292
'--tw-skew-y',
9393
'transform',
9494

95+
'zoom',
96+
9597
'animation',
9698

9799
'cursor',

packages/tailwindcss/src/utilities.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6899,6 +6899,34 @@ test('transform', async () => {
68996899
).toEqual('')
69006900
})
69016901

6902+
test('zoom', async () => {
6903+
expect(
6904+
await compileCss(
6905+
css`
6906+
@tailwind utilities;
6907+
`,
6908+
['zoom-50', 'zoom-100', 'zoom-[var(--zoom)]'],
6909+
),
6910+
).toMatchInlineSnapshot(`
6911+
"
6912+
.zoom-50 {
6913+
zoom: 50%;
6914+
}
6915+
6916+
.zoom-100 {
6917+
zoom: 100%;
6918+
}
6919+
6920+
.zoom-\\[var\\(--zoom\\)\\] {
6921+
zoom: var(--zoom);
6922+
}
6923+
"
6924+
`)
6925+
expect(
6926+
await run(['zoom', '-zoom-50', 'zoom--50', 'zoom-1.5', 'zoom-unknown', 'zoom-50/foo']),
6927+
).toEqual('')
6928+
})
6929+
69026930
test('perspective', async () => {
69036931
expect(
69046932
await compileCss(

packages/tailwindcss/src/utilities.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,21 @@ export function createUtilities(theme: Theme) {
17061706
staticUtility('transform-none', [['transform', 'none']])
17071707
}
17081708

1709+
/**
1710+
* @css `zoom`
1711+
*/
1712+
functionalUtility('zoom', {
1713+
handleBareValue: ({ value }) => {
1714+
if (!isPositiveInteger(value)) return null
1715+
return `${value}%`
1716+
},
1717+
handle: (value) => [decl('zoom', value)],
1718+
})
1719+
1720+
suggest('zoom', () => [
1721+
{ values: ['50', '75', '90', '95', '100', '105', '110', '125', '150', '200'] },
1722+
])
1723+
17091724
/**
17101725
* @css `transform-style`
17111726
*/

0 commit comments

Comments
 (0)