feat(tui): add plugin context hook
This commit is contained in:
parent
771174b5c3
commit
5bcc0016a6
16 changed files with 216 additions and 148 deletions
|
|
@ -1 +1,2 @@
|
|||
export * as Plugin from "./plugin.js"
|
||||
export { PluginContextProvider, usePlugin } from "./solid.js"
|
||||
|
|
|
|||
19
packages/plugin/src/tui/solid.ts
Normal file
19
packages/plugin/src/tui/solid.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { createComponent, createContext, useContext, type JSX } from "solid-js"
|
||||
import type { Context } from "./context.js"
|
||||
|
||||
const PluginContext = createContext<Context>()
|
||||
|
||||
export function PluginContextProvider(props: { readonly value: Context; readonly children: JSX.Element }) {
|
||||
return createComponent(PluginContext.Provider, {
|
||||
value: props.value,
|
||||
get children() {
|
||||
return props.children
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function usePlugin() {
|
||||
const context = useContext(PluginContext)
|
||||
if (!context) throw new Error("PluginContextProvider is missing")
|
||||
return context
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue