-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathTanStackRouterDevtoolsPanel.tsx
More file actions
87 lines (77 loc) · 2.2 KB
/
TanStackRouterDevtoolsPanel.tsx
File metadata and controls
87 lines (77 loc) · 2.2 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { useRouter, useRouterState } from '@tanstack/solid-router'
import { TanStackRouterDevtoolsPanelCore } from '@tanstack/router-devtools-core'
import { createEffect, createSignal, onCleanup, onMount } from 'solid-js'
import type { AnyRouter } from '@tanstack/solid-router'
import type { Component, JSX } from 'solid-js'
export interface TanStackRouterDevtoolsPanelOptions {
/**
* The standard React style object used to style a component with inline styles
*/
style?: JSX.CSSProperties
/**
* The standard React class property used to style a component with classes
*/
className?: string
/**
* A boolean variable indicating whether the panel is open or closed
*/
isOpen?: boolean
/**
* A function that toggles the open and close state of the panel
*/
setIsOpen?: (isOpen: boolean) => void
/**
* Handles the opening and closing the devtools panel
*/
handleDragStart?: (e: any) => void
/**
* A boolean variable indicating if the "lite" version of the library is being used
*/
router?: AnyRouter
/**
* Use this to attach the devtool's styles to specific element in the DOM.
*/
shadowDOMTarget?: ShadowRoot
}
export const TanStackRouterDevtoolsPanel: Component<
TanStackRouterDevtoolsPanelOptions
> = (props): JSX.Element | null => {
const activeRouter = props.router ?? useRouter()
const activeRouterState = useRouterState({ router: activeRouter })
const usedProps = {
...props,
router: activeRouter,
routerState: activeRouterState,
}
let devToolRef: HTMLDivElement | undefined
const [devtools] = createSignal(
new TanStackRouterDevtoolsPanelCore(usedProps),
)
// Update devtools when props change
createEffect(() => {
devtools().setRouter(usedProps.router)
})
createEffect(() => {
devtools().setRouterState(usedProps.routerState)
})
createEffect(() => {
devtools().setOptions({
className: usedProps.className,
style: usedProps.style,
shadowDOMTarget: usedProps.shadowDOMTarget,
})
})
onMount(() => {
if (devToolRef) {
devtools().mount(devToolRef)
onCleanup(() => {
devtools().unmount()
})
}
})
return (
<>
<div ref={devToolRef} />
</>
)
}