Merge pull request #1071 from tailwindcss/fix-negate-auto-bug

Ignore values not parseable by reduce-css-calc
This commit is contained in:
Adam Wathan 2019-08-09 16:11:12 -04:00 • committed by GitHub
commit 4974542686
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View file

@ -0,0 +1,14 @@
import negateValue from '../src/util/negateValue'
test('it negates numeric CSS values', () => {
expect(negateValue('5')).toEqual('-5')
expect(negateValue('10px')).toEqual('-10px')
expect(negateValue('18rem')).toEqual('-18rem')
expect(negateValue('-10')).toEqual('10')
expect(negateValue('-7ch')).toEqual('7ch')
})
test('it leaves keywords untouched', () => {
expect(negateValue('auto')).toEqual('auto')
expect(negateValue('cover')).toEqual('cover')
})

9
src/util/negateValue.js Normal file
View file

@ -0,0 +1,9 @@
import reduceCalc from 'reduce-css-calc'
export default function(value) {
try {
return reduceCalc(`calc(${value} * -1)`)
} catch (e) {
return value
}
}

View file

@ -3,7 +3,7 @@ import isFunction from 'lodash/isFunction'
import defaults from 'lodash/defaults'
import map from 'lodash/map'
import toPath from 'lodash/toPath'
import reduceCalc from 'reduce-css-calc'
import negateValue from './negateValue'
const configUtils = {
negative(scale) {
@ -12,7 +12,7 @@ const configUtils = {
.reduce(
(negativeScale, key) => ({
...negativeScale,
[`-${key}`]: reduceCalc(`calc(${scale[key]} * -1)`),
[`-${key}`]: negateValue(scale[key]),
}),
{}
)