Skip to content

Commit 59ecdb6

Browse files
Feat/theme toggle (#96)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 21d73ef commit 59ecdb6

File tree

14 files changed

+297
-181
lines changed

14 files changed

+297
-181
lines changed

.changeset/open-ravens-brake.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@tanstack/react-devtools': minor
3+
'@tanstack/solid-devtools': minor
4+
'@tanstack/devtools-ui': patch
5+
'@tanstack/devtools': patch
6+
---
7+
8+
added support for dark/light mode

packages/devtools-ui/src/components/main-panel.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ export const MainPanel = ({
1515
withPadding,
1616
}: PanelProps) => {
1717
const styles = useStyles()
18+
1819
return (
1920
<div
20-
class={clsx(styles().mainPanel.panel, className, classStyles, {
21-
[styles().mainPanel.withPadding]: withPadding,
22-
})}
21+
class={clsx(
22+
styles().mainPanel.panel(Boolean(withPadding)),
23+
className,
24+
classStyles,
25+
)}
2326
>
2427
{children}
2528
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createContext, createEffect, createSignal, useContext } from 'solid-js'
2+
import type { Accessor, JSX } from 'solid-js'
3+
4+
export type Theme = 'light' | 'dark'
5+
6+
type ThemeContextValue = {
7+
theme: Accessor<Theme>
8+
setTheme: (theme: Theme) => void
9+
}
10+
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined)
11+
12+
export const ThemeContextProvider = (props: {
13+
children: JSX.Element
14+
theme: Theme
15+
}) => {
16+
const [theme, setTheme] = createSignal<Theme>(props.theme)
17+
createEffect(() => {
18+
setTheme(props.theme)
19+
})
20+
return (
21+
<ThemeContext.Provider value={{ theme, setTheme }}>
22+
{props.children}
23+
</ThemeContext.Provider>
24+
)
25+
}
26+
27+
export function useTheme() {
28+
const context = useContext(ThemeContext)
29+
if (!context) {
30+
throw new Error('useTheme must be used within a ThemeContextProvider')
31+
}
32+
33+
return context
34+
}

packages/devtools-ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export {
1313
SectionIcon,
1414
} from './components/section'
1515
export { Header, HeaderLogo } from './components/header'
16+
export { useTheme, ThemeContextProvider } from './components/theme'

0 commit comments

Comments
 (0)