Skip to content

Commit 76e7a1e

Browse files
Kailash ChandraKailash Chandra
authored andcommitted
Updated Storybook setup
1 parent 2abcec6 commit 76e7a1e

7 files changed

Lines changed: 91 additions & 82 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import { withKnobs, text, optionsKnob } from "@storybook/addon-knobs";
3+
4+
import Button from "./index";
5+
6+
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
7+
export default {
8+
title: "Example/Button",
9+
component: Button,
10+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
11+
argTypes: {},
12+
decorators: [withKnobs],
13+
};
14+
15+
const Template = (args) => <Button {...args} />;
16+
17+
export const Primary = Template.bind({});
18+
Primary.args = {
19+
children: text("Label", "Button"),
20+
};
21+
22+
export const KnobExample = () => (
23+
<Button
24+
theme={optionsKnob(
25+
"Theme",
26+
{ Primary: "primary", Secondary: "secondary" },
27+
"primary",
28+
{ display: "select" }
29+
)}
30+
>
31+
{text("Label", "Button")}
32+
</Button>
33+
);

templates/common/src/components/atoms/Button/Button.story.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import { styled } from '@nextui-org/react';
1+
import { styled, Button } from "@nextui-org/react";
22

3-
const CompRoot = styled('button', {
4-
fontSize: '$3',
5-
color: '$fontColor',
6-
margin: '1em',
7-
padding: '0.25em 1em',
8-
border: '2px solid black',
9-
borderRadius: '$1',
10-
display: 'block',
11-
length: '1'
3+
const CompRoot = styled("button", {
4+
fontSize: "$3",
5+
color: "$fontColor",
6+
margin: "1em",
7+
padding: "0.25em 1em",
8+
border: "2px solid black",
9+
borderRadius: "$1",
10+
display: "block",
11+
length: "1",
12+
variants: {
13+
theme: {
14+
primary: {
15+
color: "$fontColor",
16+
},
17+
secondary: {
18+
background: "green",
19+
},
20+
},
21+
},
1222
});
1323

1424
export default CompRoot;

templates/common/src/components/atoms/Button/Button.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
// @flow
77

88
// Node_Module Imports
9-
import React from 'react';
9+
import React from "react";
1010

1111
// Relative imports
12-
import CompRoot from './Button.style';
13-
import { ButtonProps } from './types';
12+
import CompRoot from "./Button.style";
13+
import { ButtonProps } from "./types";
1414

15-
const Button: React.FunctionComponent<ButtonProps> = ({ className, children }) => (
16-
<CompRoot className={className} data-testid="CompRoot">
15+
const Button: React.FunctionComponent<ButtonProps> = ({
16+
className,
17+
children,
18+
...otherProps
19+
}) => (
20+
<CompRoot className={className} data-testid="CompRoot" {...otherProps}>
1721
{children}
1822
</CompRoot>
1923
);
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
2-
const path = require('path');
1+
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
2+
const path = require("path");
33

44
module.exports = {
55
addons: [
6-
'@storybook/addon-a11y',
7-
'@storybook/addon-actions',
8-
'@storybook/addon-docs',
9-
'@storybook/addon-knobs',
10-
'@storybook/addon-links',
11-
'storybook-design-token',
12-
'@storybook/addon-viewport'
6+
"@storybook/addon-a11y",
7+
"@storybook/addon-actions",
8+
"@storybook/addon-docs",
9+
"@storybook/addon-knobs",
10+
"@storybook/addon-links",
11+
"storybook-design-token",
12+
"@storybook/addon-viewport",
1313
],
14-
framework: '@storybook/react',
14+
framework: "@storybook/react",
1515
core: {
16-
builder: 'webpack5'
16+
builder: "webpack5",
1717
},
18+
stories: [
19+
"../../**/*.stories.mdx",
20+
"../../**/*.stories.@(js|jsx|ts|tsx)",
21+
],
1822
webpackFinal: async (config) => {
1923
config.resolve.plugins = [
2024
...(config.resolve.plugins || []),
2125
new TsconfigPathsPlugin({
2226
extensions: config.resolve.extensions,
23-
configFile: path.resolve('tsconfig.json')
24-
})
27+
configFile: path.resolve("tsconfig.json"),
28+
}),
2529
];
2630
return config;
27-
}
31+
},
2832
};
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,9 @@
1-
import React from 'react';
2-
import { addDecorator, configure, storiesOf } from '@storybook/react';
3-
import { NextUIProvider } from '@nextui-org/react';
4-
import { theme } from 'themes';
5-
61
export const parameters = {
7-
actions: { argTypesRegex: '^on[A-Z].*' },
2+
actions: { argTypesRegex: "^on[A-Z].*" },
83
controls: {
94
matchers: {
105
color: /(background|color)$/i,
11-
date: /Date$/
12-
}
13-
}
14-
};
15-
16-
addDecorator((storyFn, context) => (
17-
<NextUIProvider theme={theme}>{storyFn(context)}</NextUIProvider>
18-
));
19-
20-
const req = require.context('../../', true, /story\.tsx$/);
21-
22-
function loadStories() {
23-
req.keys().forEach((filename) => {
24-
const configs = { ...req(filename).default };
25-
let sections = configs.sections;
26-
27-
const stories = storiesOf(
28-
`${configs.componentType}/${configs.componentName}`,
29-
module
30-
);
31-
sections.forEach((section) => stories.add(section.title, section.sectionFn));
32-
33-
// Create story for Component.
34-
return stories;
35-
});
36-
}
37-
38-
configure(loadStories, module);
6+
date: /Date$/,
7+
},
8+
},
9+
}

templates/common/storybook/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
"dependencies": {
1111
"@babel/core": "^7.15.5",
1212
"@babel/preset-react": "^7.12.10",
13+
"@nextui-org/react": "^1.0.5-beta.5",
1314
"@storybook/addon-a11y": "^6.4.18",
1415
"@storybook/addon-actions": "^6.4.18",
15-
"@storybook/addon-essentials": "^6.4.18",
1616
"@storybook/addon-docs": "^6.4.18",
17+
"@storybook/addon-essentials": "^6.4.18",
1718
"@storybook/addon-knobs": "^6.4.0",
1819
"@storybook/addon-links": "^6.4.18",
1920
"@storybook/addon-viewport": "^6.4.18",
2021
"@storybook/builder-webpack5": "^6.4.18",
2122
"@storybook/cli": "^6.4.18",
2223
"@storybook/manager-webpack5": "^6.4.18",
2324
"@storybook/react": "^6.4.18",
24-
"tsconfig-paths-webpack-plugin": "^3.5.2",
25+
"@storybook/testing-library": "^0.0.9",
2526
"storybook-design-token": "^1.2.2",
26-
"@nextui-org/react": "^1.0.5-beta.5" },
27+
"tsconfig-paths-webpack-plugin": "^3.5.2",
28+
"webpack": "^5.72.0"
29+
},
2730
"devDependencies": {
2831
"tsconfig": "*"
2932
}

0 commit comments

Comments
 (0)