-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] experiment: Adds dark mode decorator for all stories (#16670)
- Loading branch information
1 parent
11d32be
commit aef571f
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<html class="bg-slate-800"> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { routerDecorator } from "./router-decorator"; | ||
export { reactQueryDecorator } from "./react-query-decorator"; | ||
export { toastDecorator } from "./toast-decorator"; | ||
export { ModeDecorator } from "./mode-decorator"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Label } from "@/components/ui/label"; | ||
import { Switch } from "@/components/ui/switch"; | ||
import { StoryFn } from "@storybook/react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export const ModeDecorator = (Story: StoryFn) => { | ||
const [isDarkMode, setIsDarkMode] = useState(false); | ||
const toggleMode = () => { | ||
setIsDarkMode((curr) => !curr); | ||
}; | ||
|
||
// sync external css with state | ||
useEffect(() => { | ||
document.documentElement.classList.toggle("dark", isDarkMode); | ||
}, [isDarkMode]); | ||
|
||
return ( | ||
<> | ||
<div className="absolute bottom-4 left-4 z-50"> | ||
<div className="flex items-center space-x-2"> | ||
<Switch id="theme-mode" checked={isDarkMode} onClick={toggleMode} /> | ||
<Label htmlFor="theme-mode"> | ||
{isDarkMode ? "Light Mode" : "Dark Mode (experimental)"} | ||
</Label> | ||
</div> | ||
</div> | ||
{/** @ts-expect-error Error typing from React 19 types upgrade. Will need to wait for this up be updated */} | ||
<Story /> | ||
</> | ||
); | ||
}; |