Skip to content

Commit

Permalink
feat: fix sheet() and add stories
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 13, 2018
1 parent f2d4bd2 commit f135cc2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [ ["env", {"modules": false} ]]
"presets": [ ["env", {"modules": false} ]]
}
43 changes: 43 additions & 0 deletions .storybook/sheet.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {createElement as h} from 'react';
import {storiesOf} from '@storybook/react';
const {action} = require('@storybook/addon-actions');
const {linkTo} = require('@storybook/addon-links');
const {create} = require('../lib');
const {addonSheet} = require('../addon/sheet');

const renderer = create(h);
addonSheet(renderer);
const {sheet} = renderer;

const styles = sheet({
tomato: {
bd: '1px solid tomato',
},
yellow: {
bd: '1px solid yellow',
},
}, 'hello');


const styles2 = renderer.sheet({
tomato: {
bd: '1px solid tomato',
},
yellow: {
bd: '1px solid yellow',
},
});

storiesOf('sheet()', module)
.add('Default', () =>
h('div', null,
h('div', {className: styles.tomato}, 'Red'),
h('div', {className: styles.yellow}, 'Yellow'),
)
)
.add('No block name', () =>
h('div', null,
h('div', {className: styles2.tomato}, 'Red'),
h('div', {className: styles2.yellow}, 'Yellow'),
)
)
10 changes: 7 additions & 3 deletions addon/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ exports.addonSheet = function (renderer) {
block = hash(map);
}

for (var elementModifier in map) {
function onElementModifiler (elementModifier) {
var styles = map[elementModifier];

Object.defineProperty(result, elementModifier, {
configurable: true,
get: function () {
var classNames = this.rule(styles, block + '-' + elementModifier);
var classNames = renderer.rule(styles, block + '-' + elementModifier);

Object.defineProperty(result, elementModifier, {
value: classNames,
value: classNames
});

return classNames;
},
});
}

for (var elementModifier in map) {
onElementModifiler(elementModifier);
}

return result;
};
};

0 comments on commit f135cc2

Please sign in to comment.