style: Add list layout for pc view

This commit is contained in:
jhynsoo 2023-11-01 19:56:37 +09:00
parent cef53c2e80
commit e85ea41398
4 changed files with 60 additions and 8 deletions

View File

@ -1,15 +1,17 @@
import { DynamicList } from '../../styles/Common.styles';
import PostItem from '../PostItem'; import PostItem from '../PostItem';
const PostList = ({ data, page }) => { const PostList = ({ data, page }) => {
return ( return (
<> <DynamicList>
{data?.results?.map((post) => ( {data?.results?.map((post) => (
<PostItem <PostItem
dynamic
key={post?.id} key={post?.id}
post={post} post={post}
/> />
))} ))}
</> </DynamicList>
); );
}; };

View File

@ -2,23 +2,25 @@ import PhoneImage from '../../assets/phone.svg';
import { URL } from '../../API'; import { URL } from '../../API';
import * as S from '../../styles/PostItem.styles'; import * as S from '../../styles/PostItem.styles';
const PostItem = ({ post }) => { const PostItem = ({ dynamic, post }) => {
const image = post?.image || PhoneImage; const image = post?.image || PhoneImage;
const PostItemComponent = dynamic ? S.DynamicPostItem : S.PostItem;
const PostImageComponent = dynamic ? S.DynamicPostImage : S.PostImage;
return ( return (
<S.PostItem to={`${URL.post}${post?.id}`}> <PostItemComponent to={`${URL.post}${post?.id}`}>
<S.PostImage> <PostImageComponent>
<img <img
src={image} src={image}
alt={post?.product?.name} alt={post?.product?.name}
/> />
</S.PostImage> </PostImageComponent>
<S.ProductInfo> <S.ProductInfo>
<S.ProductName>{post?.product?.name}</S.ProductName> <S.ProductName>{post?.product?.name}</S.ProductName>
<S.ProductDate>{post?.written_at}</S.ProductDate> <S.ProductDate>{post?.written_at}</S.ProductDate>
<S.ProductPrice>{post?.price}</S.ProductPrice> <S.ProductPrice>{post?.price}</S.ProductPrice>
</S.ProductInfo> </S.ProductInfo>
</S.PostItem> </PostItemComponent>
); );
}; };

View File

@ -38,3 +38,12 @@ export const Input = styled.input`
caret-color: ${({ theme }) => theme.colors.primary}; caret-color: ${({ theme }) => theme.colors.primary};
} }
`; `;
export const DynamicList = styled.div`
display: flex;
gap: 20px;
@media screen and (max-width: 768px) {
flex-direction: column;
}
`;

View File

@ -1,6 +1,27 @@
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { styled } from 'styled-components'; import { styled } from 'styled-components';
export const DynamicPostItem = styled(Link)`
${({ theme }) => theme.boxShadow};
${({ theme }) => theme.hoverBorder};
${({ theme }) => theme.activeTransform};
display: flex;
flex-direction: column;
gap: 20px;
padding: 16px;
margin-bottom: 16px;
box-sizing: border-box;
text-decoration: none;
color: ${({ theme }) => theme.colors.gray900};
transition: all 0.3s ease;
@media screen and (max-width: 768px) {
flex-direction: row;
align-items: center;
width: 100%;
}
`;
export const PostItem = styled(Link)` export const PostItem = styled(Link)`
${({ theme }) => theme.boxShadow}; ${({ theme }) => theme.boxShadow};
${({ theme }) => theme.hoverBorder}; ${({ theme }) => theme.hoverBorder};
@ -8,10 +29,10 @@ export const PostItem = styled(Link)`
display: flex; display: flex;
align-items: center; align-items: center;
gap: 20px; gap: 20px;
width: 100%;
padding: 16px; padding: 16px;
margin-bottom: 16px; margin-bottom: 16px;
box-sizing: border-box; box-sizing: border-box;
width: 100%;
text-decoration: none; text-decoration: none;
color: ${({ theme }) => theme.colors.gray900}; color: ${({ theme }) => theme.colors.gray900};
transition: all 0.3s ease; transition: all 0.3s ease;
@ -38,6 +59,24 @@ export const ProductPrice = styled.div`
font-weight: 600; font-weight: 600;
`; `;
export const DynamicPostImage = styled.div`
width: 200px;
height: 200px;
border-radius: 10px;
@media screen and (max-width: 768px) {
width: 100px;
height: 100px;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 10px;
}
`;
export const PostImage = styled.div` export const PostImage = styled.div`
width: 100px; width: 100px;
height: 100px; height: 100px;