Skip to content

Commit 0e5fe7f

Browse files
feat(FOROME-969): Added storybook and few stories (#611)
1 parent 2594e71 commit 0e5fe7f

File tree

10 files changed

+6398
-153
lines changed

10 files changed

+6398
-153
lines changed

.storybook/main.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path')
2+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
3+
4+
module.exports = {
5+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
6+
addons: [
7+
'@storybook/addon-links',
8+
'@storybook/addon-essentials',
9+
'@storybook/addon-interactions',
10+
'@storybook/preset-create-react-app',
11+
'storybook-dark-mode',
12+
],
13+
framework: '@storybook/react',
14+
core: {
15+
builder: '@storybook/builder-webpack5',
16+
},
17+
webpackFinal: async (config, { configType }) => {
18+
config.module.rules.push({
19+
test: /\.scss|.sass$/,
20+
use: ['style-loader', 'css-loader', 'sass-loader'],
21+
include: path.resolve(__dirname, '../'),
22+
})
23+
24+
config.resolve.plugins = [
25+
new TsconfigPathsPlugin({
26+
configFile: path.resolve(__dirname, '../tsconfig.json'),
27+
}),
28+
]
29+
30+
return config
31+
},
32+
}

.storybook/preview.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../src/index.css'
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+
}

package.json

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"react-intl": "5.15.8",
3131
"react-modal": "3.13.1",
3232
"react-popper": "2.2.5",
33+
"react-router": "5.2.0",
3334
"react-router-dom": "5.2.0",
3435
"react-scripts": "5.0.0",
3536
"react-switch": "6.0.0",
@@ -52,6 +53,17 @@
5253
"@commitlint/cli": "16.0.2",
5354
"@commitlint/config-conventional": "16.0.0",
5455
"@craco/craco": "6.4.3",
56+
"@storybook/addon-actions": "6.4.22",
57+
"@storybook/addon-essentials": "6.4.22",
58+
"@storybook/addon-interactions": "6.4.22",
59+
"@storybook/addon-links": "6.4.22",
60+
"@storybook/addon-postcss": "2.0.0",
61+
"@storybook/builder-webpack5": "6.4.22",
62+
"@storybook/manager-webpack5": "6.4.22",
63+
"@storybook/node-logger": "6.4.22",
64+
"@storybook/preset-create-react-app": "4.1.0",
65+
"@storybook/react": "6.4.22",
66+
"@storybook/testing-library": "0.0.11",
5567
"@testing-library/jest-dom": "5.11.4",
5668
"@testing-library/react": "11.1.0",
5769
"@testing-library/user-event": "12.1.10",
@@ -90,16 +102,20 @@
90102
"eslint-config-ts-react-important-stuff": "3.0.0",
91103
"eslint-plugin-formatjs": "2.20.5",
92104
"eslint-plugin-jest": "25.2.4",
105+
"eslint-plugin-prettier": "4.0.0",
93106
"eslint-plugin-promise": "6.0.0",
94107
"eslint-plugin-react": "7.28.0",
95108
"eslint-plugin-simple-import-sort": "7.0.0",
96109
"eslint-plugin-unicorn": "40.1.0",
97110
"lint-staged": "12.1.7",
98111
"postcss": "7",
99112
"simple-git-hooks": "2.7.0",
113+
"storybook-dark-mode": "1.1.0",
100114
"stylelint": "14.2.0",
101115
"stylelint-config-standard": "24.0.0",
102-
"tailwindcss": "npm:@tailwindcss/postcss7-compat"
116+
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
117+
"tsconfig-paths-webpack-plugin": "3.5.2",
118+
"webpack": "5.72.0"
103119
},
104120
"scripts": {
105121
"start": "node ./env.js && yarn & craco start",
@@ -113,7 +129,9 @@
113129
"test": "craco test",
114130
"eject": "react-scripts eject",
115131
"cy:open": "cypress open",
116-
"cy:run": "cypress run"
132+
"cy:run": "cypress run",
133+
"storybook": "start-storybook -p 6006 -s public",
134+
"build-storybook": "build-storybook -s public"
117135
},
118136
"simple-git-hooks": {
119137
"pre-commit": "yarn lint-stage && yarn lint:fix",
@@ -124,6 +142,16 @@
124142
"extends": [
125143
"react-app",
126144
"react-app/jest"
145+
],
146+
"overrides": [
147+
{
148+
"files": [
149+
"**/*.stories.*"
150+
],
151+
"rules": {
152+
"import/no-anonymous-default-export": "off"
153+
}
154+
}
127155
]
128156
},
129157
"browserslist": {

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

src/components/preset-control/preset-control-list/preset-control-list.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export const PresetControlList = ({
2525
onModify,
2626
onDelete,
2727
}: IPresetControlListProps): ReactElement => {
28-
const [contextMenuItem, setContextMenuItem] = useState<{
29-
name: string
30-
element: HTMLElement
31-
} | null>(null)
28+
const [contextMenuItem, setContextMenuItem] =
29+
useState<{
30+
name: string
31+
element: HTMLElement
32+
} | null>(null)
3233

3334
const closeContextMenu = () => {
3435
setContextMenuItem(null)

src/components/variant/drawer.utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export const useScrollShadow = (
3232
handleScroll: () => void
3333
handleStartScroll: () => void
3434
} => {
35-
const [startedLeftDistance, setStartedLeftDistance] = useState<number | null>(
36-
null,
37-
)
35+
const [startedLeftDistance, setStartedLeftDistance] =
36+
useState<number | null>(null)
3837

3938
const [shouldAddShadow, setShouldAddShadow] = useState(false)
4039

src/pages/filter/common/groups/chart/utils/useChartConfig.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ const getVariantsChartConfig = (
145145
export const useChartConfig = (
146146
status: TPropertyStatus,
147147
): TChartConfig | undefined => {
148-
const prevSourceRef = useRef<
149-
TNumericPropertyHistogram | TVariant[] | undefined
150-
>()
148+
const prevSourceRef =
149+
useRef<TNumericPropertyHistogram | TVariant[] | undefined>()
151150

152151
const configRef = useRef<TChartConfig>()
153152
const isNumeric = status.kind === AttributeKinds.NUMERIC

src/stories/button.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Button } from '@ui/button'
2+
import { ComponentMeta, ComponentStory } from '@storybook/react'
3+
4+
export default {
5+
title: 'Button',
6+
component: Button,
7+
} as ComponentMeta<typeof Button>
8+
9+
export const Template: ComponentStory<typeof Button> = args => (
10+
<Button variant="primary" text="Button" {...args} />
11+
)

src/stories/popper-menu.stories.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { PopperMenu } from '@components/popper-menu/popper-menu'
2+
import { PopperMenuItem } from '@components/popper-menu/popper-menu-item'
3+
import { ComponentMeta, ComponentStory } from '@storybook/react'
4+
5+
export default {
6+
title: 'Popper Menu',
7+
component: PopperMenu,
8+
} as ComponentMeta<typeof PopperMenu>
9+
10+
const Template: ComponentStory<typeof PopperMenu> = args => (
11+
<div style={{ width: '100px' }}>
12+
<PopperMenu {...args} close={() => {}}>
13+
{args.children}
14+
</PopperMenu>
15+
</div>
16+
)
17+
18+
export const Default = Template.bind({})
19+
20+
Default.args = {
21+
children: (
22+
<>
23+
<PopperMenuItem>Item 1</PopperMenuItem>
24+
<PopperMenuItem>Item 2</PopperMenuItem>
25+
</>
26+
),
27+
}
28+
29+
export const WithIcon = Template.bind({})
30+
31+
WithIcon.args = {
32+
children: (
33+
<>
34+
<PopperMenuItem iconName="Cloud">Item 1</PopperMenuItem>
35+
<PopperMenuItem iconName="Copy">Item 2</PopperMenuItem>
36+
</>
37+
),
38+
}

0 commit comments

Comments
 (0)