Skip to content

Commit

Permalink
feat: add Storybook (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina authored and seanforyou23 committed Oct 1, 2019
1 parent 4e1ed02 commit 68c063a
Show file tree
Hide file tree
Showing 10 changed files with 4,035 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
yarn-error.log
stats.json
coverage
storybook-static
11 changes: 11 additions & 0 deletions .storybook/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { configure } from '@storybook/react';
import '@patternfly/react-core/dist/styles/base.css';

// automatically import all files ending in *.stories.tsx
const req = require.context('../stories', true, /\.stories\.tsx$/);

function loadStories() {
req.keys().forEach(req);
}

configure(loadStories, module);
3 changes: 3 additions & 0 deletions .storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}
38 changes: 38 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const appConfig = require('../webpack.common');

module.exports = ({ config }) => {
config.module.rules = [];
config.module.rules.push(...appConfig.module.rules);
config.module.rules.push({
test: /\.css$/,
include: [
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules/@storybook'),
path.resolve(__dirname, '../node_modules/patternfly'),
path.resolve(__dirname, '../node_modules/@patternfly/patternfly'),
path.resolve(__dirname, '../node_modules/@patternfly/react-styles/css'),
path.resolve(__dirname, '../node_modules/@patternfly/react-core/dist/styles/base.css'),
path.resolve(__dirname, '../node_modules/@patternfly/react-core/dist/esm/@patternfly/patternfly'),
path.resolve(__dirname, '../node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css'),
path.resolve(__dirname, '../node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css'),
path.resolve(__dirname, '../node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css')
],
use: ["style-loader", "css-loader"]
});
config.module.rules.push({
test: /\.tsx?$/,
include: path.resolve(__dirname, '../src'),
use: [
require.resolve('react-docgen-typescript-loader'),
],
})
config.resolve.plugins = [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, "../tsconfig.json")
})
];
config.resolve.extensions.push('.ts', '.tsx');
return config;
};
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
"format": "prettier --check --write ./src/**/*.{tsx,ts,js}",
"build:bundle-profile": "webpack --config webpack.prod.js --profile --json > stats.json",
"bundle-profile:analyze": "yarn build:bundle-profile && webpack-bundle-analyzer ./stats.json",
"clean": "rimraf dist"
"clean": "rimraf dist",
"storybook": "start-storybook -p 6006",
"build:storybook": "build-storybook"
},
"devDependencies": {
"@storybook/addon-actions": "^5.2.1",
"@storybook/addon-info": "^5.2.1",
"@storybook/addon-links": "^5.2.1",
"@storybook/addons": "^5.2.1",
"@storybook/react": "^5.2.1",
"@types/enzyme": "^3.10.3",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.17",
"@types/node": "^12.7.1",
"@types/react": "^16.8.25",
"@types/react-dom": "^16.8.5",
"@types/react-router-dom": "^4.3.4",
"@types/storybook__react": "^4.0.2",
"@types/victory": "^31.0.14",
"@types/webpack": "^4.32.1",
"css-loader": "^3.2.0",
Expand All @@ -42,6 +50,7 @@
"raw-loader": "^3.1.0",
"react": "^16.8.4",
"react-axe": "^3.0.2",
"react-docgen-typescript-loader": "^3.2.1",
"react-dom": "^16.6.3",
"regenerator-runtime": "^0.13.3",
"rimraf": "^3.0.0",
Expand Down
6 changes: 5 additions & 1 deletion src/app/Support/Support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
EmptyStateSecondaryActions
} from '@patternfly/react-core';

const Support: React.FunctionComponent<any> = (props) => {
export interface ISupportProps {
sampleProp?: string;
}

const Support: React.FunctionComponent<ISupportProps> = (props) => {
return (
<PageSection>
<EmptyState variant={EmptyStateVariant.full}>
Expand Down
12 changes: 12 additions & 0 deletions stories/Dashboard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { Dashboard } from '@app/Dashboard/Dashboard';

const stories = storiesOf('Components', module);
stories.addDecorator(withInfo);
stories.add(
'Dashboard',
() => <Dashboard />,
{ info: { inline: true } }
);
12 changes: 12 additions & 0 deletions stories/Support.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { Support } from '@app/Support/Support';

const stories = storiesOf('Components', module);
stories.addDecorator(withInfo);
stories.add(
'Support',
() => <Support />,
{ info: { inline: true } }
);
1 change: 0 additions & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'ts-loader',
Expand Down
Loading

0 comments on commit 68c063a

Please sign in to comment.