Last active
June 5, 2017 14:10
-
-
Save jukben/838a43777f4881b563675b4e03e3117d to your computer and use it in GitHub Desktop.
StyledElement π¨ β new minimalistic & powerful CSS in JS solution π
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
/* | |
styledElement - new minimalistic & powerful CSS in JS solution | |
Example of usage: | |
const div = styledElement("div", {background: red}) | |
*/ | |
export function styledElement(elem = "div", rules = {}, options = {}) { | |
const element = document.createElement(elem) | |
Object.keys(rules).forEach(r => { | |
const value = rules[r] | |
element.style[r] = typeof value === 'number' ? value+'px' : value | |
}) | |
Object.keys(options).forEach(o => element[o] = options[o]) | |
return element | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment