Skip to content

Commit

Permalink
Add context to visyn view components
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Aug 16, 2023
1 parent 904cb14 commit ba792b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/views/visyn/demo/VisynDemoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -161,5 +165,6 @@ export function createVisynDemoView(): DemoVisynViewPluginType['definition'] {
view: VisynDemoView,
header: VisynDemoViewHeader,
tab: VisynDemoViewSidebar,
context: VisynDemoViewContext,
};
}
10 changes: 9 additions & 1 deletion src/views/visyn/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type VisynViewProps<Param extends Record<string, unknown>> = {
* @param parameters New parameters.
*/
onParametersChanged(parameters: React.SetStateAction<Param>): void;
/**
* Children of this visyn view. This is used to pass the actual view component to the context component.
*/
children?: React.ReactNode;
};

/**
Expand All @@ -45,6 +49,10 @@ type VisynViewComponents<Props extends object> = {
* Optional side-tab component of this visyn view plugin.
*/
tab?: React.LazyExoticComponent<React.ComponentType<Props>> | React.ComponentType<Props>;
/**
* 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<Props & { children: React.ReactNode }>> | React.ComponentType<Props & { children: React.ReactNode }>;
};

type BaseVisynViewDesc<Type extends string, Param extends Record<string, unknown>> = IBaseViewPluginDesc & {
Expand Down Expand Up @@ -117,7 +125,7 @@ export interface DefineVisynViewPlugin<
/**
* Definition to be used as return value of the loader function of the module.
*/
definition: Pick<VisynViewPluginBaseType<Type, Param, Props, Desc>, 'viewType' | 'defaultParameters' | 'header' | 'view' | 'tab'>;
definition: Pick<VisynViewPluginBaseType<Type, Param, Props, Desc>, 'viewType' | 'defaultParameters' | 'header' | 'view' | 'tab' | 'context'>;
/**
* Full plugin representing the loaded visyn view.
*/
Expand Down

0 comments on commit ba792b9

Please sign in to comment.