mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
feat(ui): add ViewContext so components can know where they are being rendered (user-linear view, editor-linear view, or editor-nodes view)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { createContext, memo, useContext } from 'react';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
type ViewType = 'user-linear' | 'editor-linear' | 'editor-nodes';
|
||||
|
||||
const ViewContext = createContext<ViewType | null>(null);
|
||||
|
||||
export const ViewContextProvider = memo((props: PropsWithChildren<{ viewType: ViewType }>) => {
|
||||
return <ViewContext.Provider value={props.viewType}>{props.children}</ViewContext.Provider>;
|
||||
});
|
||||
|
||||
ViewContextProvider.displayName = 'ViewContextProvider';
|
||||
|
||||
export const useViewContext = () => {
|
||||
const context = useContext(ViewContext);
|
||||
assert(context !== null, 'useViewContext must be used within a ViewContextProvider');
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user