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'
33import defaults from 'lodash/defaults'
44import map from 'lodash/map'
55import toPath from 'lodash/toPath'
6- import reduceCalc from 'reduce-css-calc '
6+ import negateValue from './negateValue '
77
88const 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 )
You can’t perform that action at this time.
0 commit comments