Skip to content

Commit

Permalink
feat: add useStyles interface
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 14, 2018
1 parent 26d8d9a commit 2e78159
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .storybook/withStyles.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ const Example1 = withStyles(styles, function Example1 (props) {
)
});

const styles2 = {
main: {
border: '1px solid red',
}
};

function HelloWorld ({styles}) {
return h('div', {className: styles.main}, 'Hello world!');
}

const Bordered = withStyles(styles2, HelloWorld);

storiesOf('Addons/withStyles()', module)
.add('Default', () =>
h(Example1)
)
.add('Hello world', () =>
h(Bordered)
)
20 changes: 20 additions & 0 deletions addon/useStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

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

var styles = renderer.sheet(map, block);
var Component = function (props) {
return fn(props, styles);
};

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

return Component;
};
};
2 changes: 1 addition & 1 deletion addon/withStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports.addon = function (renderer) {

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

Expand Down

0 comments on commit 2e78159

Please sign in to comment.