Skip to content

Commit d9d7df1

Browse files
committed
scale arbitrary values
Support arbitrary value for scale (e.g. `scale-[1_2_3.5]`).
1 parent 72bc00d commit d9d7df1

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

packages/tailwindcss/src/utilities.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ test('skew-y', () => {
29752975
})
29762976

29772977
test('scale', () => {
2978-
expect(run(['scale-50', '-scale-50', 'scale-[123deg]'])).toMatchInlineSnapshot(`
2978+
expect(run(['scale-50', '-scale-50', 'scale-[2]', 'scale-[2_1.5_3]'])).toMatchInlineSnapshot(`
29792979
".-scale-50 {
29802980
--tw-scale-x: calc(50% * -1);
29812981
--tw-scale-y: calc(50% * -1);
@@ -2990,11 +2990,12 @@ test('scale', () => {
29902990
scale: var(--tw-scale-x) var(--tw-scale-y);
29912991
}
29922992
2993-
.scale-\\[123deg\\] {
2994-
--tw-scale-x: 123deg;
2995-
--tw-scale-y: 123deg;
2996-
--tw-scale-z: 123deg;
2997-
scale: var(--tw-scale-x) var(--tw-scale-y);
2993+
.scale-\\[2\\] {
2994+
scale: 2;
2995+
}
2996+
2997+
.scale-\\[2_1\\.5_3\\] {
2998+
scale: 2 1.5 3;
29982999
}
29993000
30003001
@property --tw-scale-x {
@@ -3052,7 +3053,7 @@ test('scale-3d', () => {
30523053
})
30533054

30543055
test('scale-x', () => {
3055-
expect(run(['scale-x-50', '-scale-x-50', 'scale-x-[123deg]'])).toMatchInlineSnapshot(`
3056+
expect(run(['scale-x-50', '-scale-x-50', 'scale-x-[2]'])).toMatchInlineSnapshot(`
30563057
".-scale-x-50 {
30573058
--tw-scale-x: calc(50% * -1);
30583059
scale: var(--tw-scale-x) var(--tw-scale-y);
@@ -3063,8 +3064,8 @@ test('scale-x', () => {
30633064
scale: var(--tw-scale-x) var(--tw-scale-y);
30643065
}
30653066
3066-
.scale-x-\\[123deg\\] {
3067-
--tw-scale-x: 123deg;
3067+
.scale-x-\\[2\\] {
3068+
--tw-scale-x: 2;
30683069
scale: var(--tw-scale-x) var(--tw-scale-y);
30693070
}
30703071
@@ -3121,7 +3122,7 @@ test('scale-x', () => {
31213122
})
31223123

31233124
test('scale-y', () => {
3124-
expect(run(['scale-y-50', '-scale-y-50', 'scale-y-[123deg]'])).toMatchInlineSnapshot(`
3125+
expect(run(['scale-y-50', '-scale-y-50', 'scale-y-[2]'])).toMatchInlineSnapshot(`
31253126
".-scale-y-50 {
31263127
--tw-scale-y: calc(50% * -1);
31273128
scale: var(--tw-scale-x) var(--tw-scale-y);
@@ -3132,8 +3133,8 @@ test('scale-y', () => {
31323133
scale: var(--tw-scale-x) var(--tw-scale-y);
31333134
}
31343135
3135-
.scale-y-\\[123deg\\] {
3136-
--tw-scale-y: 123deg;
3136+
.scale-y-\\[2\\] {
3137+
--tw-scale-y: 2;
31373138
scale: var(--tw-scale-x) var(--tw-scale-y);
31383139
}
31393140

packages/tailwindcss/src/utilities.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,20 +1430,27 @@ export function createUtilities(theme: Theme) {
14301430
/**
14311431
* @css `scale`
14321432
*/
1433-
functionalUtility('scale', {
1434-
supportsNegative: true,
1435-
themeKeys: ['--scale'],
1436-
handleBareValue: ({ value }) => {
1437-
if (Number.isNaN(Number(value))) return null
1438-
return `${value}%`
1439-
},
1440-
handle: (value) => [
1433+
utilities.functional('scale', (candidate) => {
1434+
if (!candidate.value) return
1435+
let value
1436+
if (candidate.value.kind === 'arbitrary') {
1437+
value = candidate.value.value
1438+
return [decl('scale', value)]
1439+
} else {
1440+
value = theme.resolve(candidate.value.value, ['--scale'])
1441+
if (!value && !Number.isNaN(Number(candidate.value.value))) {
1442+
value = `${candidate.value.value}%`
1443+
}
1444+
if (!value) return
1445+
}
1446+
value = withNegative(value, candidate)
1447+
return [
14411448
scaleProperties(),
14421449
decl('--tw-scale-x', value),
14431450
decl('--tw-scale-y', value),
14441451
decl('--tw-scale-z', value),
14451452
decl('scale', `var(--tw-scale-x) var(--tw-scale-y)`),
1446-
],
1453+
]
14471454
})
14481455

14491456
suggest('scale', () => [

0 commit comments

Comments
 (0)