@@ -31,6 +31,80 @@ import DemoFileMosaicSmartImgFit from "../../components/demo-components/filemosa
3131import CodeJSFileMosaicSmartImgFit from "../../components/demo-components/filemosaic-demo/CodeJSFileMosaicSmartImgFit" ;
3232
3333const FileMosaicDemoPage = ( props ) => {
34+ const [ selectedItem , setSelectedItem ] = React . useState ( 0 ) ;
35+
36+ const scrollHandler = ( ) => {
37+ let menu = document . querySelector ( ".section-container" ) ;
38+
39+ const rightMenuItemsWithIdSec = rightMenuItems . map ( ( x ) => {
40+ return {
41+ ...x ,
42+ idSec : x . referTo . split ( "#" ) [ 1 ] ,
43+ } ;
44+ } ) ;
45+ /* console.log(
46+ "scrollHandler rightMenuItemsWithIdSec",
47+ rightMenuItemsWithIdSec.map((x) => x.idSec)
48+ ); */
49+ const arrElements = rightMenuItemsWithIdSec . map ( ( x ) => {
50+ return { ...x , element : document . getElementById ( x . idSec ) } ;
51+ } ) ;
52+
53+ //console.log("scrollHandler arrElements", arrElements);
54+ let pos_menu = window . pageYOffset + menu . offsetHeight ;
55+
56+ //simply chech whicof them is clser to offset toip????
57+ console . log ( "scrollHandler pos_menu" , pos_menu ) ;
58+
59+ const arrElementsEnhanced = arrElements . map ( ( x ) => {
60+ const element = x . element ;
61+ const postElement = element . offsetTop + element . offsetHeight ;
62+ const distance = Math . abs ( postElement - pos_menu ) ;
63+ return { ...x , distance } ;
64+ } ) ;
65+
66+ console . log (
67+ "scrollHandler distances" ,
68+ pos_menu ,
69+ arrElementsEnhanced . map ( ( { distance } ) => distance )
70+ ) ;
71+
72+ let min = Math . min ( ...arrElementsEnhanced . map ( ( x ) => x . distance ) ) ;
73+
74+ arrElementsEnhanced . forEach ( ( x ) => {
75+ if ( x . distance === min ) {
76+ setSelectedItem ( x . id ) ;
77+ console . log ( "foundelement distance" , x . distance ) ;
78+ console . log ( "foundelement id" , x . id ) ;
79+ }
80+ } ) ;
81+
82+ console . log (
83+ "distance min" ,
84+ min ,
85+ arrElementsEnhanced . map ( ( x ) => x . distance )
86+ ) ;
87+
88+ // if (min === distance_A) setSelectedItem(0);
89+ //document.querySelectorAll(".Menu .Item")[0].classList.add("Highlight");
90+ // if (min === distance_B) setSelectedItem(1);
91+ // if (min === distance_C) setSelectedItem(2);
92+ /* if (min === distance_B)
93+ document.querySelectorAll(".Menu .Item")[1].classList.add("Highlight");
94+ if (min === distance_C)
95+ document.querySelectorAll(".Menu .Item")[2].classList.add("Highlight"); */
96+ } ;
97+ React . useEffect ( ( ) => {
98+ console . log ( "scrollHandler container" ) ;
99+
100+ window . addEventListener ( "scroll" , scrollHandler ) ;
101+
102+ return ( ) => {
103+ console . log ( "foundelement" , "removing event" ) ;
104+ window . removeEventListener ( "scroll" , scrollHandler ) ;
105+ } ;
106+ } , [ ] ) ;
107+
34108 return (
35109 < React . Fragment >
36110 < MainContentContainer >
@@ -79,7 +153,10 @@ const FileMosaicDemoPage = (props) => {
79153 < CodeHighlight > { `<FileInputButton/>` } </ CodeHighlight >
80154 component for allowing the user to select files. For further
81155 information of this component check out the{ " " }
82- < AnchorToTab href = "/components/fileinputbutton" > FileInputButton</ AnchorToTab > page.
156+ < AnchorToTab href = "/components/fileinputbutton" >
157+ FileInputButton
158+ </ AnchorToTab > { " " }
159+ page.
83160 </ Alert >
84161 < br />
85162 < Alert severity = "info" >
@@ -392,12 +469,17 @@ const FileMosaicDemoPage = (props) => {
392469 </ section >
393470 </ MainContentContainer >
394471 < RightMenuContainer >
395- < RightMenu width = "240px" items = { rightMenuItems } />
472+ < RightMenu
473+ width = "240px"
474+ items = { rightMenuItems }
475+ selectedItemProp = { selectedItem }
476+ />
396477 </ RightMenuContainer >
397478 </ React . Fragment >
398479 ) ;
399480} ;
400481export default FileMosaicDemoPage ;
482+
401483const rightMenuItems = [
402484 {
403485 id : 0 ,
0 commit comments