|
1 | 1 | import { Box, Flex, Link } from "@chakra-ui/react";
|
2 |
| - |
| 2 | +import React, { useRef, useEffect } from "react"; |
| 3 | +import { motion } from "framer-motion"; |
3 | 4 | const SponsorCard = ({ imagePath, link }) => {
|
4 | 5 | return (
|
5 | 6 | <Link href={link} isExternal>
|
6 |
| - <Box |
7 |
| - mx={2} |
8 |
| - mb={4} |
9 |
| - borderRadius="md" |
10 |
| - width="140px" |
11 |
| - height="100px" |
12 |
| - display="flex" |
13 |
| - alignItems="center" |
| 7 | + <Box |
| 8 | + mx={4} |
| 9 | + mb={4} |
| 10 | + borderRadius="md" |
| 11 | + width="140px" |
| 12 | + height="100px" |
| 13 | + display="flex" |
| 14 | + alignItems="center" |
14 | 15 | justifyContent="center"
|
15 | 16 | overflow="hidden"
|
16 |
| - _hover={{ transform: 'scale(1.05)' }} |
| 17 | + _hover={{ transform: "scale(1.05)" }} |
17 | 18 | transition="transform 0.2s ease-in-out"
|
18 | 19 | >
|
19 | 20 | <img src={imagePath} alt="Sponsor" width="100%" />
|
20 | 21 | </Box>
|
21 | 22 | </Link>
|
22 | 23 | );
|
23 |
| -} |
24 |
| - |
| 24 | +}; |
| 25 | +const TranslateWrapper = ({ children, reverse }) => { |
| 26 | + return ( |
| 27 | + <> |
| 28 | + <motion.div |
| 29 | + initial={{ translateX: reverse ? "-100%" : "0%" }} |
| 30 | + animate={{ translateX: reverse ? "0%" : "-100%" }} |
| 31 | + transition={{ duration: 20, repeat: Infinity, ease: "linear" }} |
| 32 | + > |
| 33 | + {children} |
| 34 | + |
| 35 | + </motion.div> |
| 36 | + </> |
| 37 | + ); |
| 38 | +}; |
25 | 39 | const Sponsors = ({ sponsors }) => {
|
26 |
| - const halfLength = Math.ceil(sponsors.length / 2); |
27 |
| - const firstRowSponsors = sponsors.slice(0, halfLength); |
28 |
| - const secondRowSponsors = sponsors.slice(halfLength); |
29 |
| - |
30 | 40 | return (
|
31 |
| - <Box mt="2rem" w="100%" > |
32 |
| - <Flex gap="10px" direction="row" justifyContent="center" wrap="wrap" mb={4}> |
33 |
| - {firstRowSponsors.map((sponsor, index) => ( |
34 |
| - <SponsorCard key={index} imagePath={sponsor.imagePath} link={sponsor.link} /> |
35 |
| - ))} |
36 |
| - </Flex> |
37 |
| - <Flex gap="10px" direction="row" justifyContent="center" wrap="wrap"> |
38 |
| - {secondRowSponsors.map((sponsor, index) => ( |
39 |
| - <SponsorCard key={index} imagePath={sponsor.imagePath} link={sponsor.link} /> |
40 |
| - ))} |
41 |
| - </Flex> |
| 41 | + <Box |
| 42 | + mx="auto" |
| 43 | + mt="2rem" |
| 44 | + w={["100%", "80%"]} |
| 45 | + overflow="hidden" |
| 46 | + position="relative" |
| 47 | + sx={{ |
| 48 | + "::before": { |
| 49 | + content: '""', |
| 50 | + position: "absolute", |
| 51 | + top: 0, |
| 52 | + left: 0, |
| 53 | + bottom: 0, |
| 54 | + width: ["70px", "100px", "200px", "250px"], |
| 55 | + background: |
| 56 | + "linear-gradient(to right, #FCFCFC, rgba(255, 255, 255, 0))", |
| 57 | + zIndex: 2, |
| 58 | + pointerEvents: "none", |
| 59 | + }, |
| 60 | + "::after": { |
| 61 | + content: '""', |
| 62 | + position: "absolute", |
| 63 | + top: 0, |
| 64 | + right: 0, |
| 65 | + bottom: 0, |
| 66 | + width: ["70px", "100px", "200px", "250px"], |
| 67 | + background: |
| 68 | + "linear-gradient(to left, #FCFCFC, rgba(255, 255, 255, 0))", |
| 69 | + zIndex: 2, |
| 70 | + pointerEvents: "none", |
| 71 | + }, |
| 72 | + }} |
| 73 | + > |
| 74 | + <TranslateWrapper> |
| 75 | + <Flex direction="row"> |
| 76 | + {sponsors.map((sponsor, index) => ( |
| 77 | + <SponsorCard |
| 78 | + key={index} |
| 79 | + imagePath={sponsor.imagePath} |
| 80 | + link={sponsor.link} |
| 81 | + /> |
| 82 | + ))} |
| 83 | + </Flex> |
| 84 | + </TranslateWrapper> |
42 | 85 | </Box>
|
43 | 86 | );
|
44 |
| -} |
| 87 | +}; |
45 | 88 |
|
46 | 89 | export default Sponsors;
|
0 commit comments