Skip to content

Commit 4974542

Browse files
authored
Merge pull request #1071 from tailwindcss/fix-negate-auto-bug
Ignore values not parseable by reduce-css-calc
2 parents f5fe518 + b91f0ef commit 4974542

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

__tests__/negateValue.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import negateValue from '../src/util/negateValue'
2+
3+
test('it negates numeric CSS values', () => {
4+
expect(negateValue('5')).toEqual('-5')
5+
expect(negateValue('10px')).toEqual('-10px')
6+
expect(negateValue('18rem')).toEqual('-18rem')
7+
expect(negateValue('-10')).toEqual('10')
8+
expect(negateValue('-7ch')).toEqual('7ch')
9+
})
10+
11+
test('it leaves keywords untouched', () => {
12+
expect(negateValue('auto')).toEqual('auto')
13+
expect(negateValue('cover')).toEqual('cover')
14+
})

src/util/negateValue.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import reduceCalc from 'reduce-css-calc'
2+
3+
export default function(value) {
4+
try {
5+
return reduceCalc(`calc(${value} * -1)`)
6+
} catch (e) {
7+
return value
8+
}
9+
}

src/util/resolveConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isFunction from 'lodash/isFunction'
33
import defaults from 'lodash/defaults'
44
import map from 'lodash/map'
55
import toPath from 'lodash/toPath'
6-
import reduceCalc from 'reduce-css-calc'
6+
import negateValue from './negateValue'
77

88
const configUtils = {
99
negative(scale) {
@@ -12,7 +12,7 @@ const configUtils = {
1212
.reduce(
1313
(negativeScale, key) => ({
1414
...negativeScale,
15-
[`-${key}`]: reduceCalc(`calc(${scale[key]} * -1)`),
15+
[`-${key}`]: negateValue(scale[key]),
1616
}),
1717
{}
1818
)

0 commit comments

Comments
 (0)