@@ -7,12 +7,39 @@ import {
77 SandpackCodeEditor ,
88 SandpackPreview ,
99 SandpackConsole ,
10- useActiveCode ,
1110 useSandpack ,
1211} from '@codesandbox/sandpack-react'
1312// sandpackDark is bundled with sandpack-react
1413const sandpackDark = 'dark' as const
1514
15+ function RunButton ( ) {
16+ const { dispatch, sandpack } = useSandpack ( )
17+ const isLoading = sandpack . status === 'initial' || sandpack . status === 'timeout'
18+ return (
19+ < button
20+ onClick = { ( ) => dispatch ( { type : 'refresh' } ) }
21+ disabled = { isLoading }
22+ style = { {
23+ display : 'flex' ,
24+ alignItems : 'center' ,
25+ gap : '6px' ,
26+ padding : '4px 14px' ,
27+ borderRadius : '4px' ,
28+ border : 'none' ,
29+ cursor : isLoading ? 'not-allowed' : 'pointer' ,
30+ fontFamily : 'var(--sp-font-mono)' ,
31+ fontSize : '12px' ,
32+ fontWeight : 600 ,
33+ background : isLoading ? 'var(--sp-colors-surface2)' : '#22c55e' ,
34+ color : isLoading ? 'var(--sp-colors-fg-inactive)' : '#fff' ,
35+ transition : 'background 0.15s' ,
36+ } }
37+ >
38+ ▶ Run
39+ </ button >
40+ )
41+ }
42+
1643// Conflux network configs
1744const NETWORKS = {
1845 testnet : {
@@ -58,18 +85,7 @@ function NetworkToggle({
5885 onChange : ( n : Network ) => void
5986} ) {
6087 return (
61- < div
62- style = { {
63- display : 'flex' ,
64- alignItems : 'center' ,
65- gap : '8px' ,
66- padding : '6px 12px' ,
67- borderBottom : '1px solid var(--sp-colors-surface2)' ,
68- background : 'var(--sp-colors-surface1)' ,
69- fontSize : '12px' ,
70- fontFamily : 'var(--sp-font-mono)' ,
71- } }
72- >
88+ < div style = { { display : 'flex' , alignItems : 'center' , gap : '8px' , fontSize : '12px' , fontFamily : 'var(--sp-font-mono)' } } >
7389 < span style = { { color : 'var(--sp-colors-fg-inactive)' } } > network:</ span >
7490 { ( Object . keys ( NETWORKS ) as Network [ ] ) . map ( ( key ) => (
7591 < button
@@ -82,27 +98,15 @@ function NetworkToggle({
8298 cursor : 'pointer' ,
8399 fontFamily : 'inherit' ,
84100 fontSize : '11px' ,
85- background :
86- network === key
87- ? 'var(--sp-colors-accent)'
88- : 'var(--sp-colors-surface2)' ,
89- color :
90- network === key
91- ? '#fff'
92- : 'var(--sp-colors-fg-inactive)' ,
101+ background : network === key ? 'var(--sp-colors-accent)' : 'var(--sp-colors-surface2)' ,
102+ color : network === key ? '#fff' : 'var(--sp-colors-fg-inactive)' ,
93103 } }
94104 >
95105 { NETWORKS [ key ] . label }
96106 </ button >
97107 ) ) }
98- < span
99- style = { {
100- marginLeft : 'auto' ,
101- color : 'var(--sp-colors-fg-inactive)' ,
102- fontSize : '10px' ,
103- } }
104- >
105- chainId: { NETWORKS [ network ] . chainId } · { NETWORKS [ network ] . rpcUrl }
108+ < span style = { { color : 'var(--sp-colors-fg-inactive)' , fontSize : '10px' } } >
109+ · chain { NETWORKS [ network ] . chainId }
106110 </ span >
107111 </ div >
108112 )
@@ -158,18 +162,35 @@ export const NETWORK = {
158162 } ,
159163 } }
160164 >
161- < NetworkToggle network = { network } onChange = { setNetwork } />
165+ { /* Inner toolbar — inside Provider so RunButton can access sandpack context */ }
166+ < div
167+ style = { {
168+ display : 'flex' ,
169+ alignItems : 'center' ,
170+ justifyContent : 'space-between' ,
171+ padding : '6px 12px' ,
172+ borderBottom : '1px solid var(--sp-colors-surface2)' ,
173+ background : 'var(--sp-colors-surface1)' ,
174+ } }
175+ >
176+ < NetworkToggle network = { network } onChange = { setNetwork } />
177+ < RunButton />
178+ </ div >
162179 < SandpackLayout >
163180 < SandpackCodeEditor
164181 showLineNumbers
165182 showInlineErrors
166183 wrapContent
167- style = { { height : 400 } }
184+ style = { { height : 380 } }
168185 />
169186 { showConsole ? (
170- < SandpackConsole style = { { height : 400 } } />
187+ < SandpackConsole
188+ showHeader
189+ showResetConsoleButton
190+ style = { { height : 380 } }
191+ />
171192 ) : (
172- < SandpackPreview style = { { height : 400 } } />
193+ < SandpackPreview style = { { height : 380 } } showNavigator = { false } />
173194 ) }
174195 </ SandpackLayout >
175196 </ SandpackProvider >
0 commit comments