Skip to content

Commit aa32c02

Browse files
feat: add defaultOpen option to plugins (#245)
* feat: add defaultOpen option to plugins * ci: apply automated fixes * chore: docs update * fix utils * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent ed0efe5 commit aa32c02

File tree

14 files changed

+621
-24
lines changed

14 files changed

+621
-24
lines changed

.changeset/chubby-otters-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools': minor
3+
---
4+
5+
add defaultOpen to plugins

.changeset/some-adults-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-utils': patch
3+
---
4+
5+
extend the plugins to accept config

docs/config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"label": "Configuration",
2222
"to": "configuration"
2323
},
24+
{
25+
"label": "Plugin Configuration",
26+
"to": "plugin-configuration"
27+
},
2428
{
2529
"label": "Installation",
2630
"to": "installation"
@@ -148,4 +152,4 @@
148152
]
149153
}
150154
]
151-
}
155+
}

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ createRoot(document.getElementById('root')!).render(
112112
{
113113
name: 'TanStack Form',
114114
render: <FormDevtools />,
115+
defaultOpen: true,
115116
},
116117
]}
117118
/>

docs/plugin-configuration.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Plugin Configuration
3+
id: plugin-configuration
4+
---
5+
6+
7+
# Plugin Configuration
8+
9+
You can configure TanStack Devtools plugins by passing them as an array to the `plugins` prop of the `TanStackDevtools` component.
10+
11+
Each plugin can have the following configuration options:
12+
- `render` (required) - A React component that renders the plugin's UI
13+
- `defaultOpen` (optional) - A boolean that determines if the plugin panel is open by default (default: false).
14+
- `id` (optional) - A unique identifier for the plugin. If not provided, a random id will be generated.
15+
16+
Here's an example of how to configure plugins in the `TanStackDevtools` component:
17+
18+
```tsx
19+
import { TanStackDevtools } from '@tanstack/react-devtools'
20+
import { FormDevtools } from '@tanstack/react-form-devtools'
21+
22+
function App() {
23+
return (
24+
<>
25+
<YourApp />
26+
<TanStackDevtools
27+
plugins={[
28+
{
29+
name: 'TanStack Form',
30+
render: <FormDevtools />,
31+
defaultOpen: true,
32+
},
33+
]}
34+
/>
35+
</>
36+
)
37+
}
38+
```
39+
40+
## Default open
41+
42+
You can set a plugin to be open by default by setting the `defaultOpen` property to `true` when configuring the plugin. This will make the plugin panel open when the devtools are first loaded.
43+
44+
If you only have 1 plugin it will automatically be opened regardless of the `defaultOpen` setting.
45+
46+
The limit to open plugins is at 3 panels at a time. If more than 3 plugins are set to `defaultOpen: true`, only the first 3 will be opened.
47+
48+
This does not override the settings saved in localStorage. If you have previously opened the plugin panel, and selected some plugins to be open or closed, those settings will take precedence over the `defaultOpen` setting.

docs/quick-start.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ function App() {
6969
{
7070
name: 'TanStack Query',
7171
render: <ReactQueryDevtoolsPanel />,
72+
defaultOpen: true
7273
},
7374
{
7475
name: 'TanStack Router',
7576
render: <TanStackRouterDevtoolsPanel />,
77+
defaultOpen: false
7678
},
7779
]} />
7880
</QueryClientProvider>

packages/devtools-utils/src/react/plugin.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import type { JSX } from 'react'
22
import type { DevtoolsPanelProps } from './panel'
33

4-
export function createReactPlugin(
5-
name: string,
6-
Component: (props: DevtoolsPanelProps) => JSX.Element,
7-
) {
4+
export function createReactPlugin({
5+
Component,
6+
...config
7+
}: {
8+
name: string
9+
id?: string
10+
defaultOpen?: boolean
11+
Component: (props: DevtoolsPanelProps) => JSX.Element
12+
}) {
813
function Plugin() {
914
return {
10-
name: name,
15+
config,
1116
render: (_el: HTMLElement, theme: 'light' | 'dark') => (
1217
<Component theme={theme} />
1318
),
1419
}
1520
}
1621
function NoOpPlugin() {
1722
return {
18-
name: name,
23+
config,
1924
render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
2025
}
2126
}

packages/devtools-utils/src/solid/plugin.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
import type { JSX } from 'solid-js'
44
import type { DevtoolsPanelProps } from './panel'
55

6-
export function createSolidPlugin(
7-
name: string,
8-
Component: (props: DevtoolsPanelProps) => JSX.Element,
9-
) {
6+
export function createSolidPlugin({
7+
Component,
8+
...config
9+
}: {
10+
name: string
11+
id?: string
12+
defaultOpen?: boolean
13+
Component: (props: DevtoolsPanelProps) => JSX.Element
14+
}) {
1015
function Plugin() {
1116
return {
12-
name: name,
17+
...config,
1318
render: (_el: HTMLElement, theme: 'light' | 'dark') => {
1419
return <Component theme={theme} />
1520
},
1621
}
1722
}
1823
function NoOpPlugin() {
1924
return {
20-
name: name,
25+
...config,
2126
render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
2227
}
2328
}

0 commit comments

Comments
 (0)