Skip to content

Commit da8095f

Browse files
authored
feat: implement components with storybook v6 (#702)
1 parent a24b4e4 commit da8095f

14 files changed

+3634
-4537
lines changed

.storybook/addons.js

-3
This file was deleted.

.storybook/config.js

-12
This file was deleted.

.storybook/main.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
3+
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
4+
framework: '@storybook/react',
5+
webpackFinal: async (config) => {
6+
config.module.rules.push({
7+
test: /\.less$/,
8+
use: [
9+
'style-loader',
10+
'css-loader',
11+
{
12+
loader: 'less-loader',
13+
options: { javascriptEnabled: true },
14+
},
15+
],
16+
})
17+
return config
18+
},
19+
}

.storybook/preview.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../src/index.less'
2+
3+
export const parameters = {
4+
actions: { argTypesRegex: '^on[A-Z].*' },
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/,
9+
},
10+
},
11+
}

.storybook/webpack.config.js

-31
This file was deleted.

babel.config.js

-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,4 @@ module.exports = {
1010
'@babel/typescript',
1111
'@babel/react',
1212
],
13-
plugins: [
14-
'@babel/plugin-proposal-optional-chaining',
15-
'@babel/proposal-class-properties',
16-
'@babel/proposal-object-rest-spread',
17-
],
1813
}

package.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,29 @@
1515
"main": "index.js",
1616
"scripts": {
1717
"build": "webpack --mode=production",
18-
"build-storybook": "build-storybook",
1918
"codegen": "graphql-codegen --config codegen.yml",
2019
"lint": "eslint 'src/**/*.ts{,x}' --cache",
2120
"start": "webpack-dev-server",
21+
"test": "tsc -p ./tsconfig.json",
2222
"storybook": "start-storybook -p 6006",
23-
"test": "tsc -p ./tsconfig.json"
23+
"build-storybook": "build-storybook"
2424
},
2525
"resolutions": {
2626
"@types/react": "16.14.20",
2727
"@types/react-dom": "16.9.10"
2828
},
2929
"dependencies": {
30+
"@ant-design/icons": "4.7.0",
3031
"@apollo/client": "3.3.21",
3132
"antd": "4.11.2",
3233
"react": "17.0.2",
3334
"react-dom": "17.0.2",
34-
"react-hot-loader": "4.13.0",
3535
"react-router": "5.1.2",
3636
"react-router-dom": "5.1.2",
3737
"styled-components": "5.1.0"
3838
},
3939
"devDependencies": {
4040
"@babel/core": "7.14.6",
41-
"@babel/plugin-proposal-class-properties": "7.14.5",
42-
"@babel/plugin-proposal-object-rest-spread": "7.14.7",
43-
"@babel/plugin-proposal-optional-chaining": "7.14.5",
4441
"@babel/preset-env": "7.14.7",
4542
"@babel/preset-react": "7.14.5",
4643
"@babel/preset-typescript": "7.14.5",
@@ -51,12 +48,10 @@
5148
"@graphql-codegen/typescript-operations": "1.18.4",
5249
"@graphql-codegen/typescript-react-apollo": "2.3.1",
5350
"@hot-loader/react-dom": "16.13.0",
54-
"@storybook/addon-actions": "5.3.18",
55-
"@storybook/addon-knobs": "5.3.18",
56-
"@storybook/addon-links": "5.3.18",
57-
"@storybook/addons": "5.3.18",
58-
"@storybook/cli": "5.3.18",
59-
"@storybook/react": "5.3.18",
51+
"@storybook/addon-actions": "^6.4.5",
52+
"@storybook/addon-essentials": "^6.4.5",
53+
"@storybook/addon-links": "^6.4.5",
54+
"@storybook/react": "^6.4.5",
6055
"@types/clean-webpack-plugin": "0.1.3",
6156
"@types/html-webpack-plugin": "3.2.4",
6257
"@types/jest": "25.2.3",

src/App.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
2-
import { hot } from 'react-hot-loader/root'
32

43
import { Routes } from './routes'
54

6-
export const App = hot(() => <Routes />)
5+
export const App = () => <Routes />

src/components/Todos/index.tsx

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react'
2+
import { List, Typography, Space } from 'antd'
3+
import { CheckCircleTwoTone } from '@ant-design/icons'
4+
5+
type Todo = {
6+
id: number
7+
contents: string
8+
finished: boolean
9+
}
10+
11+
type Props = {
12+
isLoading?: boolean
13+
todos: Todo[]
14+
}
15+
16+
export const Todos: React.VFC<Props> = ({ todos, isLoading }) => {
17+
return (
18+
<List
19+
size="large"
20+
loading={isLoading}
21+
dataSource={todos}
22+
renderItem={({ id, contents, finished }) => (
23+
<List.Item key={id}>
24+
<Typography.Title>
25+
<Space>
26+
<CheckCircleTwoTone
27+
twoToneColor={finished ? '#52c41a' : '#e3e3e3'}
28+
/>
29+
{contents}
30+
</Space>
31+
</Typography.Title>
32+
{/* <Typography.Title level={5}>{contents}</Typography.Title> */}
33+
</List.Item>
34+
)}
35+
/>
36+
)
37+
}

src/components/button/index.stories.tsx

-9
This file was deleted.

src/components/button/index.tsx

-10
This file was deleted.

src/components/common/index.tsx

-13
This file was deleted.
+28-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
import { text } from '@storybook/addon-knobs'
2-
import { storiesOf } from '@storybook/react'
3-
import { Button } from 'antd'
1+
import { ComponentStory, ComponentMeta } from '@storybook/react'
42
import * as React from 'react'
53

6-
import { MarginCard, Wrapper } from '../common'
4+
import { Todos } from '../Todos'
75

8-
storiesOf('story/usage', module).add('default', () => {
9-
return (
10-
<Wrapper>
11-
<MarginCard title="First">
12-
<Button>{text('first', '1st')}</Button>
13-
</MarginCard>
14-
<MarginCard title="Second">
15-
<Button>{text('second', '2nd')}</Button>
16-
</MarginCard>
17-
</Wrapper>
18-
)
19-
})
6+
const todos = [
7+
{
8+
id: 1,
9+
contents: 'should do',
10+
finished: false,
11+
},
12+
{
13+
id: 2,
14+
contents: 'done is better',
15+
finished: true,
16+
},
17+
]
18+
19+
const meta: ComponentMeta<typeof Todos> = {
20+
title: 'Example/Todos',
21+
component: Todos,
22+
args: {
23+
todos,
24+
},
25+
}
26+
27+
export default meta
28+
29+
const Template: ComponentStory<typeof Todos> = (args) => <Todos {...args} />
30+
31+
export const Main = Template.bind({})

0 commit comments

Comments
 (0)