44 * MIT License
55 */
66
7+ import React , { createContext , useContext } from 'react' ;
78import { BaseStyles , ThemeProvider } from '@primer/react' ;
89import { Colormode , JupyterLabCss , jupyterLabTheme } from '../theme' ;
910
@@ -19,6 +20,22 @@ import '@primer/primitives/dist/css/functional/size/size.css';
1920import '@primer/primitives/dist/css/functional/size/viewport.css' ;
2021import '@primer/primitives/dist/css/functional/typography/typography.css' ;
2122
23+ // Create context for colormode
24+ const JupyterReactColormodeContext = createContext < Colormode | undefined > (
25+ undefined
26+ ) ;
27+
28+ // Hook to access the colormode from the context
29+ export function useJupyterReactColormode ( ) : Colormode {
30+ const colormode = useContext ( JupyterReactColormodeContext ) ;
31+ if ( colormode === undefined ) {
32+ throw new Error (
33+ 'useJupyterReactColormode must be used within a JupyterReactTheme provider'
34+ ) ;
35+ }
36+ return colormode ;
37+ }
38+
2239type IJupyterLabThemeProps = {
2340 colormode ?: Colormode ;
2441 loadJupyterLabCss ?: boolean ;
@@ -35,7 +52,7 @@ export function JupyterReactTheme(
3552 theme = jupyterLabTheme ,
3653 } = props ;
3754 return (
38- < >
55+ < JupyterReactColormodeContext . Provider value = { colormode } >
3956 { loadJupyterLabCss && < JupyterLabCss colormode = { colormode } /> }
4057 < ThemeProvider
4158 theme = { theme }
@@ -53,7 +70,7 @@ export function JupyterReactTheme(
5370 { children }
5471 </ BaseStyles >
5572 </ ThemeProvider >
56- </ >
73+ </ JupyterReactColormodeContext . Provider >
5774 ) ;
5875}
5976
0 commit comments