Skip to content

Commit 771f588

Browse files
committed
🤖 fix: add manual theme toggle for storybook
1 parent bbf02f1 commit 771f588

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

.storybook/preview.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,37 @@ import React from "react";
22
import type { Preview } from "@storybook/react-vite";
33
import {
44
ThemeProvider,
5+
useTheme,
56
type ThemeMode,
67
} from "../src/browser/contexts/ThemeContext";
78
import "../src/browser/styles/globals.css";
89

10+
const ThemeToggle = () => {
11+
const { theme, toggleTheme } = useTheme();
12+
return (
13+
<button
14+
onClick={toggleTheme}
15+
style={{
16+
position: "fixed",
17+
bottom: "1rem",
18+
right: "1rem",
19+
zIndex: 9999,
20+
padding: "0.5rem 1rem",
21+
background: theme === "dark" ? "#f5f6f8" : "#1e1e1e",
22+
color: theme === "dark" ? "#1e1e1e" : "#f5f6f8",
23+
border: "1px solid #777",
24+
borderRadius: "4px",
25+
cursor: "pointer",
26+
fontFamily: "system-ui, sans-serif",
27+
fontSize: "12px",
28+
boxShadow: "0 2px 5px rgba(0,0,0,0.2)",
29+
}}
30+
>
31+
{theme === "dark" ? "☀️ Light" : "🌙 Dark"}
32+
</button>
33+
);
34+
};
35+
936
const preview: Preview = {
1037
globalTypes: {
1138
theme: {
@@ -27,6 +54,7 @@ const preview: Preview = {
2754
return (
2855
<ThemeProvider forcedTheme={mode}>
2956
<Story />
57+
{!mode && <ThemeToggle />}
3058
</ThemeProvider>
3159
);
3260
},

0 commit comments

Comments
 (0)