Skip to content

Commit

Permalink
feat: improve snake addon
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 22, 2018
1 parent d8c0951 commit 9ec9de6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
14 changes: 12 additions & 2 deletions .storybook/snake.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ const {addon: addonSnake} = require('../addon/snake');
const nano = create({h});
addonRule(nano);
addonCache(nano);
addonSnake(nano);
addonSnake(nano, {
inline: function () {
this.display = 'inline';
},

cornerRadius: function (value) {
this.borderRadius = value;
},

style: 'fontStyle'
});

const {s} = nano;

Expand All @@ -31,5 +41,5 @@ storiesOf('Addons/snake', module)
h('div', {className: lazy}, 'Hello world')
)
.add('Getters', () =>
h('div', {className: s.bgBlack.col('pink')}, 'Hello world')
h('div', {className: s.bgBlack.col('pink').inline.pointer.cornerRadius('4px').style('italic').bold}, 'Hello world')
)
27 changes: 19 additions & 8 deletions addon/snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var atoms = require('./atoms').atoms;

var createSnake = function (renderer, rules) {
exports.addon = function (renderer, rules) {
rules = rules || {};

var defaultRules = renderer.assign({}, atoms, {
Expand All @@ -14,9 +14,25 @@ var createSnake = function (renderer, rules) {
bgBlack: function () {
this.backgroundColor = '#000';
},

pointer: function () {
this.cursor = 'pointer';
},

inlineBlock: function () {
this.display = 'inline-block';
},

bold: function () {
this.fontWeight = 'bold';
},

em: function () {
this.fontStyle = 'italic';
}
});

rules = renderer.assign({}, defaultRules, rules);
rules = renderer.assign(defaultRules, rules);

var snake = {};

Expand All @@ -31,6 +47,7 @@ var createSnake = function (renderer, rules) {

return renderer.cache(instance.obj);
};
instance.valueOf = instance.toString;

return instance;
};
Expand Down Expand Up @@ -78,11 +95,5 @@ var createSnake = function (renderer, rules) {

for (var name in rules) onRule(name);

return snake;
};

exports.addon = function (renderer) {
var snake = createSnake(renderer);

renderer.s = snake;
};

0 comments on commit 9ec9de6

Please sign in to comment.