Skip to content

Commit 7223846

Browse files
committed
add plugin utility
1 parent 3a5c518 commit 7223846

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './panel'
2+
export * from './plugin'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { JSX } from "react"
2+
import type { DevtoolsPanelProps } from "./panel"
3+
4+
export function createReactPlugin(name: string, Component: (props: DevtoolsPanelProps) => JSX.Element) {
5+
function Plugin() {
6+
return {
7+
name: name,
8+
render: (_el: HTMLElement, theme: 'light' | 'dark') => <Component theme={theme} />,
9+
}
10+
}
11+
function NoOpPlugin() {
12+
return {
13+
name: name,
14+
render: (_el: HTMLElement, _theme: 'light' | 'dark') => null,
15+
}
16+
}
17+
return [Plugin, NoOpPlugin] as const
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './class'
22
export * from './panel'
3+
export * from "./plugin"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @jsxImportSource solid-js - we use Solid.js as JSX here */
2+
3+
import type { JSX } from "solid-js";
4+
import type { DevtoolsPanelProps } from "./panel";
5+
6+
export function createSolidPlugin(name: string, Component: (props: DevtoolsPanelProps) => JSX.Element) {
7+
function Plugin() {
8+
return {
9+
name: name,
10+
render: (_el: HTMLElement, theme: 'light' | 'dark') => {
11+
return <Component theme={theme} />;
12+
},
13+
}
14+
}
15+
function NoOpPlugin() {
16+
return {
17+
name: name,
18+
render: (_el: HTMLElement, _theme: 'light' | 'dark') => null,
19+
}
20+
}
21+
return [Plugin, NoOpPlugin] as const
22+
}

0 commit comments

Comments
 (0)