1๊ฐ์ sprint์ ๋! ๊ธ์์ผ!! ํ ์ฃผ๊ฐ ๋๋ฌ๋ค!
์ค๋์ ํ๊ณผ ํจ๊ป LOVE ๋ฉด๋ด์ ํ๋ฉฐ ๋ง์ ๋ถ๋ถ์ ๋๊ผ์ง๋ง
์ฒซ ํค์ค ์ฒ๋ผ ์ด๋ฒ ํ๋ก์ ํธ๊ฐ ๋ค์๋ ์ค์ง ์์, ๊ณ์ ๊ธฐ์ต์ ๋จ์
๋ด ์ฒซ!!ํ๋ก์ ํธ!๋ผ๋ ์ ์ด ์ฐธ ์๋ฟ์๋ค.
๊ทธ๋ ๊ฒ ์๊ฐํ๋ ๋ญ๊ฐ ๋ ์ ํํ๊ณ ๋ ์ ์์คํ ๋ค๋ค์ผ๊ฒ ๋ค๋ ์๊ฐ์ด ๋ค์๋ค.
๋ ์์คํ ํด์ผ์ง ๋์๋ดค์ ๋ ์ธ์ ๋ ๊ธฐ์ตํ๊ณ ์ถ์ ์๊ฐ์ผ๋ก ๋จ๊ฒ ํด์ผ์ง.
๊ทธ๋ฌ๋ ๋ ์ฆ๊ฒ๊ฒ ํ๋ณตํ๊ฒ ํ์ดํ
ํ์!!
๋์ ํ๊ณ : ๋ฒ์จ ์ผ์ฃผ์ผ์ด ์ง๋ฌ๋ค๋, ๋ฏฟ๊ธฐ์ง ์๋๋ค. ๋ ์ฆ๊ธฐ๋ฉด์ ํด์ผ๊ฒ ๋ค!
js ํ์ผ
function Modal({ children, closeModal }) {
const modalContent = useRef();
const clickOutside = e => {
if (!modalContent.current.contains(e.target)) {
closeModal();
}
};
return (
<div className="modal" onClick={clickOutside}>
<div className="modalContent" ref={modalContent}>
{children}
</div>
</div>
);
}
export default Modal;
scss ํ์ผ
.modal {
@include flexCenter;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
background-color: rgba($color: #000000, $alpha: 0.3);
.modalContent {
background-color: $bg-white;
border-radius: 15px;
}
}
{isCartModalOpen && (
<CartModal
setCartInfo={setCartInfo}
product={cartInfo}
setIsCartModalOpen={setIsCartModalOpen}
/>
function CartModal({ product, setCartInfo, setIsCartModalOpen }) {
const modalContent = useRef();
const [quantity, setQuantity] = useState(1);
const { name, price } = product;
const closeModal = () => {
setCartInfo({});
setIsCartModalOpen(false);
};
const addQuantity = () => {
setQuantity(quantity + 1);
};
const clickOutside = e => {
if (!modalContent.current.contains(e.target)) {
closeModal();
}
};
// TODO : ์ฅ๋ฐ๊ตฌ๋ ์ถ๊ฐ ์ fetch ํ๊ธฐ
const addProductToCart = () => {
closeModal();
};
return (
<div className="modal" onClick={clickOutside}>
<div className="modalContent" ref={modalContent}>
<div className="top">
<div className="productName">{name}</div>
<div className="productDetail">
<div className="price">{Number(price).toLocaleString()}์</div>
<div className="quantityContainer">
<button className="down" onClick={removeQuantity}>
-
</button>
<span className="quantity">{quantity}</span>
<button className="up" onClick={addQuantity}>
+
</button>
</div>
</div>
</div>
<div className="bottom">
<div className="totalContainer">
<h3 className="totalText">ํฉ๊ณ</h3>
<h2 className="total">
{Number(quantity * price).toLocaleString()}
<span className="unit">์</span>
</h2>
</div>
<div className="btns">
<button className="cancel btn" onClick={closeModal}>
์ทจ์
</button>
<button className="addToCart btn" onClick={addProductToCart}>
์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ
</button>
</div>
</div>
</div>
</div>
);
}
{isCartModalOpen && (
<Modal closeModal={closeModal}>
<CartModal closeModal={closeModal} product={cartInfo} />
</Modal>
}
function CartModal({ product, closeModal }) {
const [quantity, setQuantity] = useState(1);
const { name, price } = product;
const addQuantity = () => {
setQuantity(quantity + 1);
};
// TODO : ์ฅ๋ฐ๊ตฌ๋ ์ถ๊ฐ ์ fetch ํ๊ธฐ
const addProductToCart = () => {
closeModal();
};
return (
<div className="cartModal">
<div className="top">
<div className="productName">{name}</div>
<div className="productDetail">
<div className="price">{Number(price).toLocaleString()}์</div>
<div className="quantityContainer">
<button className="down" onClick={removeQuantity}>
-
</button>
<span className="quantity">{quantity}</span>
<button className="up" onClick={addQuantity}>
+
</button>
</div>
</div>
</div>
<div className="bottom">
<div className="totalContainer">
<h3 className="totalText">ํฉ๊ณ</h3>
<h2 className="total">
{Number(quantity * price).toLocaleString()}
<span className="unit">์</span>
</h2>
</div>
<div className="btns">
<button className="cancel btn" onClick={closeModal}>
์ทจ์
</button>
<button className="addToCart btn" onClick={addProductToCart}>
์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ
</button>
</div>
</div>
</div>
);
}
function Modal() {
const stopClickPropagation = e => {
e.stopPropagation();
}
return (
<div className="modalBackground" onClick={closeModal}>
<div className="modalContent" onClick={stopClickPropagation}>
function Modal() {
const clickOutside = e => {
if (!e.target.closest('.modalContent')) {
closeModal();
}
return (
<div className="modalBackground" onClick={clickOutside}>
<div className="modalContent">
function Modal() {
const modalContent = useRef();
const clickOutside = e => {
if (!modalContent.current.contains(e.target)) {
closeModal();
}
};
return (
<div className="modalBackground" onClick={clickOutside}>
<div className="modalContent" ref={modalContent}>