Created
October 25, 2017 16:34
-
-
Save greymechanic/53387977e37d52cd1cc0102a50142afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const styleLocations = { | |
v: ["-top", "-bottom"], | |
h: ["-left", "-right"], | |
l: ["-left"], | |
r: ["-right"], | |
t: ["-top"], | |
b: ["-bottom"], | |
a: [""], | |
}; | |
const styleTypes = { | |
m: "margin", | |
p: "padding", | |
}; | |
const styleSizes = { | |
n: 0, | |
xs: 3, | |
x: 6, | |
m: 12, | |
l: 21, | |
xl: 36, | |
}; | |
const buildWhiteSpace = () => { | |
let whitespace = {}; | |
Object.keys(styleSizes).forEach(size => { | |
Object.keys(styleLocations).forEach(loc => { | |
Object.keys(styleTypes).forEach(type => { | |
let whitespaceClass = type + loc + size; | |
let ruleName = styleLocations[loc].map(r => { | |
return styleTypes[type] + r; | |
}); | |
let rule = {}; | |
ruleName.forEach(name => { | |
rule[name] = styleSizes[size]; | |
}); | |
whitespace[whitespaceClass] = rule; | |
}); | |
}); | |
}); | |
return whitespace; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As Flow is a static analysis system that doesn't understand Javascript, it isn't possible to do this sort of inference without augmentation. You could use a function to enforce typed access to the generated object:
Usage:
<MyComponent className={css(ws("m", "t", "s"))} />