Skip to content

Commit

Permalink
feat: add number and custom alt text
Browse files Browse the repository at this point in the history
  • Loading branch information
malloc3141 committed Nov 24, 2024
1 parent 70a5938 commit 3e09331
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions packages/web/src/common/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Image from "next/image";

type BannerProps = {
images?: string[];
alt?: string[];
onClick?: (idx: number) => void;
};

Expand Down Expand Up @@ -38,8 +39,20 @@ const Arrow = styled.button`
z-index: 1;
`;

const IndexWrapper = styled.div`
display: flex;
margin-top: 8px;
justify-content: center;
`;

const StyledImage = styled(Image)`
width: 100%;
height: auto;
`;

const Banner: React.FC<BannerProps> = ({
images = ["temp/1.jpg", "temp/2.jpg", "temp/3.jpg"],
alt = ["배너 이미지 1", "배너 이미지 2", "배너 이미지 3"],
onClick = _idx => {},
}) => {
const [currentIndex, setCurrentIndex] = useState<number>(0);
Expand All @@ -63,21 +76,28 @@ const Banner: React.FC<BannerProps> = ({
}, [currentIndex]);

return (
<BannerWrapper>
<Arrow onClick={handlePrev}>{"<"}</Arrow>

<div>
<Image
src={`/${images[currentIndex]}`}
alt={`배너 이미지 ${currentIndex + 1}`}
width={840}
height={336}
onClick={() => onClick(currentIndex)}
/>
</div>

<Arrow onClick={handleNext}>{">"}</Arrow>
</BannerWrapper>
<div>
<BannerWrapper>
<Arrow onClick={handlePrev}>{"<"}</Arrow>

<div>
<StyledImage
src={`/${images[currentIndex]}`}
alt={alt[currentIndex]}
width={0}
height={0}
sizes="40vw"
onClick={() => onClick(currentIndex)}
/>
</div>

<Arrow onClick={handleNext}>{">"}</Arrow>
</BannerWrapper>

<IndexWrapper>
{currentIndex + 1} / {images.length}
</IndexWrapper>
</div>
);
};
export default Banner;

0 comments on commit 3e09331

Please sign in to comment.