From ba792b9289e114af18e3785382ab4ba10bb75a46 Mon Sep 17 00:00:00 2001 From: Michael Puehringer Date: Wed, 16 Aug 2023 14:36:38 +0200 Subject: [PATCH] Add context to visyn view components --- src/views/visyn/demo/VisynDemoView.tsx | 5 +++++ src/views/visyn/interfaces.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/views/visyn/demo/VisynDemoView.tsx b/src/views/visyn/demo/VisynDemoView.tsx index 11011cfda..ffe7cbe24 100644 --- a/src/views/visyn/demo/VisynDemoView.tsx +++ b/src/views/visyn/demo/VisynDemoView.tsx @@ -150,6 +150,10 @@ export function VisynDemoViewHeader({ parameters, selection, onParametersChanged ); } +export function VisynDemoViewContext({ children }: DemoVisynViewPluginType['props']) { + return children; +} + export function createVisynDemoView(): DemoVisynViewPluginType['definition'] { return { viewType: 'simple', @@ -161,5 +165,6 @@ export function createVisynDemoView(): DemoVisynViewPluginType['definition'] { view: VisynDemoView, header: VisynDemoViewHeader, tab: VisynDemoViewSidebar, + context: VisynDemoViewContext, }; } diff --git a/src/views/visyn/interfaces.ts b/src/views/visyn/interfaces.ts index 48d8dd713..7cf581cf4 100644 --- a/src/views/visyn/interfaces.ts +++ b/src/views/visyn/interfaces.ts @@ -27,6 +27,10 @@ type VisynViewProps> = { * @param parameters New parameters. */ onParametersChanged(parameters: React.SetStateAction): void; + /** + * Children of this visyn view. This is used to pass the actual view component to the context component. + */ + children?: React.ReactNode; }; /** @@ -45,6 +49,10 @@ type VisynViewComponents = { * Optional side-tab component of this visyn view plugin. */ tab?: React.LazyExoticComponent> | React.ComponentType; + /** + * Optional context component of this visyn view plugin. This component wraps all of the above and allows to provide context values (i.e. via React.createContext). + */ + context?: React.LazyExoticComponent> | React.ComponentType; }; type BaseVisynViewDesc> = IBaseViewPluginDesc & { @@ -117,7 +125,7 @@ export interface DefineVisynViewPlugin< /** * Definition to be used as return value of the loader function of the module. */ - definition: Pick, 'viewType' | 'defaultParameters' | 'header' | 'view' | 'tab'>; + definition: Pick, 'viewType' | 'defaultParameters' | 'header' | 'view' | 'tab' | 'context'>; /** * Full plugin representing the loaded visyn view. */