Skip to content

Commit 9ec9de6

Browse files
committed
feat: improve snake addon
1 parent d8c0951 commit 9ec9de6

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

.storybook/snake.stories.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ const {addon: addonSnake} = require('../addon/snake');
1010
const nano = create({h});
1111
addonRule(nano);
1212
addonCache(nano);
13-
addonSnake(nano);
13+
addonSnake(nano, {
14+
inline: function () {
15+
this.display = 'inline';
16+
},
17+
18+
cornerRadius: function (value) {
19+
this.borderRadius = value;
20+
},
21+
22+
style: 'fontStyle'
23+
});
1424

1525
const {s} = nano;
1626

@@ -31,5 +41,5 @@ storiesOf('Addons/snake', module)
3141
h('div', {className: lazy}, 'Hello world')
3242
)
3343
.add('Getters', () =>
34-
h('div', {className: s.bgBlack.col('pink')}, 'Hello world')
44+
h('div', {className: s.bgBlack.col('pink').inline.pointer.cornerRadius('4px').style('italic').bold}, 'Hello world')
3545
)

addon/snake.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
var createSnake = function (renderer, rules) {
6+
exports.addon = function (renderer, rules) {
77
rules = rules || {};
88

99
var defaultRules = renderer.assign({}, atoms, {
@@ -14,9 +14,25 @@ var createSnake = function (renderer, rules) {
1414
bgBlack: function () {
1515
this.backgroundColor = '#000';
1616
},
17+
18+
pointer: function () {
19+
this.cursor = 'pointer';
20+
},
21+
22+
inlineBlock: function () {
23+
this.display = 'inline-block';
24+
},
25+
26+
bold: function () {
27+
this.fontWeight = 'bold';
28+
},
29+
30+
em: function () {
31+
this.fontStyle = 'italic';
32+
}
1733
});
1834

19-
rules = renderer.assign({}, defaultRules, rules);
35+
rules = renderer.assign(defaultRules, rules);
2036

2137
var snake = {};
2238

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

3248
return renderer.cache(instance.obj);
3349
};
50+
instance.valueOf = instance.toString;
3451

3552
return instance;
3653
};
@@ -78,11 +95,5 @@ var createSnake = function (renderer, rules) {
7895

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

81-
return snake;
82-
};
83-
84-
exports.addon = function (renderer) {
85-
var snake = createSnake(renderer);
86-
8798
renderer.s = snake;
8899
};

0 commit comments

Comments
 (0)