Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add context to visyn view components #79

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>> | React.ComponentType<Props>;
};

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
Loading