안녕하세요:) 개발자 우디입니다! 아래 내용 관련하여 작업 중이신 분들께 도움이되길 바라며 글을 공유하니 참고 부탁드립니다😊
(이번에 벨로그로 이사오면서 예전 글을 옮겨적었습니다. 이 점 양해 부탁드립니다!)
각 디자인 경우에 따른 속성값 설정
const streamerInfo = {
Horizontal: {
Circle: {
Mobile: { img: 32, name: 16 },
Desktop: { img: 64, name: 20 },
},
Square: {
Mobile: { img: 54, name: 16 },
Desktop: { img: 56, name: 24 },
},
},
Vertical: {
Circle: {
Mobile: { img: 80, name: 12 },
Desktop: { img: 104, name: 16 },
},
Square: {
Mobile: { img: 80, name: 12 },
Desktop: { img: 104, name: 16 },
},
},
};
이미지와 텍스트 구조가 수직/수평인지, 이미지 모양이 사각/원형인지, 사용자 접속 기기가 모바일/데스크톱인지에 따라 속성값을 다르게 적용하여 컴포넌트 구성함
const StreamerInfoContainer = styled.div`
display: flex;
flex-direction: ${props => (props.direction === 'Vertical' ? 'column' : 'row')};
row-gap: 8px;
column-gap: 8px;
width: max-content;
align-items: ${props => (props.direction === 'Vertical' ? 'center' : 'unset')};
@media screen and (min-width: 769px) {
row-gap: 14px;
column-gap: 14px;
}
`;
const StreamerImageWrapper = styled.div`
position: relative;
width: ${props => `${streamerInfo[props.direction][props.shape].Mobile.img}px`};
height: ${props => `${streamerInfo[props.direction][props.shape].Mobile.img}px`};
@media screen and (min-width: 769px) {
width: ${props => `${streamerInfo[props.direction][props.shape].Desktop.img}px`};
height: ${props => `${streamerInfo[props.direction][props.shape].Desktop.img}px`};
}
`;
const StreamerImage = styled(Image)`
border-radius: ${props => (props.shape === 'Circle' ? '50%' : '8px')};
@media screen and (min-width: 769px) {
border-radius: ${props => (props.shape === 'Circle' ? '50%' : '16px')};
}
`;
const StreamerInfoTextWrapper = styled.div`
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: ${props => (props.direction === 'Vertical' ? 'center' : 'unset')};
`;
const StreamerName = styled.div`
width: max-content;
font-weight: 500;
font-size: ${props => `${streamerInfo[props.direction][props.shape].Mobile.name}px`};
@media screen and (min-width: 769px) {
font-size: ${props => `${streamerInfo[props.direction][props.shape].Desktop.name}px`};
}
`;
const StreamerClipNum = styled.div`
display: ${props => (props.isClipNum ? 'block' : 'none')};
font-size: 14px;
font-weight: 400;
color: ${Colors.gray[400]};
@media screen and (min-width: 769px) {
font-size: 18px;
}
`;
컴포넌트 props로 direction과 shape을 받은 후, 적절한 디자인 출력
export const StreamerInfo = props => {
const streamerInfoData = props.data;
return (
<Link passHref href={`/streamer/${streamerInfoData.streamerName}`}>
<StreamerInfoContainer direction={props.direction}>
<StreamerImageWrapper direction={props.direction} shape={props.shape}>
<StreamerImage
src={streamerInfoData.profileUrl}
alt="streamerProfileUrl"
layout="fill"
shape={props.shape}
/>
</StreamerImageWrapper>
<StreamerInfoTextWrapper direction={props.direction}>
<StreamerName direction={props.direction} shape={props.shape}>
{streamerInfoData.streamerName}
</StreamerName>
<StreamerClipNum isClipNum={streamerInfoData.clipNum}>
{streamerInfoData.clipNum}
</StreamerClipNum>
</StreamerInfoTextWrapper>
</StreamerInfoContainer>
</Link>
);
};