-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy paththeme.tsx
More file actions
34 lines (29 loc) · 936 Bytes
/
theme.tsx
File metadata and controls
34 lines (29 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createContext, createEffect, createSignal, useContext } from 'solid-js'
import type { Accessor, JSX } from 'solid-js'
export type TanStackDevtoolsTheme = 'light' | 'dark'
type ThemeContextValue = {
theme: Accessor<TanStackDevtoolsTheme>
setTheme: (theme: TanStackDevtoolsTheme) => void
}
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined)
export const ThemeContextProvider = (props: {
children: JSX.Element
theme: TanStackDevtoolsTheme
}) => {
const [theme, setTheme] = createSignal<TanStackDevtoolsTheme>(props.theme)
createEffect(() => {
setTheme(props.theme)
})
return (
<ThemeContext.Provider value={{ theme, setTheme }}>
{props.children}
</ThemeContext.Provider>
)
}
export function useTheme() {
const context = useContext(ThemeContext)
if (!context) {
throw new Error('useTheme must be used within a ThemeContextProvider')
}
return context
}