Skip to content

Commit

Permalink
feat: add Atrule support
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 13, 2018
1 parent d545dee commit 20882c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .storybook/jsx.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const Button = jsx('button', {
position: 'relative',
top: '2px',
},
// '@media (max-width: 480px)': {
// width: '160px',
// }
'@media (max-width: 480px)': {
width: '160px',
}
});

storiesOf('jsx()', module)
Expand Down
11 changes: 8 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.create = function (h) {
if (isClient) {
var sheet = document.head.appendChild(document.createElement('style')).sheet;
putRaw = function (rawCss) {
console.log('rawCss', rawCss);
sheet.insertRule(rawCss, 0);
};
} else {
Expand All @@ -37,23 +38,27 @@ exports.create = function (h) {
};
}

var put = function (selector, decls) {
var put = function (selector, decls, atrule) {
var str = '';
var prop, value;

for (prop in decls) {
value = decls[prop];

if (value instanceof Object) {
put(renderer.selector(selector, prop), value);
if (prop[0] === '@') {
put(selector, value, prop);
} else {
put(renderer.selector(selector, prop), value, atrule);
}
} else {
str += renderer.decl(prop, value);
}
}

if (str) {
str = '.' + selector + '{' + str + '}';
putRaw(str);
putRaw(atrule ? atrule + '{' + str + '}' : str);
}
};

Expand Down

0 comments on commit 20882c4

Please sign in to comment.