Skip to content

Commit

Permalink
add support to inline styles
Browse files Browse the repository at this point in the history
  • Loading branch information
lopez-alex committed Mar 11, 2018
1 parent a67fdb6 commit 4313074
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/jsx-render/index.js
Expand Up @@ -5,6 +5,12 @@ function isSVG(element) {
return SVGTags.some(tag => patt.test(tag))
}

function styleString(styles) {
return Object.keys(styles)
.map(prop => `${prop}: ${styles[prop]}`)
.join(';')
}

function dom(tag, attrs, ...children) {
// Custom Components will be functions
if (typeof tag === 'function') {
Expand Down Expand Up @@ -40,7 +46,9 @@ function dom(tag, attrs, ...children) {
element.appendChild(fragments)

for (const prop in attrs) {
if (attrs.hasOwnProperty(prop)) {
if (prop === 'style') {
element.style = styleString(attrs[prop])
} else if (attrs.hasOwnProperty(prop)) {
element.setAttribute(prop, attrs[prop])
}
}
Expand Down

0 comments on commit 4313074

Please sign in to comment.