Skip to content

Commit 2dc3fcc

Browse files
author
Kristian Djaković
authored
Merge pull request #35 from infinum/fix-storybook
Fix storybook
2 parents 576f332 + 44ee86b commit 2dc3fcc

File tree

7 files changed

+43878
-22419
lines changed

7 files changed

+43878
-22419
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ yarn-error.log*
3737
# sitemaps
3838
public/sitemap*.xml
3939
public/robots.txt
40+
41+
# storybook
42+
storybook-static

.storybook/main.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ const path = require('path');
44
const toPath = (_path) => path.join(process.cwd(), _path);
55

66
module.exports = {
7+
core: {
8+
builder: 'webpack5',
9+
},
710
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.(js|jsx|ts|tsx)', '../src/**/stories.(js|jsx|ts|tsx)'],
811
addons: [
912
'@storybook/addon-a11y',
1013
'@storybook/addon-links',
1114
'@storybook/addon-essentials',
1215
'storybook-addon-next-router',
16+
'@chakra-ui/storybook-addon',
1317
],
1418
typescript: {
1519
reactDocgen: false,
1620
},
21+
features: {
22+
emotionAlias: false,
23+
},
1724
webpackFinal: async (config) => {
1825
// Remove default svg file loader
1926
const rules = config.module.rules.map((rule) => {
@@ -25,16 +32,26 @@ module.exports = {
2532
}
2633
});
2734

35+
config.module.rules.push({
36+
test: /\.mjs$/,
37+
include: /node_modules/,
38+
type: 'javascript/auto',
39+
});
40+
2841
return {
2942
...config,
3043
resolve: {
3144
...config.resolve,
32-
plugins: [...config.resolve.plugins, new TsconfigPathsPlugin()],
33-
alias: {
34-
...config.resolve.alias,
35-
'@emotion/core': toPath('node_modules/@emotion/react'),
36-
'emotion-theming': toPath('node_modules/@emotion/react'),
45+
fallback: {
46+
fs: false,
47+
path: false,
3748
},
49+
plugins: [
50+
...(config.resolve.plugins || []),
51+
new TsconfigPathsPlugin({
52+
extensions: config.resolve.extensions,
53+
}),
54+
],
3855
},
3956
module: {
4057
rules: [
@@ -50,4 +67,9 @@ module.exports = {
5067
},
5168
};
5269
},
70+
env: (config) => ({
71+
...config,
72+
__NEXT_NEW_LINK_BEHAVIOR: JSON.stringify(true),
73+
}),
74+
staticDirs: ['../public'],
5375
};

.storybook/preview.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { withPerformance } from 'storybook-addon-performance';
21
import { RouterContext } from 'next/dist/shared/lib/router-context';
32
import { initializeWorker, mswDecorator } from 'msw-storybook-addon';
3+
import theme from '../src/styles/theme';
44

5-
import { withThemeProvider } from './withThemeProvider';
65
import { withDatxProvider } from './withDatxProvider';
76

87
import 'focus-visible/dist/focus-visible';
98

109
initializeWorker();
1110

12-
export const decorators = [mswDecorator, withDatxProvider, withThemeProvider, withPerformance];
11+
export const decorators = [mswDecorator, withDatxProvider];
1312

1413
export const parameters = {
1514
actions: { argTypesRegex: '^on[A-Z].*' },
@@ -39,4 +38,7 @@ export const globalTypes = {
3938
items: [{ value: 'default', title: 'Default Theme' }],
4039
},
4140
},
41+
chakra: {
42+
theme,
43+
},
4244
};

.storybook/withDatxProvider.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { createFetcher, DatxProvider, useInitialize } from '@datx/swr';
12
import { Story, StoryContext } from '@storybook/react';
2-
import React from 'react';
3-
import { cache } from 'swr';
3+
import { SWRConfig } from 'swr';
44

5-
import { DatxProvider } from '../src/libs/@datx/jsonapi-react';
6-
import client from '../src/store';
5+
import { createClient } from '../src/datx/create-client';
76

87
export const withDatxProvider = (StoryFn: Story, context: StoryContext) => {
9-
cache.clear();
8+
const client = useInitialize(createClient);
109

1110
return (
1211
<DatxProvider client={client}>
13-
<StoryFn />
12+
<SWRConfig value={{ fetcher: createFetcher(client), provider: () => new Map() }}>
13+
<StoryFn />
14+
</SWRConfig>
1415
</DatxProvider>
1516
);
1617
};

.storybook/withThemeProvider.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)