Skip to content

Commit

Permalink
feat: add withStyles() interface
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 14, 2018
1 parent ed537e1 commit 4d04280
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Super lite CSS-in-JS solution.

- Does not create wrapper components.


## Usage

Expand Down
28 changes: 28 additions & 0 deletions addon/withStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

exports.addon = function (renderer) {
renderer.withStyles = function (map, fn, block) {
block = block || fn.displayName || fn.name;

var styles = this.sheet(map, block);
var Component = function (props) {
if (process.env.NODE_ENV !== 'production') {
return fn(Object.assign({}, props, {
styles: styles
}));
}

props.styles = styles;

return fn(props);
};

if (process.env.NODE_ENV !== 'production') {
if (block) {
Component.displayName = block;
}
}

return Component;
};
};

0 comments on commit 4d04280

Please sign in to comment.