Skip to content

Commit c90149d

Browse files
authored
Merge pull request #21 from opendexnetwork/feat/storybook
feat: add storybook
2 parents 90e6d49 + 7e746cf commit c90149d

File tree

9 files changed

+5465
-1458
lines changed

9 files changed

+5465
-1458
lines changed

.storybook/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/preset-create-react-app"
10+
]
11+
}

.storybook/manager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { addons } from "@storybook/addons";
2+
import theme from "./theme";
3+
4+
addons.setConfig({
5+
theme,
6+
});

.storybook/preview.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from "react";
2+
import { ThemeProvider } from "@material-ui/core";
3+
import { createMuiTheme } from "@material-ui/core/styles";
4+
import { addDecorator } from "@storybook/react";
5+
import { withThemes } from "@react-theming/storybook-addon";
6+
import { darkTheme } from "../src/themes";
7+
import storybookTheme from "./theme";
8+
9+
const providerFn = ({ theme, children }) => {
10+
const muTheme = createMuiTheme(theme);
11+
return <ThemeProvider theme={muTheme}>{children}</ThemeProvider>;
12+
};
13+
14+
addDecorator(withThemes(null, [darkTheme], { providerFn }));
15+
16+
export const parameters = {
17+
actions: { argTypesRegex: "^on[A-Z].*" },
18+
docs: {
19+
theme: storybookTheme,
20+
},
21+
};

.storybook/theme.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { create } from "@storybook/theming";
2+
import { darkTheme } from "../src/themes";
3+
4+
export default create({
5+
base: "dark",
6+
brandTitle: "OpenDEX storybook",
7+
brandImage:
8+
"https://gblobscdn.gitbook.com/spaces%2F-Lq7dAvRcXVJXcPrZrNF%2Favatar.png?alt=media",
9+
});

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ A graphical user interface for interacting with an [opendex-docker](https://gith
2727
### Lint
2828

2929
`yarn lint`
30+
31+
### Develop view components
32+
33+
`yarn storybook`

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"eject": "react-scripts eject",
1111
"lint": "eslint . --ext .js,.ts,.tsx",
1212
"check-prettier": "prettier --check src/",
13-
"prettier": "prettier --write src/"
13+
"prettier": "prettier --write src/",
14+
"storybook": "start-storybook -p 6006 -s public --no-manager-cache",
15+
"build-storybook": "build-storybook -s public"
1416
},
1517
"dependencies": {
1618
"@fortawesome/fontawesome-svg-core": "^1.2.32",
@@ -34,6 +36,15 @@
3436
"xterm-addon-fit": "^0.4.0"
3537
},
3638
"devDependencies": {
39+
"@react-theming/storybook-addon": "^1.0.3",
40+
"@storybook/addon-actions": "^6.1.21",
41+
"@storybook/addon-essentials": "^6.1.21",
42+
"@storybook/addon-links": "^6.1.21",
43+
"@storybook/addons": "^6.1.21",
44+
"@storybook/node-logger": "^6.1.21",
45+
"@storybook/preset-create-react-app": "^3.1.6",
46+
"@storybook/react": "^6.1.21",
47+
"@storybook/theming": "^6.1.21",
3748
"@testing-library/jest-dom": "^5.11.4",
3849
"@testing-library/react": "^11.1.0",
3950
"@testing-library/user-event": "^12.1.10",

src/common/components/input/buttons/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReactElement } from "react";
22
import ButtonBase, { ButtonBaseProps } from "./ButtonBase";
33

4-
type ButtonProps = Omit<ButtonBaseProps, "variant"> & {
4+
export type ButtonProps = Omit<ButtonBaseProps, "variant"> & {
55
variant?: "contained" | "outlined";
66
};
77

src/stories/Button.stories.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Button, { ButtonProps } from "../common/components/input/buttons/Button";
2+
import React from "react";
3+
import { Story, Meta } from "@storybook/react/types-6-0";
4+
5+
export default {
6+
title: "Button",
7+
component: Button,
8+
argTypes: {
9+
text: { defaultValue: "I'm a Button" },
10+
},
11+
} as Meta;
12+
13+
const Template: Story<ButtonProps> = (args: ButtonProps) => (
14+
<Button {...args} />
15+
);
16+
17+
export const PrimaryButton = Template.bind({});
18+
PrimaryButton.args = {
19+
color: "primary",
20+
};
21+
22+
export const OutlinedButton = Template.bind({});
23+
OutlinedButton.args = {
24+
color: "default",
25+
variant: "outlined",
26+
};

0 commit comments

Comments
 (0)