Skip to content

Commit

Permalink
refactor: GeneralCarousel 컴포넌트 children prop 추가 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
dladncks1217 authored Jan 8, 2024
1 parent 830716f commit 1e0a108
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/components/GeneralCarousel/GeneralCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface useGeneralCarouselProps {
showNavigationOnHover?: boolean;
showArrows?: boolean;
showDots?: boolean;
children?: JSX.Element | JSX.Element[] | null;
}

const GeneralCarousel = ({
Expand All @@ -30,6 +31,7 @@ const GeneralCarousel = ({
showNavigationOnHover = true,
showArrows = true,
showDots = true,
children = null,
}: useGeneralCarouselProps) => {
const { viewIndex, itemRef, carouselBoxRef, handleMoveImage, handleClickLeft, handleClickRight } =
useGeneralCarousel(items);
Expand All @@ -50,28 +52,30 @@ const GeneralCarousel = ({
</div>
)}
<Box css={sliderWrapperStyling}>
{items.map((Item, index) => {
if (typeof Item === 'string') {
return (
<div
ref={index === viewIndex ? itemRef : null}
key={crypto.randomUUID()}
css={getItemWrapperStyling(width, height)}
>
<img draggable={false} src={Item} alt="이미지" />
</div>
);
}
return (
<div
ref={index === viewIndex ? itemRef : null}
key={crypto.randomUUID()}
css={getItemWrapperStyling(width, height)}
>
<Item />
</div>
);
})}
{children === null
? items.map((Item, index) => {
if (typeof Item === 'string') {
return (
<div
ref={index === viewIndex ? itemRef : null}
key={crypto.randomUUID()}
css={getItemWrapperStyling(width, height)}
>
<img draggable={false} src={Item} alt="이미지" />
</div>
);
}
return (
<div
ref={index === viewIndex ? itemRef : null}
key={crypto.randomUUID()}
css={getItemWrapperStyling(width, height)}
>
<Item />
</div>
);
})
: children}
</Box>
</div>
);
Expand Down

0 comments on commit 1e0a108

Please sign in to comment.