diff --git a/src/component/template/Template1.tsx b/src/component/template/Template1.tsx index e2e7ba3..5a186ca 100644 --- a/src/component/template/Template1.tsx +++ b/src/component/template/Template1.tsx @@ -1,11 +1,8 @@ -import React, {useEffect, useRef, useState} from 'react'; +import React, {useRef} from 'react'; import Wedding from "@remote/value/Wedding"; import * as S from '@src/component/template/Template1.style'; -import colors from "@designsystem/foundation/colors"; -import {Column,} from "@designsystem/component/flexLayout"; import MoneyInfoTemplate from "@src/component/template/component/MoneyInfoTemplate"; import FooterTemplate from "@src/component/template/component/FooterTemplate"; -import Text from "@designsystem/component/text"; import {templateFontSizeRecord} from "@remote/value/Template"; import GuestCommentsTemplate from "@src/component/template/component/GuestCommentsTemplate"; import {increaseFontSize} from "@util/html.util"; @@ -55,6 +52,7 @@ function Template1( rootRef={rootRef} imgDesign={wedding.imgDesign} imgList={wedding.imgList} + slideStyle={'style1'} /> ; imgDesign: ImgDesign; imgList: string[]; + slideStyle?: GallerySlideStyle; } function GalleryTemplate( { rootRef, imgDesign, - imgList + imgList, + slideStyle = 'style1' }: GalleryTemplateProps ) { - const [currentImageIndex, setCurrentImageIndex] = useState(0); // 현재 보여지는 이미지의 인덱스를 추적 + return ( + + + GALLERY + + {imgDesign === ImgDesign.SLIDE ? ( + + ) : ( + + {imgList.map((img, index) => ( + + ))} + + )} + + ); +} + +function GallerySlide( + { + rootRef, + imgList, + slideStyle + }: { + rootRef: RefObject; + imgList: string[]; + slideStyle: GallerySlideStyle; + } +) { const scrollContainerRef = useRef(null); + const [currentImageIndex, setCurrentImageIndex] = useState(0); // 현재 보여지는 이미지의 인덱스를 추적 + const handleScroll = () => { if (!scrollContainerRef.current) return; const containerWidth = rootRef.current?.getBoundingClientRect().width ?? 0; const scrollContainer = scrollContainerRef.current; - const scrollPosition = scrollContainer.scrollLeft - 34; - const imageWidth = containerWidth - 34 * 2 + 8; // 이미지 너비 + 간격 + const scrollPosition = scrollContainer.scrollLeft - (slideStyle === 'style1' ? 34 : 0); + const imageWidth = containerWidth + - (slideStyle === 'style1' ? (34 * 2) : 0) + + (slideStyle === 'style1' ? 8 : 0); // 이미지 너비 - 간격 const index = Math.floor(scrollPosition / imageWidth); console.log(`${scrollPosition}, ${imageWidth}`); console.log(index); @@ -43,40 +85,77 @@ function GalleryTemplate( container?.removeEventListener('scroll', handleScroll); } }, []); - + return ( - - - GALLERY - - {imgDesign === ImgDesign.SLIDE ? ( - - - {imgList.map((img, index) => ( - - ))} - - - {Array.from({length: imgList.length}, (_, index) => index).map((i, index) => ( - - ))} - - - ) : ( - - {imgList.map((img, index) => ( - - ))} - - )} - + + + {imgList.map((img, index) => ( + + ))} + + {}} + /> + ); } +function GalleryStyleIndicator( + { + imgListLength, + currentImageIndex, + slideStyle, + onClick + }: { + imgListLength: number; + currentImageIndex: number; + slideStyle: GallerySlideStyle; + onClick: (type: 'moveLeft' | 'moveRight') => void; + } +) { + switch (slideStyle) { + case 'style1': + return ( + + {Array.from({length: imgListLength}, (_, index) => index).map((i, index) => ( + + ))} + + ); + case 'style2': + return ( + + { + onClick('moveLeft'); + }}/> + {currentImageIndex + 1}/{imgListLength} + { + onClick('moveRight'); + }}/> + + ); + } +} + const S = { root: styled.div` display: flex; @@ -99,12 +178,14 @@ const S = { align-self: stretch; overflow-x: hidden; `, - scroll: styled.div` + scroll: styled.div<{ slideStyle: GallerySlideStyle }>` scroll-snap-type: x mandatory; overflow-x: scroll; overflow-y: hidden; display: flex; - gap: 8px; + ${({slideStyle}) => slideStyle === 'style1' && css` + gap: 8px; + `}; ${hideScrollBar}; `, gridImg: styled.img` @@ -113,9 +194,12 @@ const S = { object-fit: cover; border-radius: 4px; `, - slideImg: styled.img<{ $rootWidth: number }>` + slideImg: styled.img<{ + $rootWidth: number, + slideStyle: GallerySlideStyle + }>` display: flex; - ${({$rootWidth}) => css` + ${({$rootWidth, slideStyle}) => slideStyle === 'style1' ? css` width: ${$rootWidth - 34 * 2}px; &:first-child { @@ -125,17 +209,22 @@ const S = { &:last-child { margin-right: ${$rootWidth - 34}px; } + border-radius: 12px; + ` : css` + width: ${$rootWidth}px; + + // &:first-child { + // margin-left: ${$rootWidth}px; + // } + // + // &:last-child { + // margin-right: ${$rootWidth}px; + // } `}; height: 517px; - border-radius: 12px; scroll-snap-align: center; object-fit: cover; `, - indicatorWrapper: styled.div` - display: flex; - gap: 8px; - align-self: center; - `, indicator: styled.span<{ selected: boolean }>` display: flex; width: 8px;