Skip to content

Commit a61a41c

Browse files
authored
chore: update storybook (#244)
1 parent b8bae21 commit a61a41c

File tree

19 files changed

+2902
-3670
lines changed

19 files changed

+2902
-3670
lines changed

.storybook/main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type {StorybookConfig} from '@storybook/react-webpack5';
1+
import {defineMain} from '@storybook/react-webpack5/node';
22
import * as sass from 'sass';
33

4-
const config: StorybookConfig = {
4+
export default defineMain({
55
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(ts|tsx)'],
66
addons: [
77
'@storybook/addon-docs',
88
'@storybook/addon-a11y',
9-
'./theme-addon/register.tsx',
9+
import.meta.resolve('./theme-addon/theme-preset.ts'),
1010
'@storybook/addon-webpack5-compiler-babel',
1111
{
1212
name: '@storybook/addon-styling-webpack',
@@ -59,6 +59,4 @@ const config: StorybookConfig = {
5959
['@babel/preset-react', {runtime: 'automatic'}],
6060
],
6161
},
62-
};
63-
64-
export default config;
62+
});

.storybook/preview.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import React from 'react';
88
import {settings} from '@gravity-ui/date-utils';
99
import {MobileProvider, ThemeProvider, ToasterComponent, ToasterProvider} from '@gravity-ui/uikit';
1010
import {toaster} from '@gravity-ui/uikit/toaster-singleton';
11-
import type {Decorator, Preview} from '@storybook/react-webpack5';
11+
import addonDocs from '@storybook/addon-docs';
12+
import type {Decorator} from '@storybook/react-webpack5';
13+
import {definePreview} from '@storybook/react-webpack5';
1214
import {MINIMAL_VIEWPORTS} from 'storybook/viewport';
1315

1416
import {DocsDecorator} from '../src/demo/DocsDecorator/DocsDecorator';
@@ -36,7 +38,8 @@ const WithContextProvider: Decorator = (Story, context) => {
3638
);
3739
};
3840

39-
const preview: Preview = {
41+
export default definePreview({
42+
addons: [addonDocs()],
4043
parameters: {
4144
docs: {
4245
theme: themes.light,
@@ -45,7 +48,7 @@ const preview: Preview = {
4548
},
4649
jsx: {showFunctions: false}, // Do not show functions in sources
4750
viewport: {
48-
viewports: MINIMAL_VIEWPORTS,
51+
options: MINIMAL_VIEWPORTS,
4952
},
5053
options: {
5154
storySort: {
@@ -107,6 +110,4 @@ const preview: Preview = {
107110
direction: 'ltr',
108111
platform: 'desktop',
109112
},
110-
};
111-
112-
export default preview;
113+
});

.storybook/theme-addon/register.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
3+
import {addons, types, useGlobals} from 'storybook/manager-api';
4+
5+
import {themes} from '../theme.js';
6+
7+
const ADDON_ID = 'gravity-theme-addon';
8+
const TOOL_ID = `${ADDON_ID}tool`;
9+
10+
addons.register(ADDON_ID, (api) => {
11+
addons.add(TOOL_ID, {
12+
type: types.TOOL,
13+
title: 'Theme',
14+
render: function Tool() {
15+
const [{theme = 'light'}] = useGlobals();
16+
17+
React.useEffect(() => {
18+
api.setOptions({theme: themes[theme.includes('dark') ? 'dark' : 'light']});
19+
}, [theme]);
20+
21+
return null;
22+
},
23+
});
24+
});

.storybook/theme-addon/register.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {fileURLToPath} from 'node:url';
2+
3+
export function managerEntries(entry = []) {
4+
return [...entry, fileURLToPath(import.meta.resolve('./register.js'))];
5+
}

.storybook/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {create} from 'storybook/theming';
22
import type {ThemeVarsPartial} from 'storybook/theming';
33

4-
import pkg from '../package.json';
4+
import pkg from '../package.json' with {type: 'json'};
55

66
function renderBrandTitle(theme: 'light' | 'dark') {
77
const titleColor = theme === 'light' ? 'rgba(0, 0, 0, 0.85)' : 'rgba(255, 255, 255, 0.85)';

0 commit comments

Comments
 (0)