OHIF with Cornerstone3D 2.0 (#4347)

This commit is contained in:
Alireza authored and GitHub committed 2024-11-06 07:15:27 -05:00
1 parent 8981a61b8c
commit 7ce7127d7c
803 files changed
+32760 -15893

No files matched your search

@@ -0,0 +1,38 @@
import * as React from 'react';
// https://github.com/reach/reach-ui/blob/dev/packages/utils/src/context.tsx
type ContextProvider<T> = React.FC<React.PropsWithChildren<T>>;
export function createContext<ContextValueType extends object | null>(
rootComponentName: string,
defaultContext?: ContextValueType
): [ContextProvider<ContextValueType>, (callerComponentName: string) => ContextValueType] {
const Ctx = React.createContext<ContextValueType | undefined>(defaultContext);
function Provider(props: React.PropsWithChildren<ContextValueType>) {
const { children, ...context } = props;
const value = React.useMemo(
() => context,
// eslint-disable-next-line react-hooks/exhaustive-deps
Object.values(context)
) as ContextValueType;
return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
}
function useContext(callerComponentName: string) {
const context = React.useContext(Ctx);
if (context) {
return context;
}
if (defaultContext) {
return defaultContext;
}
throw Error(
`${callerComponentName} must be rendered inside of a ${rootComponentName} component.`
);
}
Ctx.displayName = `${rootComponentName}Context`;
Provider.displayName = `${rootComponentName}Provider`;
return [Provider, useContext];
}