Skip to content

Commit

Permalink
test: add class decorator story
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 14, 2018
1 parent 51b09b3 commit 9f2a4f1
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../.storybook', true, /.stories.jsx?$/);
const req = require.context('../.storybook', true, /.stories.(j|t)sx?$/);
function loadStories() {
req.keys().forEach((filename) => req(filename));
}
Expand Down
24 changes: 24 additions & 0 deletions .storybook/decorator.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {createElement as h, Component} from 'react';
import {storiesOf} from '@storybook/react';
const {action} = require('@storybook/addon-actions');
const {linkTo} = require('@storybook/addon-links');

import {create} from '../lib';
import {addon} from '../addon/decorator';
const renderer = create();
addon(renderer);
const {css} = renderer;

@css({
border: '1px solid red'
})
class CssTest extends Component<any, any> {
render () {
return <div>Hello there</div>;
}
}

storiesOf('Addons/@css decorator', module)
.add('Default', () =>
<CssTest />
)
11 changes: 10 additions & 1 deletion .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader'
}
]
},

resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
enforceExtension: false
}
};
4 changes: 1 addition & 3 deletions addon/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ exports.addon = function (renderer) {
};
};

var decorator = function (a, b) {
renderer.css = function (a, b) {
return function (Klass) {
transformStatic(Klass, a, b);
};
};

return decorator;
};
5 changes: 0 additions & 5 deletions demo/demo1.html

This file was deleted.

17 changes: 0 additions & 17 deletions demo/demo1.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
"mocha": "5.0.4",
"chai": "4.1.2",
"webpack-bundle-analyzer": "^2.9.0",
"eslint": "^4.9.0"
"eslint": "^4.9.0",
"typescript": "2.7.2",
"tslib": "1.9.0",
"ts-loader": "3.5.0"
},
"config": {
"commitizen": {
Expand Down
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"removeComments": false,
"noImplicitAny": false,
"sourceMap": false,
"experimentalDecorators": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"jsx": "react",
"jsxFactory": "h",
"importHelpers": true,
"lib": [
"dom",
"es5",
"es6",
"es7",
"es2015",
"scripthost",
"dom.iterable"
]
}
}

0 comments on commit 9f2a4f1

Please sign in to comment.