diff --git a/packages/web/public/temp/1.jpg b/packages/web/public/temp/1.jpg new file mode 100644 index 0000000..465572b Binary files /dev/null and b/packages/web/public/temp/1.jpg differ diff --git a/packages/web/public/temp/2.jpg b/packages/web/public/temp/2.jpg new file mode 100644 index 0000000..7d178ca Binary files /dev/null and b/packages/web/public/temp/2.jpg differ diff --git a/packages/web/public/temp/3.jpg b/packages/web/public/temp/3.jpg new file mode 100644 index 0000000..b71d90c Binary files /dev/null and b/packages/web/public/temp/3.jpg differ diff --git a/packages/web/src/common/components/Banner/Banner.tsx b/packages/web/src/common/components/Banner/Banner.tsx new file mode 100644 index 0000000..855c7c3 --- /dev/null +++ b/packages/web/src/common/components/Banner/Banner.tsx @@ -0,0 +1,83 @@ +import React, { useState, useEffect } from "react"; +import styled from "styled-components"; +import Image from "next/image"; + +type BannerProps = { + images?: string[]; + onClick?: (idx: number) => void; +}; + +const BannerWrapper = styled.div` + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + padding: 0px; + gap: 0px; + + position: relative; + + border-radius: 4px; +`; + +const Arrow = styled.button` + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + padding: 5px; + gap: 0px; + + margin: 0 -40px; + width: 18px; + height: 18px; + + background: rgba(94, 94, 94, 0.5); + color: white; + border-radius: 4px; + z-index: 1; +`; + +const Banner: React.FC = ({ + images = ["temp/1.jpg", "temp/2.jpg", "temp/3.jpg"], + onClick = _idx => {}, +}) => { + const [currentIndex, setCurrentIndex] = useState(0); + + const handlePrev = () => { + const index = currentIndex === 0 ? images.length - 1 : currentIndex - 1; + setCurrentIndex(index); + }; + + const handleNext = () => { + const index = currentIndex === images.length - 1 ? 0 : currentIndex + 1; + setCurrentIndex(index); + }; + + useEffect(() => { + const interval = setInterval(() => { + handleNext(); + }, 5000); // 5초마다 이미지 변경 + + return () => clearInterval(interval); + }, [currentIndex]); + + return ( + + {"<"} + +
+ {`배너 onClick(currentIndex)} + /> +
+ + {">"} +
+ ); +}; +export default Banner;