Skip to content

Commit b320be3

Browse files
committed
fix: move storybook theme provider out of themeprovider.tsx
1 parent a88fd3c commit b320be3

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

.storybook/preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { StorybookThemeProvider } from "../src/components/ThemeProvider";
2+
import { StorybookThemeProvider } from "../src/stories/ThemeUtility";
33
import type { Preview } from "@storybook/react";
44
import {
55
ThemeDefaultBackground,

src/components/ThemeProvider.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ export const ThemeProvider = (props: {
6262
);
6363
};
6464

65-
export const StorybookThemeProvider = (props: {
66-
children: React.ReactNode;
67-
theme?: PartialDeep<Theme>;
68-
}) => {
69-
const { children, theme: providedTheme } = props;
70-
const darkMode = useDarkMode(false);
71-
const theme = providedTheme ?? defaultTheme;
72-
return (
73-
<StyledThemeProvider theme={darkMode.value ? theme.dark : theme.light}>
74-
{children}
75-
</StyledThemeProvider>
76-
);
77-
};
78-
7965
export const getThemeValue = (key: keyof Palette) => {
8066
try {
8167
const darkMode = useDarkMode(false);

src/stories/ThemeUtility.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
import React from "react";
22
import useDarkMode from "use-dark-mode";
33
import styled from "styled-components";
4+
import { PartialDeep } from "type-fest";
5+
import { ThemeProvider as StyledThemeProvider } from "styled-components";
6+
import { defaultTheme, Theme } from "../components/ThemeProvider";
7+
8+
export const StorybookThemeProvider = (props: {
9+
children: React.ReactNode;
10+
theme?: PartialDeep<Theme>;
11+
}) => {
12+
const { children, theme: providedTheme } = props;
13+
const darkMode = useDarkMode(false);
14+
const theme = providedTheme ?? defaultTheme;
15+
return (
16+
<StyledThemeProvider theme={darkMode.value ? theme.dark : theme.light}>
17+
{children}
18+
</StyledThemeProvider>
19+
);
20+
};
421

522
export const ToggleThemeButton = () => {
623
const { value, toggle } = useDarkMode(false);

0 commit comments

Comments
 (0)