11const directions = require ( './directions' )
22const decls = require ( './declarations' )
33const { step, mqSteps } = require ( './docs-helper' )
4+ const withUnits = require ( './units' ) . withUnits
45
56const docs = ( spacing , mqs ) => `
67/*
@@ -23,45 +24,26 @@ const docs = (spacing, mqs) => `
2324 b = bottom
2425 l = left
2526
26- ${
27- Array . from ( { length : spacing . steps + 1 } )
28- . map ( ( _ , idx ) => step ( { zeroth : '/none' , nth : 'spacing scale' } , idx ) ) . join ( '\n ' )
29- }
27+ ${ [ ] . concat ( 0 , spacing ) . map ( ( _ , idx ) => step ( { zeroth : '/none' , nth : 'spacing scale' } , idx ) ) . join ( '\n ' ) }
3028
3129 Media Query Extensions:
3230 ${ mqSteps ( mqs ) }
3331
3432*/`
3533
36- const css = ( spacing , mediaQueries ) => {
37- const steps = [ ]
34+ const css = spacing =>
35+ [ ] . concat ( 0 , spacing ) . map ( ( spacing , idx ) =>
36+ Object . keys ( directions ) . map ( d =>
37+ [
38+ `.p${ directions [ d ] } ${ idx } { ${ fullDecl ( d , spacing , 'padding' ) } }` ,
39+ `.m${ directions [ d ] } ${ idx } { ${ fullDecl ( d , spacing , 'margin' ) } }` ,
40+ `.n${ directions [ d ] } ${ idx } { ${ fullDecl ( d , `-${ spacing } ` , 'margin' ) } }`
41+ ] . join ( '\n' )
42+ ) . join ( '\n' )
43+ )
3844
39- for ( let i = 0 ; i <= spacing . steps ; i ++ ) {
40- steps . push ( spacingDecls ( i , spacing . ratio ) )
41- }
4245
43- return steps . join ( '\n' )
44- }
45-
46- const spacingDecls = ( step , baseScale , opts ) => {
47- opts = opts || { }
48-
49- const postfix = opts . postfix || ''
50- const spacing = [ ]
51- const paddingClass = 'p' // TODO: Make configurable
52- const marginClass = 'm'
53- const negativeMarginClass = 'n'
54- const size = step * baseScale
55-
56- // TODO: Don't create negative margin classes for horiz/vert directions
57- return Object . keys ( directions ) . map ( d => `
58- .${ paddingClass } ${ directions [ d ] } ${ step } ${ postfix } { ${ fullDecl ( d , size , 'padding' ) } }
59- .${ marginClass } ${ directions [ d ] } ${ step } ${ postfix } { ${ fullDecl ( d , size , 'margin' ) } }
60- .${ negativeMarginClass } ${ directions [ d ] } ${ step } ${ postfix } { ${ fullDecl ( d , - size , 'margin' ) } }
61- ` ) . join ( '\n' )
62- }
63-
64- const fullDecl = ( d , size , prop ) => decls [ d ] . map ( dir => `${ prop } ${ dir } : ${ size } rem;` ) . join ( '\n' )
46+ const fullDecl = ( d , size , prop ) => decls [ d ] . map ( dir => `${ prop } ${ dir } : ${ withUnits ( size , 'rem' ) } ;` ) . join ( '\n' )
6547
6648module . exports = {
6749 css,
0 commit comments