chore: storybook (#15285)
Co-authored-by: David Hill <iamdavidhill@gmail.com>
This commit is contained in:
21
packages/storybook/.storybook/theme-tool.ts
Normal file
21
packages/storybook/.storybook/theme-tool.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createElement } from "react"
|
||||
import { useGlobals } from "storybook/manager-api"
|
||||
import { ToggleButton } from "storybook/internal/components"
|
||||
|
||||
export function ThemeTool() {
|
||||
const [globals, updateGlobals] = useGlobals()
|
||||
const mode = globals.theme === "dark" ? "dark" : "light"
|
||||
const toggle = () => {
|
||||
const next = mode === "dark" ? "light" : "dark"
|
||||
updateGlobals({ theme: next })
|
||||
}
|
||||
return createElement(
|
||||
ToggleButton,
|
||||
{
|
||||
title: "Toggle theme",
|
||||
active: mode === "dark",
|
||||
onClick: toggle,
|
||||
},
|
||||
mode === "dark" ? "Dark" : "Light",
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user