Use theme store to pass color_scheme directly to components

This commit is contained in:
Nate Butler
2023-07-04 00:13:04 -04:00
parent f8316dd127
commit d5acfe8fc1
36 changed files with 280 additions and 136 deletions
+21
View File
@@ -1,3 +1,24 @@
import { create } from "zustand"
import { ColorScheme } from "./color_scheme"
type ThemeState = {
theme: ColorScheme | undefined
setTheme: (theme: ColorScheme) => void
}
export const useThemeStore = create<ThemeState>((set) => ({
theme: undefined,
setTheme: (theme) => set(() => ({ theme })),
}))
export const useTheme = (): ColorScheme => {
const { theme } = useThemeStore.getState()
if (!theme) throw new Error("Tried to use theme before it was loaded")
return theme
}
export * from "./color_scheme"
export * from "./ramps"
export * from "./syntax"