Skip to content

Commit

Permalink
feat: add dsheet() interface
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 14, 2018
1 parent 50fa646 commit 1d509ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .storybook/drule.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ storiesOf('drule()', module)
h('div', {className: '' + className1}, 'Hello world')
)
.add('Dynamic styles', () =>
h('div', {className: className1({fontWeight: 'bold'})}, 'Hello world')
h('div', null,
h('div', {className: className1({fontWeight: 'bold'})}, 'Hello world'),
h('div', {className: className1({color: 'blue'})}, 'Hello world')
)
)
36 changes: 36 additions & 0 deletions addon/dsheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

exports.addon = function (renderer) {
if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('dsheet', renderer, ['sheet', 'cache']);
}

renderer.dsheet = function (map, block) {
var styles = renderer.sheet(map, block);
var closures = {};

var createClosure = function (modifier) {
var closure = function (dynamicStyles) {
if (!dynamicStyles) {
return styles[modifier];
}

var dynamicClassName = renderer.cache(dynamicStyles);

return styles[modifier] + dynamicClassName;
};

closure.toString = function () {
return styles[modifier];
};

return closure;
};

for (var modifier in map) {
closures[modifier] = createClosure(modifier);
}

return closures;
};
};

0 comments on commit 1d509ed

Please sign in to comment.