33 EditorProps ,
44 EditorStep ,
55} from "@code-hike/mini-editor"
6- import { Code } from "./code"
6+ import { InnerCode , updateEditorStep } from "./code"
77import {
88 Scroller ,
99 Step as ScrollerStep ,
@@ -25,12 +25,26 @@ export function Scrollycoding({
2525} ) {
2626 const stepsChildren = React . Children . toArray ( children )
2727
28- const [ stepIndex , setIndex ] = React . useState ( start )
29- const tab = editorSteps [ stepIndex ]
28+ const [ state , setState ] = React . useState ( {
29+ stepIndex : start ,
30+ step : editorSteps [ start ] ,
31+ } )
32+
33+ const tab = state . step
3034
3135 function onStepChange ( index : number ) {
32- setIndex ( index )
36+ setState ( { stepIndex : index , step : editorSteps [ index ] } )
37+ }
38+
39+ function onTabClick ( filename : string ) {
40+ const newStep = updateEditorStep (
41+ state . step ,
42+ filename ,
43+ null
44+ )
45+ setState ( { ...state , step : newStep } )
3346 }
47+
3448 return (
3549 < section
3650 className = { `ch-scrollycoding ${
@@ -44,10 +58,10 @@ export function Scrollycoding({
4458 as = "div"
4559 key = { i }
4660 index = { i }
47- onClick = { ( ) => setIndex ( i ) }
61+ onClick = { ( ) => onStepChange ( i ) }
4862 className = "ch-scrollycoding-step-content"
4963 data-selected = {
50- i === stepIndex ? "true" : undefined
64+ i === state . stepIndex ? "true" : undefined
5165 }
5266 >
5367 { children }
@@ -56,7 +70,11 @@ export function Scrollycoding({
5670 </ Scroller >
5771 </ div >
5872 < div className = "ch-scrollycoding-sticker" >
59- < Code { ...( tab as any ) } codeConfig = { codeConfig } />
73+ < InnerCode
74+ { ...( tab as any ) }
75+ codeConfig = { codeConfig }
76+ onTabClick = { onTabClick }
77+ />
6078 { presetConfig && (
6179 < Preview
6280 className = "ch-scrollycoding-preview"
0 commit comments