Skip to content

Instantly share code, notes, and snippets.

@abelaska
Created August 31, 2016 07:23
Show Gist options
  • Save abelaska/6a4d8d4da37595e03303e666090f76d9 to your computer and use it in GitHub Desktop.
Save abelaska/6a4d8d4da37595e03303e666090f76d9 to your computer and use it in GitHub Desktop.
Primitive inline styling
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