Skip to content

Commit 54699a4

Browse files
committed
🤖 refactor(storybook): remove manual theme toggle button
Removes the floating StorybookThemeToggle button that was added as a workaround. The native Storybook toolbar already provides a theme switcher via the globalTypes configuration. This simplifies the code by removing: - StorybookThemeToggle component (40 lines) - isE2ETestEnv() utility (7 lines) - Conditional rendering logic in decorator (3 lines) Users can now toggle themes using the standard Storybook toolbar (mirror icon at the top), which provides a cleaner, more consistent UX. Net: -52 lines
1 parent 8665a58 commit 54699a4

File tree

1 file changed

+1
-52
lines changed

1 file changed

+1
-52
lines changed

.storybook/preview.tsx

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import type { Preview } from "@storybook/react-vite";
33
import { ThemeProvider, type ThemeMode } from "../src/browser/contexts/ThemeContext";
44
import { getStorageChangeEvent } from "@/common/constants/events";
55
import { UI_THEME_KEY } from "@/common/constants/storage";
6-
7-
// Utility: detect e2e/test contexts where UI should be hidden (Chromatic, SB test-runner)
8-
const isE2ETestEnv = () => {
9-
if (typeof window !== "undefined" && (window as any).CHROMATIC) return true;
10-
if (typeof navigator !== "undefined" && /StorybookTestRunner/i.test(navigator.userAgent)) return true;
11-
return false;
12-
};
136
import "../src/browser/styles/globals.css";
147

158
const applyStorybookTheme = (mode: ThemeMode) => {
@@ -51,47 +44,6 @@ const syncStorybookTheme = (mode?: ThemeMode): ThemeMode => {
5144
return resolved;
5245
};
5346

54-
const StorybookThemeToggle: React.FC<{ initialTheme: ThemeMode }> = ({ initialTheme }) => {
55-
const [theme, setTheme] = React.useState(initialTheme);
56-
57-
React.useEffect(() => {
58-
setTheme(initialTheme);
59-
}, [initialTheme]);
60-
61-
const handleToggle = () => {
62-
const next = theme === "dark" ? "light" : "dark";
63-
applyStorybookTheme(next);
64-
setTheme(next);
65-
};
66-
67-
if (typeof window === "undefined") {
68-
return null;
69-
}
70-
71-
return (
72-
<button
73-
onClick={handleToggle}
74-
style={{
75-
position: "fixed",
76-
bottom: "1rem",
77-
right: "1rem",
78-
zIndex: 9999,
79-
padding: "0.5rem 1rem",
80-
background: theme === "dark" ? "#f5f6f8" : "#1e1e1e",
81-
color: theme === "dark" ? "#1e1e1e" : "#f5f6f8",
82-
border: "1px solid #777",
83-
borderRadius: "4px",
84-
cursor: "pointer",
85-
fontFamily: "system-ui, sans-serif",
86-
fontSize: "12px",
87-
boxShadow: "0 2px 5px rgba(0,0,0,0.2)",
88-
}}
89-
>
90-
{theme === "dark" ? "☀️ Light" : "🌙 Dark"}
91-
</button>
92-
);
93-
};
94-
9547
const preview: Preview = {
9648
globalTypes: {
9749
theme: {
@@ -110,13 +62,10 @@ const preview: Preview = {
11062
decorators: [
11163
(Story, context) => {
11264
const mode = context.globals.theme as ThemeMode | undefined;
113-
const resolved = syncStorybookTheme(mode);
65+
syncStorybookTheme(mode);
11466
return (
11567
<ThemeProvider>
11668
<Story />
117-
{!mode && !isE2ETestEnv() && (
118-
<StorybookThemeToggle initialTheme={resolved} />
119-
)}
12069
</ThemeProvider>
12170
);
12271
},

0 commit comments

Comments
 (0)