Skip to content

Commit

Permalink
[Add] Card component
Browse files Browse the repository at this point in the history
  • Loading branch information
deprecated-hongbiii committed Apr 20, 2021
1 parent c9802c4 commit 1b7f635
Show file tree
Hide file tree
Showing 7 changed files with 45,727 additions and 9,918 deletions.
35,220 changes: 35,220 additions & 0 deletions banchan/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions banchan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"styled-components": "^5.2.3",
"web-vitals": "^1.0.1"
},
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions banchan/src/components/main/CarouselSection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from 'react';
import Card from '../utils/Card';

const CarouselSection = (props) => {
const [products, setProducts] = useState([]);

useEffect(() => {
fetch(
'https://h3rb9c0ugl.execute-api.ap-northeast-2.amazonaws.com/develop/baminchan/main'
)
.then((response) => response.json())
.then((result) => setProducts(result.body))
.then((error) => console.log('error', error));
}, []);

return (
<ul>
{products.map((product) => (
<Card key={product.detail_hash} product={product} cardSize={'medium'} />
))}
</ul>
);
};

export default CarouselSection;
4 changes: 3 additions & 1 deletion banchan/src/components/main/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const MainPage = (props) => <></>;
import CarouselSection from './CarouselSection';

const MainPage = (props) => <CarouselSection />;

export default MainPage;
76 changes: 76 additions & 0 deletions banchan/src/components/utils/Card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import styled from 'styled-components';
import theme from './constant';

const Card = ({ product, cardSize }) => {
return (
<CardContainer cardSize={cardSize}>
<img src={product.image} alt="card-image" />
<CardInfoContainer>
<div className="title">
<span>{product.title}</span>
</div>
<div className="description">
<span>{product.description}</span>
</div>
<Price product={product} />
</CardInfoContainer>
</CardContainer>
);
};

const Price = ({ product }) => {
const isOnSale = !!product.n_price;
if (!isOnSale) {
return <FinalPriceSpan>{product.s_price}</FinalPriceSpan>;
}
return (
<div className="price">
<FinalPriceSpan>{product.n_price}</FinalPriceSpan>
<OriginalPriceSpan>{product.s_price}</OriginalPriceSpan>
</div>
);
};

// ============================= ● Styled components ● =============================

const CardContainer = styled.li`
width: ${(props) => (props.cardSize === 'medium' ? '308px' : '384px')};
img {
border-radius: ${theme.borders.radius};
margin-bottom: 16px;
width: ${(props) => (props.cardSize === 'medium' ? '308px' : '384px')};
}
`;

const CardInfoContainer = styled.div`
.title {
font-size: ${theme.fontSizes.S};
color: ${theme.colors.darkGray};
}
.description {
font-size: ${theme.fontSizes.XS};
color: ${theme.colors.gray};
margin: 8px 0px;
}
.price {
display: flex;
align-items: center;
}
`;

const FinalPriceSpan = styled.span`
font-size: ${theme.fontSizes.L};
font-weight: bold;
margin-right: 8px;
`;

const OriginalPriceSpan = styled.span`
font-size: ${theme.fontSizes.XS};
text-decoration: line-through;
color: ${theme.colors.lightGray};
`;

export default Card;
4 changes: 4 additions & 0 deletions banchan/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* {
box-sizing: border-box;
list-style: none;
}
Loading

0 comments on commit 1b7f635

Please sign in to comment.