From cf2070fe97af3c888f8c3012c8e21bee263727e9 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Tue, 13 Mar 2018 20:52:16 +0000 Subject: [PATCH] test: add jsx() stories --- .storybook/jsx.stories.js | 23 +++++++++++++++++++++++ .storybook/rule.stories.js | 2 +- lib/hash.js | 2 +- lib/index.js | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .storybook/jsx.stories.js diff --git a/.storybook/jsx.stories.js b/.storybook/jsx.stories.js new file mode 100644 index 00000000..2fff7a63 --- /dev/null +++ b/.storybook/jsx.stories.js @@ -0,0 +1,23 @@ +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 renderer = create(h); +const {jsx} = renderer; + +const RedBorder = jsx('div', { + border: '1px solid red' +}); + +storiesOf('jsx()', module) + .add('Default', () => + h(RedBorder, null, 'Hello world') + ) + .add('Custom CSS', () => + h(RedBorder, {css: {fontWeight: 'bold'}}, 'Hello world') + ) + .add('Inline styles', () => + h(RedBorder, {style: {color: 'red'}, css: {fontWeight: 'bold'}}, 'Hello world') + ) diff --git a/.storybook/rule.stories.js b/.storybook/rule.stories.js index e3319d52..4cf9335b 100644 --- a/.storybook/rule.stories.js +++ b/.storybook/rule.stories.js @@ -11,7 +11,7 @@ const className1 = rule({ border: '1px solid red' }, 'RedBorder'); -storiesOf('Light/rule()', module) +storiesOf('rule()', module) .add('Default', () => h('div', {className: className1}, 'Hello world') ) diff --git a/lib/hash.js b/lib/hash.js index 7cb8b8c9..78ca6c72 100644 --- a/lib/hash.js +++ b/lib/hash.js @@ -11,5 +11,5 @@ exports.hash = function(styles) { hash = (hash * 33) ^ str.charCodeAt(--i); } - return '_' + (hash >>> 0); + return '_' + (hash >>> 0).toString(36); }; diff --git a/lib/index.js b/lib/index.js index 5bc1bcf7..84ba36a0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -169,7 +169,7 @@ exports.create = function (h) { var dynamicClassName = fromCache(props.css); delete copy.css; - copy.className = (props.className + '') + className + dynamicClassName; + copy.className = (props.className || '') + className + dynamicClassName; return isElement ? h(fn, copy) : fn(copy); };