Skip to content

Commit

Permalink
feat: 카드 컴포넌트 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
cjy3458 committed Aug 26, 2024
1 parent 96abdee commit 99da85f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/components/home/homeRecentTales/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,28 @@ const getRandomColorPair = () => {
};

const Card = (props: CardProps) => {
const cards = Array.from({ length: 3 }, (_, index) => {
const [backgroundColor1, backgroundColor2, height, imgSrc] =
getRandomColorPair();
return {
key: index,
backgroundColor1,
backgroundColor2,
height,
imgSrc,
};
});
const [backgroundColor1, backgroundColor2, height, imgSrc] =
getRandomColorPair();

return (
<>
{cards.map(
({ key, backgroundColor1, backgroundColor2, height, imgSrc }) => (
<S.CardContainer
key={key}
height={height}
backgroundColor1={backgroundColor1}
backgroundColor2={backgroundColor2}
>
<S.CardWrapper>
<S.TitleWrapper>
<S.CardTitle>사과나무 위에 사과가 있다</S.CardTitle>
<S.CardCreatedAt>2024/08/26</S.CardCreatedAt>
</S.TitleWrapper>
{props.btnText ? (
<button onClick={props.onClick}>{props.btnText}</button>
) : (
<S.CardImg src={imgSrc} />
)}
</S.CardWrapper>
</S.CardContainer>
)
)}
<S.CardContainer
height={height}
backgroundColor1={backgroundColor1}
backgroundColor2={backgroundColor2}
>
<S.CardWrapper>
<S.TitleWrapper>
<S.CardTitle>사과나무 위에 사과가 있다</S.CardTitle>
<S.CardCreatedAt>2024/08/26</S.CardCreatedAt>
</S.TitleWrapper>
{props.btnText ? (
<button onClick={props.onClick}>{props.btnText}</button>
) : (
<S.CardImg src={imgSrc} />
)}
</S.CardWrapper>
</S.CardContainer>
</>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/tales/createMain/CreateMain.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const OptionContainer = styled.div`
justify-content: space-evenly;
align-items: center;
@media (max-width: 600px) {
width: 100%;
flex-direction: column;
flex-wrap: wrap;
gap: 1.5rem;
}
Expand Down

0 comments on commit 99da85f

Please sign in to comment.