Skip to content

Commit 790ce1a

Browse files
authored
resolves theopenconversationkit#126: Update to Storybook 7 (theopenconversationkit#129)
* resolve theopenconversationkit#126: migrate to Storybook 7 * Add story for Loader component * Add theme configuration to storybook toolbar
1 parent dac77ab commit 790ce1a

28 files changed

+5274
-2790
lines changed

.babelrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"sourceType": "unambiguous",
3+
"presets": [
4+
[
5+
"@babel/preset-env",
6+
{
7+
"targets": {
8+
"chrome": 100,
9+
"safari": 15,
10+
"firefox": 91
11+
}
12+
}
13+
],
14+
"@babel/preset-typescript",
15+
"@babel/preset-react"
16+
],
17+
"plugins": []
18+
}

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
1717
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
1818
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
19+
'plugin:storybook/recommended',
1920
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
2021
],
2122

.storybook/addons.js

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

.storybook/config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import {ThemeProvider} from "@emotion/react";
3+
import {createTheme} from "../../src";
4+
5+
export const palettes = {
6+
default: {},
7+
alternative: {
8+
text: {
9+
user: '#fad390',
10+
bot: '#f8c291',
11+
card: '#6a89cc',
12+
input: '#82ccdd',
13+
},
14+
background: {
15+
user: '#e58e26',
16+
bot: '#b71540',
17+
card: '#0c2461',
18+
input: '#0a3d62',
19+
inputDisabled: '#079992',
20+
},
21+
}
22+
}
23+
24+
export const sizings = {
25+
default: {},
26+
alternative: {
27+
loaderSize: '20px',
28+
borderRadius: '4em',
29+
conversation: {
30+
width: '400px',
31+
},
32+
}
33+
}
34+
35+
export const typographies = {
36+
default: {},
37+
alternative: {
38+
fontFamily: 'cursive',
39+
fontSize: '1em',
40+
}
41+
}
42+
43+
const ThemeDecorator = (Story: () => JSX.Element, context: any) => {
44+
const theme = createTheme({
45+
palette: palettes[context.globals.palette],
46+
sizing: sizings[context.globals.sizing],
47+
typography: typographies[context.globals.typography]
48+
});
49+
return (
50+
<ThemeProvider theme={theme}>
51+
<Story/>
52+
</ThemeProvider>
53+
);
54+
};
55+
56+
export default ThemeDecorator;

.storybook/decorators/tockContextDecorator.js renamed to .storybook/decorators/TockContextDecorator.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react';
22

33
import TockProvider from '../../src/TockContext';
44

5-
const TockContextDecorator = story => (
6-
<TockProvider>
7-
{story()}
8-
</TockProvider>
5+
const TockContextDecorator = (Story: () => JSX.Element) => (
6+
<TockProvider>
7+
<Story/>
8+
</TockProvider>
99
);
1010

1111
export default TockContextDecorator;

.storybook/decorators/themeDecorator.js

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

.storybook/main.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { StorybookConfig } from '@storybook/react-webpack5';
2+
3+
const config: StorybookConfig = {
4+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5+
6+
addons: [
7+
'@storybook/addon-links',
8+
'@storybook/addon-essentials',
9+
'@storybook/addon-interactions',
10+
],
11+
12+
framework: {
13+
name: '@storybook/react-webpack5',
14+
options: {},
15+
},
16+
17+
docs: {
18+
autodocs: true,
19+
},
20+
21+
core: {
22+
builder: '@storybook/builder-webpack5'
23+
}
24+
};
25+
export default config;

.storybook/preview.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Preview } from '@storybook/react';
2+
import ThemeDecorator, {palettes, sizings, typographies} from './decorators/ThemeDecorator'
3+
import TockContextDecorator from "./decorators/TockContextDecorator";
4+
5+
const preview: Preview = {
6+
parameters: {
7+
actions: { argTypesRegex: '^on[A-Z].*' },
8+
controls: {
9+
matchers: {
10+
color: /(background|color)$/i,
11+
date: /Date$/,
12+
},
13+
},
14+
},
15+
decorators: [
16+
ThemeDecorator,
17+
TockContextDecorator,
18+
],
19+
globalTypes: {
20+
palette: {
21+
description: 'Global color palette for components',
22+
defaultValue: 'default',
23+
toolbar: {
24+
title: 'Palette',
25+
items: [...Object.keys(palettes)]
26+
}
27+
},
28+
sizing: {
29+
description: 'Global sizing for components',
30+
defaultValue: 'default',
31+
toolbar: {
32+
title: 'Sizing',
33+
items: [...Object.keys(sizings)]
34+
}
35+
},
36+
typography: {
37+
description: 'Global typography for components',
38+
defaultValue: 'default',
39+
toolbar: {
40+
title: 'Typography',
41+
items: [...Object.keys(typographies)]
42+
}
43+
},
44+
}
45+
};
46+
47+
export default preview;

.storybook/webpack.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module.exports = ({ config }) => {
22
config.module.rules.push({
33
test: /\.(ts|tsx)$/,
4-
use: [
5-
{
6-
loader: require.resolve('awesome-typescript-loader'),
7-
},
8-
],
94
});
105
config.resolve.extensions.push('.ts', '.tsx');
116
return config;

0 commit comments

Comments
 (0)