Skip to content

Instantly share code, notes, and snippets.

@jukben
Last active June 5, 2017 14:10
Show Gist options
  • Save jukben/838a43777f4881b563675b4e03e3117d to your computer and use it in GitHub Desktop.
Save jukben/838a43777f4881b563675b4e03e3117d to your computer and use it in GitHub Desktop.
StyledElement 🎨 – new minimalistic & powerful CSS in JS solution πŸ˜‚
/*
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