Skip to content

Commit 68c063a

Browse files
riccardo-forinaseanforyou23
authored andcommitted
feat: add Storybook (#66)
1 parent 4e1ed02 commit 68c063a

File tree

10 files changed

+4035
-110
lines changed

10 files changed

+4035
-110
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
yarn-error.log
44
stats.json
55
coverage
6+
storybook-static

.storybook/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { configure } from '@storybook/react';
2+
import '@patternfly/react-core/dist/styles/base.css';
3+
4+
// automatically import all files ending in *.stories.tsx
5+
const req = require.context('../stories', true, /\.stories\.tsx$/);
6+
7+
function loadStories() {
8+
req.keys().forEach(req);
9+
}
10+
11+
configure(loadStories, module);

.storybook/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.json"
3+
}

.storybook/webpack.config.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const path = require('path');
2+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
3+
const appConfig = require('../webpack.common');
4+
5+
module.exports = ({ config }) => {
6+
config.module.rules = [];
7+
config.module.rules.push(...appConfig.module.rules);
8+
config.module.rules.push({
9+
test: /\.css$/,
10+
include: [
11+
path.resolve(__dirname, '../src'),
12+
path.resolve(__dirname, '../node_modules/@storybook'),
13+
path.resolve(__dirname, '../node_modules/patternfly'),
14+
path.resolve(__dirname, '../node_modules/@patternfly/patternfly'),
15+
path.resolve(__dirname, '../node_modules/@patternfly/react-styles/css'),
16+
path.resolve(__dirname, '../node_modules/@patternfly/react-core/dist/styles/base.css'),
17+
path.resolve(__dirname, '../node_modules/@patternfly/react-core/dist/esm/@patternfly/patternfly'),
18+
path.resolve(__dirname, '../node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css'),
19+
path.resolve(__dirname, '../node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css'),
20+
path.resolve(__dirname, '../node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css')
21+
],
22+
use: ["style-loader", "css-loader"]
23+
});
24+
config.module.rules.push({
25+
test: /\.tsx?$/,
26+
include: path.resolve(__dirname, '../src'),
27+
use: [
28+
require.resolve('react-docgen-typescript-loader'),
29+
],
30+
})
31+
config.resolve.plugins = [
32+
new TsconfigPathsPlugin({
33+
configFile: path.resolve(__dirname, "../tsconfig.json")
34+
})
35+
];
36+
config.resolve.extensions.push('.ts', '.tsx');
37+
return config;
38+
};

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
"format": "prettier --check --write ./src/**/*.{tsx,ts,js}",
1616
"build:bundle-profile": "webpack --config webpack.prod.js --profile --json > stats.json",
1717
"bundle-profile:analyze": "yarn build:bundle-profile && webpack-bundle-analyzer ./stats.json",
18-
"clean": "rimraf dist"
18+
"clean": "rimraf dist",
19+
"storybook": "start-storybook -p 6006",
20+
"build:storybook": "build-storybook"
1921
},
2022
"devDependencies": {
23+
"@storybook/addon-actions": "^5.2.1",
24+
"@storybook/addon-info": "^5.2.1",
25+
"@storybook/addon-links": "^5.2.1",
26+
"@storybook/addons": "^5.2.1",
27+
"@storybook/react": "^5.2.1",
2128
"@types/enzyme": "^3.10.3",
2229
"@types/enzyme-adapter-react-16": "^1.0.5",
2330
"@types/jest": "^24.0.17",
2431
"@types/node": "^12.7.1",
2532
"@types/react": "^16.8.25",
2633
"@types/react-dom": "^16.8.5",
2734
"@types/react-router-dom": "^4.3.4",
35+
"@types/storybook__react": "^4.0.2",
2836
"@types/victory": "^31.0.14",
2937
"@types/webpack": "^4.32.1",
3038
"css-loader": "^3.2.0",
@@ -42,6 +50,7 @@
4250
"raw-loader": "^3.1.0",
4351
"react": "^16.8.4",
4452
"react-axe": "^3.0.2",
53+
"react-docgen-typescript-loader": "^3.2.1",
4554
"react-dom": "^16.6.3",
4655
"regenerator-runtime": "^0.13.3",
4756
"rimraf": "^3.0.0",

src/app/Support/Support.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
EmptyStateSecondaryActions
1212
} from '@patternfly/react-core';
1313

14-
const Support: React.FunctionComponent<any> = (props) => {
14+
export interface ISupportProps {
15+
sampleProp?: string;
16+
}
17+
18+
const Support: React.FunctionComponent<ISupportProps> = (props) => {
1519
return (
1620
<PageSection>
1721
<EmptyState variant={EmptyStateVariant.full}>

stories/Dashboard.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { withInfo } from '@storybook/addon-info';
4+
import { Dashboard } from '@app/Dashboard/Dashboard';
5+
6+
const stories = storiesOf('Components', module);
7+
stories.addDecorator(withInfo);
8+
stories.add(
9+
'Dashboard',
10+
() => <Dashboard />,
11+
{ info: { inline: true } }
12+
);

stories/Support.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { withInfo } from '@storybook/addon-info';
4+
import { Support } from '@app/Support/Support';
5+
6+
const stories = storiesOf('Components', module);
7+
stories.addDecorator(withInfo);
8+
stories.add(
9+
'Support',
10+
() => <Support />,
11+
{ info: { inline: true } }
12+
);

webpack.common.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = {
1717
rules: [
1818
{
1919
test: /\.(tsx|ts|jsx)?$/,
20-
include: path.resolve(__dirname, 'src'),
2120
use: [
2221
{
2322
loader: 'ts-loader',

0 commit comments

Comments
 (0)