File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change
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
+ } )
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import isFunction from 'lodash/isFunction'
3
3
import defaults from 'lodash/defaults'
4
4
import map from 'lodash/map'
5
5
import toPath from 'lodash/toPath'
6
- import reduceCalc from 'reduce-css-calc '
6
+ import negateValue from './negateValue '
7
7
8
8
const configUtils = {
9
9
negative ( scale ) {
@@ -12,7 +12,7 @@ const configUtils = {
12
12
. reduce (
13
13
( negativeScale , key ) => ( {
14
14
...negativeScale ,
15
- [ `-${ key } ` ] : reduceCalc ( `calc( ${ scale [ key ] } * -1)` ) ,
15
+ [ `-${ key } ` ] : negateValue ( scale [ key ] ) ,
16
16
} ) ,
17
17
{ }
18
18
)
You can’t perform that action at this time.
0 commit comments