11"use client" ;
22
3- import { Box , Container , Stack , Typography } from "@mui/material" ;
3+ import { Box , Container , Fade , Stack , Typography } from "@mui/material" ;
44import { useEffect , useRef , useState } from "react" ;
5+
56import Organizations from "./Organizations" ;
67
78const OrganizationsSlider : React . FC = ( ) => {
89 const orgsTitleEl = useRef < HTMLElement > ( ) ;
910
1011 const [ sliderActiveIndex , setSliderActiveIndex ] = useState ( 0 ) ;
1112 const [ sliderOffsetX , setSliderOffsetX ] = useState ( 0 ) ;
13+ const [ refInView , setRefInView ] = useState ( false ) ;
1214
1315 const onActiveIndexChange = ( index : number ) => {
1416 setSliderActiveIndex ( index ) ;
@@ -17,6 +19,7 @@ const OrganizationsSlider: React.FC = () => {
1719 const updateSliderOffset = ( ) => {
1820 if ( orgsTitleEl . current ) {
1921 setSliderOffsetX ( orgsTitleEl . current . offsetWidth + orgsTitleEl . current . offsetLeft ) ;
22+ setRefInView ( true ) ;
2023 }
2124 } ;
2225
@@ -44,21 +47,23 @@ const OrganizationsSlider: React.FC = () => {
4447 } }
4548 >
4649 < Container >
47- < Stack direction = "row" minWidth = "max-content" alignItems = "center" >
48- < Box ref = { orgsTitleEl } >
49- < Typography
50- variant = "h4"
51- sx = { {
52- opacity : sliderActiveIndex == 0 ? 1 : 0 ,
53- transition : ( theme ) => theme . transitions . create ( "opacity" ) ,
54- } }
55- >
56- Våre < br />
57- Foreninger
58- </ Typography >
59- </ Box >
60- < Organizations onActiveIndexChange = { onActiveIndexChange } offsetX = { sliderOffsetX + 48 } />
61- </ Stack >
50+ < Fade in = { refInView } >
51+ < Stack direction = "row" minWidth = "max-content" alignItems = "center" >
52+ < Box ref = { orgsTitleEl } >
53+ < Typography
54+ variant = "h4"
55+ sx = { {
56+ opacity : sliderActiveIndex == 0 ? 1 : 0 ,
57+ transition : ( theme ) => theme . transitions . create ( "opacity" ) ,
58+ } }
59+ >
60+ Våre < br />
61+ Foreninger
62+ </ Typography >
63+ </ Box >
64+ < Organizations onActiveIndexChange = { onActiveIndexChange } offsetX = { sliderOffsetX + 48 } />
65+ </ Stack >
66+ </ Fade >
6267 </ Container >
6368 </ Box >
6469 ) ;
0 commit comments