1- import React from 'react' ;
1+ import React , { useRef } from 'react' ;
22import videos from '@site/docs/tutorial-videos.json' ;
33
44interface Video {
@@ -7,10 +7,71 @@ interface Video {
77}
88
99export default function VideoGrid ( ) : JSX . Element {
10+ const videoRefs = useRef < { [ key : string ] : HTMLDivElement | null } > ( { } ) ;
11+
12+ const scrollToVideo = ( videoId : string ) => {
13+ const element = videoRefs . current [ videoId ] ;
14+ if ( element ) {
15+ element . scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
16+ }
17+ } ;
18+
1019 return (
11- < div className = "video-grid" >
12- { videos . videos . map ( ( video : Video ) => (
13- < div key = { video . id } className = "video-item" >
20+ < div >
21+ { /* Table of Contents */ }
22+ < div className = "video-toc" style = { {
23+ marginBottom : '2rem' ,
24+ padding : '1.5rem' ,
25+ backgroundColor : 'var(--ifm-background-surface-color)' ,
26+ borderRadius : '8px' ,
27+ border : '1px solid var(--ifm-color-emphasis-200)' ,
28+ } } >
29+ < h3 style = { { marginTop : 0 , marginBottom : '1rem' } } > Videos</ h3 >
30+ < ol style = { {
31+ listStylePosition : 'inside' ,
32+ paddingLeft : 0 ,
33+ marginBottom : 0 ,
34+ } } >
35+ { videos . videos . map ( ( video : Video ) => (
36+ < li key = { `toc-${ video . id } ` } style = { {
37+ marginBottom : '0.5rem' ,
38+ cursor : 'pointer' ,
39+ color : 'var(--ifm-color-primary)' ,
40+ } } >
41+ < a
42+ onClick = { ( e ) => {
43+ e . preventDefault ( ) ;
44+ scrollToVideo ( video . id ) ;
45+ } }
46+ style = { {
47+ cursor : 'pointer' ,
48+ textDecoration : 'none' ,
49+ color : 'inherit' ,
50+ } }
51+ onMouseEnter = { ( e ) => {
52+ e . currentTarget . style . textDecoration = 'underline' ;
53+ } }
54+ onMouseLeave = { ( e ) => {
55+ e . currentTarget . style . textDecoration = 'none' ;
56+ } }
57+ >
58+ { video . title }
59+ </ a >
60+ </ li >
61+ ) ) }
62+ </ ol >
63+ </ div >
64+
65+ { /* Video Grid */ }
66+ < div className = "video-grid" >
67+ { videos . videos . map ( ( video : Video ) => (
68+ < div
69+ key = { video . id }
70+ className = "video-item"
71+ ref = { ( el ) => {
72+ videoRefs . current [ video . id ] = el ;
73+ } }
74+ >
1475 < div
1576 className = "video-container"
1677 onClick = { ( e ) => {
@@ -59,6 +120,7 @@ export default function VideoGrid(): JSX.Element {
59120 </ div >
60121 </ div >
61122 ) ) }
123+ </ div >
62124 </ div >
63125 ) ;
64126}
0 commit comments