Skip to content

Commit

Permalink
use official storybook themes addon to apply themes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvllmr committed Jul 24, 2024
1 parent 7094aa1 commit 5d4dacd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
8 changes: 6 additions & 2 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: StorybookConfig = {
addons: [
"@storybook/addon-interactions",
"storybook-dark-mode",
"storybook-addon-mantine",

{
name: "@storybook/addon-storysource",
options: {
Expand All @@ -30,7 +30,11 @@ const config: StorybookConfig = {
},
},
},
"@storybook/addon-essentials",
{
name: "@storybook/addon-essentials",
options: { docs: false, backgrounds: false },
},
"@storybook/addon-themes",
],
framework: {
name: "@storybook/react-vite",
Expand Down
18 changes: 9 additions & 9 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import {
DEFAULT_THEME,
MantineProvider,
MantineTheme,
MantineThemeProvider,
useMantineColorScheme,
} from "@mantine/core";
import "@mantine/core/styles.css";
import "@mantine/core/styles.layer.css";
import "@mantine/dates/styles.layer.css";
import { withThemeFromJSXProvider } from "@storybook/addon-themes";
import { addons } from "@storybook/preview-api";
import type { Preview } from "@storybook/react";
import type { Preview, ReactRenderer } from "@storybook/react";
import { useEffect } from "react";
import { withMantineThemes } from "storybook-addon-mantine";
import { DARK_MODE_EVENT_NAME } from "storybook-dark-mode";

const allColorThemes: MantineTheme[] = Object.keys(DEFAULT_THEME.colors)
.sort()
.map((primaryColor) => ({ ...DEFAULT_THEME, primaryColor }));
Expand Down Expand Up @@ -48,12 +48,12 @@ const preview: Preview = {
</MantineProvider>
);
},
withMantineThemes({
themes: allColorThemes.map((theme) => ({
id: theme.primaryColor,
name: `Color: ${theme.primaryColor}`,
...theme,
})),
withThemeFromJSXProvider<ReactRenderer>({
defaultTheme: "blue",
Provider: MantineThemeProvider,
themes: Object.fromEntries(
allColorThemes.map((theme) => [theme.primaryColor, theme]),
),
}),
],
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@storybook/addon-essentials": "^8.2.6",
"@storybook/addon-interactions": "^8.2.6",
"@storybook/addon-storysource": "^8.2.6",
"@storybook/addon-themes": "^8.2.6",
"@storybook/blocks": "^8.2.6",
"@storybook/preview-api": "^8.2.6",
"@storybook/react": "^8.2.6",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d4dacd

Please sign in to comment.