@@ -7,12 +7,10 @@ const settings: Meta = {
77
88const  allVars  =  getCssVariables ( ) ; 
99
10- const  basefontsize  =  allVars . reduce ( ( BaseFontSize ,  [ key ,  value ] )  =>  { 
11-   if  ( key . indexOf ( '--base-font-size' )  ===  0 )  { 
12-     BaseFontSize  =  value ; 
13-   } 
14-   return  BaseFontSize ; 
15- } ,  { }  as  string ) ; 
10+ const  baseFontVar  =  allVars . find ( 
11+   ( [ key ] )  =>  key . indexOf ( '--base-font-size' )  ===  0 , 
12+ ) ; 
13+ const  baseFontSize  =  baseFontVar  ? parseInt ( baseFontVar [ 1 ] )  : 16 ; 
1614
1715interface  SpacingOptions  { 
1816  [ space : string ] : string ; 
@@ -23,8 +21,6 @@ const spacing = allVars.reduce((allSpacing, [key, value]) => {
2321    let  space  =  key . substring ( 10 ) ; 
2422    if  ( space . includes ( '-' ) )  { 
2523      space  =  space . replace ( '-' ,  '.' ) ; 
26-     }  else  { 
27-       space  =  space  +  '.0' ; 
2824    } 
2925    allSpacing [ space ]  =  value ; 
3026  } 
@@ -43,26 +39,27 @@ const Spacing: Story = args => {
4339        </ tr > 
4440      </ thead > 
4541      < tbody > 
46-         { Object . entries ( args . spacing  as  SpacingOptions ) . map ( ( [ name ,  unit ] )  =>  ( 
47-           < tr  key = { `spacing-${ name }  } > 
48-             < td > { name . replace ( '.0' ,  '' ) } </ td > 
49-             < td > 
50-               { Number ( unit . replace ( 'px' ,  '' ) )  / 
51-                 Number ( basefontsize . replace ( 'px' ,  '' ) ) } 
52-               rem
53-             </ td > 
54-             < td > { unit } </ td > 
55-             < td > 
56-               < div 
57-                 style = { { 
58-                   height : unit , 
59-                   width : unit , 
60-                   backgroundColor : '#ccc' , 
61-                 } } 
62-               > </ div > 
63-             </ td > 
64-           </ tr > 
65-         ) ) } 
42+         { Object . entries ( args . spacing  as  SpacingOptions ) 
43+           . sort ( ( [ keyA ] ,  [ keyB ] )  =>  Number ( keyA )  -  Number ( keyB ) ) 
44+           . map ( ( [ name ,  unit ] )  =>  ( 
45+             < tr  key = { `spacing-${ name }  } > 
46+               < td > { name } </ td > 
47+               < td > 
48+                 { parseInt ( unit )  /  baseFontSize } 
49+                 rem
50+               </ td > 
51+               < td > { unit } </ td > 
52+               < td > 
53+                 < div 
54+                   style = { { 
55+                     height : unit , 
56+                     width : unit , 
57+                     backgroundColor : '#ccc' , 
58+                   } } 
59+                 > </ div > 
60+               </ td > 
61+             </ tr > 
62+           ) ) } 
6663      </ tbody > 
6764    </ table > 
6865  ) ; 
0 commit comments