Skip to content

Commit 624ff62

Browse files
authored
Merge pull request #402 from datalayer/fix/css-primer
enh: better theme support
1 parent b1e4bef commit 624ff62

File tree

9 files changed

+36
-15
lines changed

9 files changed

+36
-15
lines changed

packages/lexical/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
"dependencies": {
6464
"@datalayer/icons-react": "^1.0.0",
65-
"@datalayer/jupyter-react": "^1.1.4",
65+
"@datalayer/jupyter-react": "^1.1.5",
6666
"@datalayer/primer-addons": "^1.0.3",
6767
"@jupyterlab/application": "^4.0.0",
6868
"@jupyterlab/coreutils": "^6.0.0",

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datalayer/jupyter-react",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Jupyter React - React.js components 100% compatible with Jupyter.",
55
"license": "MIT",
66
"main": "lib/index.js",

packages/react/src/components/jupyterlab/JupyterLabAppAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class JupyterLabAppAdapter {
4242
this._ready = new Promise((resolve, _) => {
4343
this._readyResolve = resolve;
4444
});
45-
this._plugins = (this._jupyterLab as any)['_plugins'];
45+
this._plugins = (this._jupyterLab as any)['pluginRegistry']['_plugins'];
4646
this._readyResolve();
4747
return;
4848
}

packages/react/src/components/notebook/cell/sidebar/CellSidebarExtension.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import type { CommandRegistry } from '@lumino/commands';
1313
import type { IDisposable } from '@lumino/disposable';
1414
import type { PanelLayout, Widget } from '@lumino/widgets';
1515
import { Signal } from '@lumino/signaling';
16-
import { JupyterReactTheme, Colormode } from '../../../../theme';
1716
import { CellSidebar, type ICellSidebarProps } from './CellSidebar';
1817
import {
1918
NotebookExtension,
2019
INotebookExtensionProps,
2120
} from '../../NotebookExtensions';
21+
import { JupyterReactTheme, Colormode } from '../../../../theme';
2222

2323
class CellSidebarFactory implements IDisposable {
2424
private _isDisposed = false;
@@ -54,7 +54,6 @@ class CellSidebarFactory implements IDisposable {
5454
if (this._isDisposed) {
5555
return;
5656
}
57-
5857
this._isDisposed = true;
5958
this.panel.content.model?.cells.changed.disconnect(
6059
this._onCellsChanged,

packages/react/src/examples/NotebookThemeColormode.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import {
1515
Notebook2,
1616
NotebookToolbar,
1717
} from '../components';
18-
import { jupyterLabTheme, JupyterReactTheme, Colormode } from '../theme';
18+
import { useJupyterReactStore } from '../state';
19+
import { jupyterLabTheme, JupyterReactTheme } from '../theme';
1920

2021
import nbformat from './notebooks/NotebookExample1.ipynb.json';
2122

2223
const NotebookThemeColormode = () => {
2324
const { serviceManager } = useJupyter();
25+
const { colormode, setColormode } = useJupyterReactStore();
2426
const [theme, setTheme] = useState<any>(jupyterLabTheme);
2527
const [isThemeOn, setIsThemeOn] = useState(false);
26-
const [colormode, setColormode] = useState<Colormode>('light');
2728
const [isOn, setIsOn] = useState(false);
2829
const extensions = useMemo(
2930
() => [new CellSidebarExtension({ colormode })],

packages/react/src/state/JupyterReactState.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
terminalStore,
3535
TerminalState,
3636
} from '../components/terminal/TerminalState';
37+
import { Colormode } from '../theme';
3738

3839
export type OnSessionConnection = (
3940
kernelConnection: Session.ISessionConnection | undefined
@@ -54,9 +55,11 @@ export type JupyterReactState = {
5455
serviceManager?: ServiceManager.IManager;
5556
terminalStore: TerminalState;
5657
version: string;
58+
colormode: Colormode;
5759
setJupyterConfig: (configuration?: IJupyterConfig) => void;
5860
setServiceManager: (serviceManager?: ServiceManager.IManager) => void;
5961
setVersion: (version: string) => void;
62+
setColormode: (colormode: Colormode) => void;
6063
};
6164

6265
export const jupyterReactStore = createStore<JupyterReactState>((set, get) => ({
@@ -72,6 +75,7 @@ export const jupyterReactStore = createStore<JupyterReactState>((set, get) => ({
7275
notebookStore: notebookStore.getState(),
7376
outputStore: outputsStore.getState(),
7477
terminalStore: terminalStore.getState(),
78+
colormode: 'light',
7579
setJupyterConfig: (jupyterConfig?: IJupyterConfig) => {
7680
set(state => ({ jupyterConfig }));
7781
},
@@ -83,6 +87,9 @@ export const jupyterReactStore = createStore<JupyterReactState>((set, get) => ({
8387
set(state => ({ version }));
8488
}
8589
},
90+
setColormode: colormode => {
91+
set(state => ({ colormode }));
92+
},
8693
}));
8794

8895
// TODO Reuse code portions from JupyterContext.

packages/react/src/theme/JupyterReactTheme.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* MIT License
55
*/
66

7-
import React, { createContext, useContext } from 'react';
7+
import React, { createContext, useContext, useEffect, useState } from 'react';
88
import { BaseStyles, ThemeProvider } from '@primer/react';
99
import { Colormode, JupyterLabCss, jupyterLabTheme } from '../theme';
10+
import { useJupyterReactStore } from '../state';
1011

1112
import '@primer/primitives/dist/css/functional/themes/light.css';
1213
import '@primer/primitives/dist/css/functional/themes/dark.css';
@@ -47,10 +48,18 @@ export function JupyterReactTheme(
4748
): JSX.Element {
4849
const {
4950
children,
50-
colormode = 'light',
51+
colormode: colormodeProps = 'light',
5152
loadJupyterLabCss = true,
5253
theme = jupyterLabTheme,
5354
} = props;
55+
const [colormode, setColormode] = useState<Colormode>(colormodeProps);
56+
const { colormode: colormodeFromStore } = useJupyterReactStore();
57+
useEffect(() => {
58+
setColormode(colormodeProps);
59+
}, [colormodeProps]);
60+
useEffect(() => {
61+
setColormode(colormodeFromStore);
62+
}, [colormodeFromStore]);
5463
return (
5564
<JupyterReactColormodeContext.Provider value={colormode}>
5665
{loadJupyterLabCss && <JupyterLabCss colormode={colormode} />}

packages/react/src/typings.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ declare module '*/widgets-base.css' {
6464
export default value;
6565
}
6666

67+
declare module '@primer/primitives/dist/css/*' {
68+
const value: any;
69+
export default value;
70+
}
71+
6772
declare module 'jupyterlab-plotly/lib/jupyterlab-plugin' {
6873
const value: any;
6974
export default value;

packages/react/webpack.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ const ENTRY =
7272
// './src/examples/NotebookSimple';
7373
// './src/examples/NotebookSkeleton';
7474
// './src/examples/NotebookTheme';
75-
// './src/examples/NotebookThemeColormode';
76-
// './src/examples/NotebookToc';
77-
// './src/examples/NotebookURL';
78-
// './src/examples/NotebookURL';
79-
// './src/examples/ObservableHQ';
80-
'./src/examples/Outputs';
75+
'./src/examples/NotebookThemeColormode';
76+
// './src/examples/NotebookToc';
77+
// './src/examples/NotebookURL';
78+
// './src/examples/NotebookURL';
79+
// './src/examples/ObservableHQ';
80+
// './src/examples/Outputs';
8181
// './src/examples/OutputIpynb';
8282
// './src/examples/OutputWithMonitoring';
8383
// './src/examples/Plotly';

0 commit comments

Comments
 (0)