Skip to content

Commit 563107c

Browse files
committed
feat: using react-docgen-typescript-loader in storybook
1 parent 31066a1 commit 563107c

File tree

8 files changed

+90
-51
lines changed

8 files changed

+90
-51
lines changed
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
const path = require('path')
22

3-
module.exports = {
4-
module: {
5-
rules: [
3+
module.exports = (baseConfig, env, defaultConfig) => {
4+
defaultConfig.module.rules.push({
5+
test: /\.(ts|tsx)$/,
6+
use: [
67
{
7-
test: /\.scss$/,
8-
use: ['style-loader', 'css-loader', 'sass-loader'],
8+
loader: require.resolve('babel-loader'),
9+
options: {
10+
cacheDirectory: true,
11+
...require('../../.babelrc')
12+
}
913
},
10-
{
11-
test: /\.jsx?$/,
12-
use: {
13-
loader: 'babel-loader',
14-
options: {
15-
cacheDirectory: true,
16-
}
17-
},
18-
exclude: /node_modules/,
19-
}
14+
require.resolve('react-docgen-typescript-loader')
2015
]
21-
},
22-
resolve: {
23-
extensions: ['.js', '.jsx'],
24-
modules: ['node_modules', '../node_modules']
25-
},
16+
}, {
17+
test: /\.scss$/,
18+
use: ['style-loader', 'css-loader', 'sass-loader']
19+
})
20+
21+
defaultConfig.resolve.extensions.push('.ts', '.tsx')
22+
23+
defaultConfig.resolve.modules.push(
24+
path.resolve(__dirname, '../node_modules'),
25+
path.resolve(__dirname, '../../node_modules')
26+
)
27+
28+
defaultConfig.devServer = {
29+
inline: true,
30+
hot: true
31+
}
32+
33+
return defaultConfig
2634
}

template/examples/package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"dev": "start-storybook -p 9001 -c .storybook",
98
"build-storybook": "build-storybook -s public",
109
"deploy": "storybook-to-ghpages"
1110
},
1211
"storybook-deployer": {
13-
"gitUsername": "Yuki Bot",
14-
"gitEmail": "zhangjihong1993@gmail.com",
12+
"gitUsername": "<%= username %>'s bot",
13+
"gitEmail": "<%= email %>",
1514
"commitMessage": "Deploy Storybook"
1615
},
17-
"author": "",
16+
"author": "<%= username %> <<%= email %>>",
1817
"license": "MIT",
1918
"devDependencies": {
20-
"@storybook/addon-options": "^3.2.17",
21-
"@storybook/react": "^3.2.15",
19+
"@babel/core": "^7.0.1",
20+
"@storybook/addon-info": "^3.4.10",
21+
"@storybook/addon-options": "^3.4.10",
22+
"@storybook/react": "^3.4.10",
23+
"@types/storybook__addon-actions": "^3.4.1",
24+
"@types/storybook__addon-info": "^3.4.2",
25+
"@types/storybook__react": "^3.0.9",
26+
"babel-loader": "^8.0.2",
2227
"css-loader": "^0.28.7",
2328
"node-sass": "^4.7.2",
29+
"react-docgen-typescript-loader": "^2.2.0",
2430
"sass-loader": "^6.0.6",
25-
"style-loader": "^0.19.0"
31+
"style-loader": "^0.19.0",
32+
"typescript": "^3.0.3"
2633
},
2734
"dependencies": {
2835
"react": "^16.1.1",

template/examples/stories/index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

template/examples/stories/index.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { CSSProperties} from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import { withInfo } from "@storybook/addon-info"
4+
// import { action } from '@storybook/addon-actions'
5+
6+
import Hello from 'index'
7+
8+
storiesOf('Hello', module)
9+
.add('with text', () => (
10+
<Hello content="world" />
11+
))
12+
.add('docs', withInfo({ inline: true })(() => (
13+
<div style={styles.container}>
14+
<div style={styles.firstCellContainer}>
15+
<Hello content="world!!!233" />
16+
</div>
17+
<div style={styles.cellContainer}>
18+
<Hello content="world" />
19+
</div>
20+
</div>
21+
)))
22+
23+
const styles: { [key: string]: CSSProperties } = {
24+
container: {
25+
display: "flex",
26+
},
27+
cellContainer: {
28+
width: 100,
29+
height: 100,
30+
backgroundColor: "rgb(72, 78, 104)",
31+
},
32+
};
33+
styles.firstCellContainer = { ...styles.cellContainer, marginRight: 20 };

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"devDependencies": {
3535
"@babel/cli": "^7.0.0",
3636
"@babel/core": "^7.0.1",
37+
"@babel/plugin-proposal-class-properties": "^7.0.0",
3738
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
3839
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
3940
"@babel/preset-env": "^7.0.0",

template/src/Hello.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import React from 'react'
1+
import React, { PureComponent } from 'react'
22
import a from './a'
33

4-
class Hello extends React.PureComponent<{
5-
content: string;
6-
}, {}> {
4+
interface Props {
5+
/**
6+
* Value to display, either empty string or you passed
7+
*
8+
* @default ""
9+
**/
10+
content?: string;
11+
}
12+
13+
export class Hello extends PureComponent<Props, {}> {
714
render () {
815
return (
916
<div className='title'>
10-
{a} 2222 {this.props.content}
17+
{a} {this.props.content}
1118
</div>
1219
)
1320
}
1421
}
15-
16-
export default Hello

template/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import Hello from './Hello'
1+
export { Hello as default } from './Hello'
22
import './styles.scss'
3-
4-
export default Hello

template/tests/a.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import A from '../src/a'
1+
import A from 'src/a'
22

33
test('a should return a string', () => {
44
expect(typeof A).toBe('string')

0 commit comments

Comments
 (0)