File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
packages/react/src/examples Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2021-2023 Datalayer, Inc.
3
+ *
4
+ * MIT License
5
+ */
6
+ import React , { useEffect } from 'react' ;
7
+ import { createRoot } from 'react-dom/client' ;
8
+
9
+ import { Button , Box } from '@primer/react' ;
10
+
11
+ import Jupyter from '../jupyter/Jupyter' ;
12
+ import Cell from '../components/cell/Cell' ;
13
+ import { cellsStore , ICellsState } from '../components/cell/CellState' ;
14
+
15
+
16
+ const div = document . createElement ( 'div' ) ;
17
+ document . body . appendChild ( div ) ;
18
+ const root = createRoot ( div ) ;
19
+
20
+ const btnStyle = {
21
+ marginLeft : '50px' ,
22
+ marginTop : '20px'
23
+ }
24
+
25
+ const CELL_CODE = `
26
+ import time
27
+ time.sleep(10)
28
+ `
29
+
30
+ const CellExecuteControl = ( ) => {
31
+ const [ executionDisable , setExecutionDisable ] = React . useState ( false ) ;
32
+
33
+ useEffect ( ( ) => {
34
+ const handleChange = ( newState : ICellsState ) => {
35
+ setExecutionDisable ( newState . isAnyCellExecuting ) ;
36
+ } ;
37
+
38
+ const unsubscribe = cellsStore . subscribe ( handleChange ) ;
39
+ return ( ) => {
40
+ unsubscribe ( ) ;
41
+ } ;
42
+ } , [ ] ) ;
43
+
44
+ const onExecuteClick = ( ) => {
45
+ cellsStore . getState ( ) . execute ( ) ;
46
+ }
47
+
48
+ return (
49
+ < Jupyter >
50
+ < Box style = { { marginTop : '20px' } } >
51
+ < Cell
52
+ id = '1'
53
+ type = { 'code' }
54
+ source = { CELL_CODE }
55
+ autoStart = { false }
56
+ showToolbar = { false } />
57
+ < Cell
58
+ id = '2'
59
+ type = { 'code' }
60
+ autoStart = { false }
61
+ showToolbar = { false } />
62
+ < Button
63
+ onClick = { onExecuteClick }
64
+ disabled = { executionDisable }
65
+ style = { btnStyle } > Execute all</ Button >
66
+ </ Box >
67
+ </ Jupyter >
68
+ )
69
+ } ;
70
+
71
+ root . render ( < CellExecuteControl /> ) ;
You can’t perform that action at this time.
0 commit comments