@@ -91,6 +91,17 @@ function getStylePropValue(prop: string, value: t.ObjectProperty['value'], eleme
91
91
case 'end' :
92
92
case 'flexBasis' : {
93
93
if ( value . type === 'StringLiteral' || value . type === 'NumericLiteral' ) {
94
+ if ( prop === 'margin' && value . type === 'StringLiteral' && / \s / . test ( value . value ) ) {
95
+ // Check if it has multiple whitespace-separated values
96
+ let expansions = expandSpaceShorthand ( prop , value . value , convertDimension ) ;
97
+ if ( ! expansions ) {
98
+ return null ;
99
+ }
100
+ return {
101
+ macroValues : expansions
102
+ } ;
103
+ }
104
+
94
105
let val = convertDimension ( value . value , 'space' ) ;
95
106
if ( val != null ) {
96
107
return {
@@ -316,6 +327,17 @@ function getStylePropValue(prop: string, value: t.ObjectProperty['value'], eleme
316
327
case 'paddingBottom' :
317
328
if ( element === 'View' ) {
318
329
if ( value . type === 'StringLiteral' || value . type === 'NumericLiteral' ) {
330
+ if ( prop === 'padding' && value . type === 'StringLiteral' && / \s / . test ( value . value ) ) {
331
+ // Check if it has multiple whitespace-separated values
332
+ let expansions = expandSpaceShorthand ( prop , value . value , convertDimension ) ;
333
+ if ( ! expansions ) {
334
+ return null ;
335
+ }
336
+ return {
337
+ macroValues : expansions
338
+ } ;
339
+ }
340
+
319
341
let val = convertDimension ( value . value , 'space' ) ;
320
342
if ( val != null ) {
321
343
return {
@@ -519,6 +541,56 @@ function handleProp(
519
541
}
520
542
}
521
543
544
+ function expandSpaceShorthand (
545
+ prop : string ,
546
+ rawValue : string ,
547
+ convertFn : ( val : string | number , type : 'space' | 'size' | 'px' ) => any
548
+ ) {
549
+ // Split on whitespace (e.g. "10px 16px" -> ["10px", "16px"])
550
+ let parts = rawValue . trim ( ) . split ( / \s + / ) ;
551
+
552
+ // One value => all sides
553
+ // Two values => vertical horizontal
554
+ // Three values => top, horizontal, bottom
555
+ // Four values => top, right, bottom, left
556
+ // Return keys and values in an array we can map to macroValues.
557
+ switch ( parts . length ) {
558
+ case 1 : {
559
+ let val = convertFn ( parts [ 0 ] , 'space' ) ;
560
+ return [ { key : prop , value : val } ] ;
561
+ }
562
+ case 2 : {
563
+ let [ y , x ] = parts ;
564
+ return [
565
+ { key : `${ prop } Y` , value : convertFn ( y , 'space' ) } ,
566
+ { key : `${ prop } X` , value : convertFn ( x , 'space' ) }
567
+ ] ;
568
+ }
569
+ case 3 : {
570
+ // top horizontal bottom
571
+ let [ top , x , bottom ] = parts ;
572
+ return [
573
+ { key : `${ prop } Top` , value : convertFn ( top , 'space' ) } ,
574
+ { key : `${ prop } X` , value : convertFn ( x , 'space' ) } ,
575
+ { key : `${ prop } Bottom` , value : convertFn ( bottom , 'space' ) }
576
+ ] ;
577
+ }
578
+ case 4 : {
579
+ // top right bottom left
580
+ let [ top , right , bottom , left ] = parts ;
581
+ return [
582
+ { key : `${ prop } Top` , value : convertFn ( top , 'space' ) } ,
583
+ { key : `${ prop } Right` , value : convertFn ( right , 'space' ) } ,
584
+ { key : `${ prop } Bottom` , value : convertFn ( bottom , 'space' ) } ,
585
+ { key : `${ prop } Left` , value : convertFn ( left , 'space' ) }
586
+ ] ;
587
+ }
588
+ default : {
589
+ return null ;
590
+ }
591
+ }
592
+ }
593
+
522
594
export function transformStyleProps ( path : NodePath < t . JSXElement > , element : string ) {
523
595
let macroValues = new Map < string , object | string | number | boolean > ;
524
596
let dynamicValues = new Map < string , t . ObjectProperty [ 'value' ] > ;
0 commit comments