Skip to content

Commit 3676660

Browse files
committed
docs: add theme switch to Storybook
1 parent 466d37b commit 3676660

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.storybook/preview.tsx

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
import React from 'react';
12
import { Preview } from '@storybook/react';
23
import { themes } from '@storybook/theming';
3-
import React from 'react';
4-
import { RedesignedColors } from '../src/essentials/Colors/globalStyles';
4+
import { ClassicColors, ModernColors } from '../src/essentials/Colors/globalStyles';
5+
6+
const THEMES = {
7+
classic: ClassicColors,
8+
modern: ModernColors
9+
} as const;
10+
11+
export const withTheme = (Story, context) => {
12+
const Theme = THEMES[context.globals.theme];
13+
return (
14+
<>
15+
<Theme />
16+
<Story {...context} />
17+
</>
18+
);
19+
};
520

621
export const preview: Preview = {
7-
decorators: [
8-
Story => (
9-
<>
10-
<RedesignedColors />
11-
<Story />
12-
</>
13-
)
14-
],
22+
decorators: [withTheme],
1523
parameters: {
1624
actions: { argTypesRegex: '^on[A-Z].*' },
1725
viewMode: 'docs',
@@ -22,6 +30,11 @@ export const preview: Preview = {
2230
date: /Date$/
2331
}
2432
},
33+
options: {
34+
storySort: {
35+
order: ['Welcome', 'Get Started', 'Essentials', 'Components', 'Form Elements']
36+
}
37+
},
2538
docs: {
2639
theme: themes.light
2740
},
@@ -75,10 +88,17 @@ export const preview: Preview = {
7588
type: 'desktop'
7689
}
7790
}
78-
},
79-
options: {
80-
storySort: {
81-
order: ['Welcome', 'Get Started', 'Essentials', 'Components', 'Form Elements']
91+
}
92+
},
93+
globalTypes: {
94+
theme: {
95+
description: 'Global theme for components',
96+
defaultValue: 'modern',
97+
toolbar: {
98+
title: 'Theme',
99+
icon: 'paintbrush',
100+
items: ['modern', 'classic'],
101+
dynamicTitle: true
82102
}
83103
}
84104
}

0 commit comments

Comments
 (0)