Skip to content

Commit 6f5f2a9

Browse files
committed
fix: nextjs
1 parent f4d510c commit 6f5f2a9

File tree

5 files changed

+69
-38
lines changed

5 files changed

+69
-38
lines changed

examples/next-js/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Image from "next/image";
44
import dynamic from 'next/dynamic';
55

66
const JupyterComponentNoSSR = dynamic(
7-
() => import('../components/CellComponent'),
7+
() => import('../components/NotebookComponent'),
88
{
99
ssr: false,
1010
loading: () => <p>Loading Jupyter Component...</p>

examples/next-js/src/components/CellComponent.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,41 @@
66

77
'use client';
88

9-
import { useEffect, useState } from 'react';
10-
import { useJupyter, JupyterReactTheme } from '@datalayer/jupyter-react';
9+
import { useJupyter, JupyterReactTheme, Cell } from '@datalayer/jupyter-react';
10+
/*
1111
import dynamic from 'next/dynamic';
12-
13-
// Dynamically import the Cell component with SSR disabled
1412
const Cell = dynamic(
1513
() => import('@datalayer/jupyter-react').then((mod) => ({ default: mod.Cell })),
1614
{
1715
ssr: false,
1816
loading: () => <p>Loading Jupyter Cell...</p>
1917
}
2018
);
21-
19+
*/
2220
export const CellComponent = () => {
2321
const { defaultKernel } = useJupyter({
2422
jupyterServerUrl: "https://oss.datalayer.run/api/jupyter-server",
2523
jupyterServerToken: "60c1661cc408f978c309d04157af55c9588ff9557c9380e4fb50785750703da6",
2624
startDefaultKernel: true,
2725
});
28-
if (!defaultKernel) {
29-
return <p>Loading Jupyter Cell...</p>;
30-
}
3126
return (
3227
<>
33-
<div style={{fontSize: 20}}>Jupyter Cell in Next.js</div>
34-
<JupyterReactTheme>
35-
<Cell
36-
id="test-cell"
37-
type="code"
38-
source="1+1"
39-
kernel={defaultKernel}
40-
autoStart
41-
/>
42-
</JupyterReactTheme>
28+
{defaultKernel ?
29+
<>
30+
<div style={{fontSize: 20}}>Jupyter Cell in Next.js</div>
31+
<JupyterReactTheme>
32+
<Cell
33+
id="test-cell"
34+
type="code"
35+
source="1+1"
36+
kernel={defaultKernel}
37+
autoStart
38+
/>
39+
</JupyterReactTheme>
40+
</>
41+
:
42+
<p>Loading Jupyter Cell...</p>
43+
}
4344
</>
4445
)
4546
}

examples/next-js/src/components/NotebookComponent.tsx

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,60 @@
66

77
'use client'
88

9-
import { JupyterReactTheme, Notebook, CellSidebarExtension, CellSidebarButton } from '@datalayer/jupyter-react';
10-
import { NotebookToolbar } from '@datalayer/jupyter-react';
9+
import { useJupyter, JupyterReactTheme, Notebook2, NotebookToolbar, CellSidebarExtension, CellSidebarButton } from '@datalayer/jupyter-react';
10+
import { Box } from '@primer/react';
1111
import { PrimerTheme } from './PrimerTheme';
1212

13-
type NotebookComponentProps = {
13+
type INotebookComponentProps = {
1414
colorMode?: 'light' | 'dark';
1515
theme?: PrimerTheme;
1616
}
1717

18-
export const NotebookComponent = (props: NotebookComponentProps) => {
19-
const { colorMode, theme } = props;
18+
export const NotebookComponent = (props: INotebookComponentProps) => {
19+
// const { colorMode, theme } = props;
20+
const { defaultKernel, serviceManager } = useJupyter({
21+
jupyterServerUrl: "https://oss.datalayer.run/api/jupyter-server",
22+
jupyterServerToken: "60c1661cc408f978c309d04157af55c9588ff9557c9380e4fb50785750703da6",
23+
startDefaultKernel: true,
24+
});
2025
return (
2126
<>
22-
<div style={{fontSize: 20}}>Jupyter Notebook in Next.js</div>
23-
<JupyterReactTheme>
24-
<Notebook
25-
path="ipywidgets.ipynb"
26-
id="notebook-nextjs-1"
27-
cellSidebarMargin={120}
28-
height="500px"
29-
extensions={[new CellSidebarExtension({ factory: CellSidebarButton })]}
30-
Toolbar={NotebookToolbar}
31-
/>
32-
</JupyterReactTheme>
27+
{ defaultKernel && serviceManager ?
28+
<>
29+
<div style={{fontSize: 20}}>Jupyter Notebook in Next.js</div>
30+
<JupyterReactTheme>
31+
<Box
32+
sx={{
33+
'& .jp-NotebookPanel': {
34+
height: '500px !important',
35+
maxHeight: '500px !important',
36+
width: '100%',
37+
overflowY: 'hidden',
38+
},
39+
'& .jp-Notebook': {
40+
flex: '1 1 auto !important',
41+
height: '500px !important',
42+
maxHeight: '500px !important',
43+
overflowY: 'scroll',
44+
},
45+
}}
46+
>
47+
<Notebook2
48+
path="ipywidgets.ipynb"
49+
id="notebook-nextjs-1"
50+
cellSidebarMargin={120}
51+
height="500px"
52+
kernelId={defaultKernel.id}
53+
serviceManager={serviceManager}
54+
extensions={[new CellSidebarExtension({ factory: CellSidebarButton })]}
55+
Toolbar={NotebookToolbar}
56+
/>
57+
</Box>
58+
</JupyterReactTheme>
59+
</>
60+
:
61+
<p>Loading Jupyter Notebook...</p>
62+
}
3363
</>
3464
)
3565
}

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.0.3",
3+
"version": "1.0.4",
44
"description": "Jupyter React - React.js components 100% compatible with Jupyter.",
55
"license": "MIT",
66
"main": "lib/index.js",

packages/react/src/components/notebook/Notebook2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export function Notebook2(props: React.PropsWithChildren<INotebook2Props>): JSX.
195195
overflowY: 'scroll',
196196
},
197197
'& .jp-NotebookPanel': {
198-
height: '100% !important',
199-
width: '100% !important',
198+
// height: '100% !important',
199+
// width: '100% !important',
200200
},
201201
'& .jp-Toolbar': {
202202
display: 'none',

0 commit comments

Comments
 (0)