Skip to content

Commit d11aaf9

Browse files
feat: extract theme provider (#386)
* feat: extract theme provider * chore: export type * chore: unify types * fix:lock
1 parent 63e505c commit d11aaf9

File tree

16 files changed

+42
-36
lines changed

16 files changed

+42
-36
lines changed

.changeset/cyan-times-marry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@tanstack/devtools-utils': minor
3+
'@tanstack/devtools-ui': patch
4+
---
5+
6+
Extract devtools-ui from devtools-utils to avoid theme miss-match

examples/solid/devtools-ui/src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { createEffect, createSignal } from 'solid-js'
22
import { render } from 'solid-js/web'
3-
43
import { JsonTree, ThemeContextProvider } from '@tanstack/devtools-ui'
54

5+
import type { TanStackDevtoolsTheme } from '@tanstack/devtools-ui'
6+
67
import './index.css'
78

89
const JsonTreeDate = {
@@ -20,7 +21,7 @@ const JsonTreePath = {
2021
const darkThemeMq = window.matchMedia('(prefers-color-scheme: dark)')
2122

2223
function App() {
23-
const [theme, setTheme] = createSignal<'light' | 'dark'>(
24+
const [theme, setTheme] = createSignal<TanStackDevtoolsTheme>(
2425
darkThemeMq.matches ? 'dark' : 'light',
2526
)
2627

packages/devtools-a11y/src/core/styles/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as goober from 'goober'
22
import { useTheme } from '@tanstack/devtools-ui'
33
import { createMemo } from 'solid-js'
44

5+
import type { TanStackDevtoolsTheme } from '@tanstack/devtools-ui'
56
import type { RuleCategory, SeverityThreshold } from '../types/types'
67

78
const SEVERITY_COLORS: Record<SeverityThreshold, string> = {
@@ -49,7 +50,7 @@ const css = goober.css
4950
const FONT_SCALE = 1.1
5051
const fontPx = (size: number) => `calc(${size}px * ${FONT_SCALE})`
5152

52-
function createA11yPanelStyles(theme: 'light' | 'dark') {
53+
function createA11yPanelStyles(theme: TanStackDevtoolsTheme) {
5354
const t = (light: string, dark: string) => (theme === 'light' ? light : dark)
5455

5556
const bg = t('#f9fafb;', '#191c24')

packages/devtools-ui/src/components/icons.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// import { Show, createUniqueId } from 'solid-js'
22

3+
import type { TanStackDevtoolsTheme } from './theme'
4+
35
/* export function Search() {
46
return (
57
<svg
@@ -39,7 +41,7 @@ export function Trash() {
3941
</svg>
4042
)
4143
} */
42-
/*
44+
/*
4345
export function ChevronDown() {
4446
return (
4547
<svg
@@ -466,7 +468,7 @@ export function Link() {
466468
</svg>
467469
)
468470
}
469-
/*
471+
/*
470472
471473
export function Pencil() {
472474
return (
@@ -696,7 +698,7 @@ export function PiP() {
696698
)
697699
}
698700

699-
export function CopiedCopier(props: { theme: 'light' | 'dark' }) {
701+
export function CopiedCopier(props: { theme: TanStackDevtoolsTheme }) {
700702
return (
701703
<svg
702704
width="24"
@@ -735,7 +737,7 @@ export function ErrorCopier() {
735737
</svg>
736738
)
737739
}
738-
/*
740+
/*
739741
export function List() {
740742
return (
741743
<svg
@@ -755,7 +757,7 @@ export function List() {
755757
)
756758
}
757759
758-
export function Check(props: { checked: boolean; theme: 'light' | 'dark' }) {
760+
export function Check(props: { checked: boolean; theme: TanStackDevtoolsTheme }) {
759761
return (
760762
<>
761763
<Show when={props.checked}>
@@ -884,7 +886,7 @@ export function PauseCircle() {
884886
</svg>
885887
)
886888
} */
887-
/*
889+
/*
888890
export function TanstackLogo() {
889891
const id = createUniqueId()
890892
return (

packages/devtools-ui/src/components/theme.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { createContext, createEffect, createSignal, useContext } from 'solid-js'
22
import type { Accessor, JSX } from 'solid-js'
33

4-
export type Theme = 'light' | 'dark'
4+
export type TanStackDevtoolsTheme = 'light' | 'dark'
55

66
type ThemeContextValue = {
7-
theme: Accessor<Theme>
8-
setTheme: (theme: Theme) => void
7+
theme: Accessor<TanStackDevtoolsTheme>
8+
setTheme: (theme: TanStackDevtoolsTheme) => void
99
}
1010
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined)
1111

1212
export const ThemeContextProvider = (props: {
1313
children: JSX.Element
14-
theme: Theme
14+
theme: TanStackDevtoolsTheme
1515
}) => {
16-
const [theme, setTheme] = createSignal<Theme>(props.theme)
16+
const [theme, setTheme] = createSignal<TanStackDevtoolsTheme>(props.theme)
1717
createEffect(() => {
1818
setTheme(props.theme)
1919
})

packages/devtools-ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
} from './components/section'
1515
export { Header, HeaderLogo } from './components/header'
1616
export { useTheme, ThemeContextProvider } from './components/theme'
17+
export type { TanStackDevtoolsTheme } from './components/theme'
1718
export {
1819
CheckCircleIcon,
1920
ChevronDownIcon,

packages/devtools-ui/src/styles/use-styles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as goober from 'goober'
22
import { createEffect, createSignal } from 'solid-js'
33
import { useTheme } from '../components/theme'
44
import { tokens } from './tokens'
5+
6+
import type { TanStackDevtoolsTheme } from '../components/theme'
57
import type { ButtonVariant } from '../components/button'
6-
import type { Theme } from '../components/theme'
78

89
const buttonVariantColors: Record<
910
ButtonVariant,
@@ -118,7 +119,7 @@ const buttonVariantColors: Record<
118119
},
119120
}
120121
export const css = goober.css
121-
const stylesFactory = (theme: Theme = 'dark') => {
122+
const stylesFactory = (theme: TanStackDevtoolsTheme) => {
122123
const { colors, font, size, border } = tokens
123124
const { fontFamily } = font
124125

packages/devtools-utils/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
"engines": {
7373
"node": ">=18"
7474
},
75-
"dependencies": {
76-
"@tanstack/devtools-ui": "workspace:^"
77-
},
7875
"devDependencies": {
7976
"@tanstack/devtools": "workspace:^",
8077
"tsup": "^8.5.0",

packages/devtools-utils/src/solid/class-mount-impl.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { lazy } from 'solid-js'
44
import { Portal, render } from 'solid-js/web'
5+
56
import type { JSX } from 'solid-js'
67
import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
78

@@ -13,19 +14,12 @@ export function __mountComponent(
1314
}>,
1415
): () => void {
1516
const Component = lazy(importFn)
16-
const ThemeProvider = lazy(() =>
17-
import('@tanstack/devtools-ui').then((m) => ({
18-
default: m.ThemeContextProvider,
19-
})),
20-
)
2117

2218
return render(
2319
() => (
2420
<Portal mount={el}>
2521
<div style={{ height: '100%' }}>
26-
<ThemeProvider theme={props.theme}>
27-
<Component {...props} />
28-
</ThemeProvider>
22+
<Component {...props} />
2923
</div>
3024
</Portal>
3125
),

packages/devtools/src/context/devtools-context.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {
1111
import { initialState } from './devtools-store'
1212
import type { DevtoolsStore } from './devtools-store'
1313
import type { JSX, Setter } from 'solid-js'
14+
import type { TanStackDevtoolsTheme } from '@tanstack/devtools-ui'
1415

1516
export interface TanStackDevtoolsPluginProps {
16-
theme: DevtoolsStore['settings']['theme']
17+
theme: TanStackDevtoolsTheme
1718
devtoolsOpen: boolean
1819
}
1920
export interface TanStackDevtoolsPlugin {

0 commit comments

Comments
 (0)