Created
August 31, 2016 07:23
-
-
Save abelaska/6a4d8d4da37595e03303e666090f76d9 to your computer and use it in GitHub Desktop.
Primitive inline styling
This file contains hidden or 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 compileStyles = defaultStyles => (...stylePaths) => { | |
const styles = stylePaths.map(stylePath => { | |
const path = `${stylePath}.style` | |
const style = get(defaultStyles, path); | |
if (!style) { | |
throw new Error(`Style path ${path} not found`); | |
} | |
return style; | |
}); | |
return Object.assign({}, ...styles); | |
}; | |
const s = compileStyles({ | |
header: { | |
style: { | |
fontSize: 13 | |
}, | |
menu: { | |
style: { | |
fontSize: 16 | |
}, | |
item: { | |
style: { | |
fontSize: 14 | |
} | |
} | |
} | |
} | |
}); | |
<header style={s('header')}> | |
<div style={s('header.menu')}> | |
<div style={s('header.menu.item')}>menu item</div> | |
</div> | |
</header> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment