Skip to content

Commit faa0d68

Browse files
committed
Enhance OrganizationsSlider with fade-in effect and view tracking
1 parent 0527970 commit faa0d68

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

frontend/src/app/_components/LandingHero/Organizations.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { ArrowLeft, ArrowRight } from "@mui/icons-material";
12
import { Box, Button, IconButton } from "@mui/material";
23
import { styled } from "@mui/system";
34
import Link from "next/link";
45
import { FreeMode, Mousewheel, Navigation } from "swiper";
56
import "swiper/css";
67
import { Swiper, SwiperSlide } from "swiper/react";
78

8-
import { ArrowLeft, ArrowRight } from "@mui/icons-material";
99
import { Organization, OrganizationLink } from "./OrganizationLink";
1010

1111
const organizations: Readonly<Organization[]> = [

frontend/src/app/_components/LandingHero/OrganizationsSlider.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"use client";
22

3-
import { Box, Container, Stack, Typography } from "@mui/material";
3+
import { Box, Container, Fade, Stack, Typography } from "@mui/material";
44
import { useEffect, useRef, useState } from "react";
5+
56
import Organizations from "./Organizations";
67

78
const 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

Comments
 (0)