diff --git a/shopping-cart/src/Cart.jsx b/shopping-cart/src/Cart.jsx index e183976..21d8b6c 100644 --- a/shopping-cart/src/Cart.jsx +++ b/shopping-cart/src/Cart.jsx @@ -22,16 +22,18 @@ function Bag({ cartKeys, cart, setCart }) { return ( <> {cartKeys.length > 0 ? ( -
-

Cart

- {cartKeys.map((key, index) => ( - - ))} +
+

Cart

+
+ {cartKeys.map((key, index) => ( + + ))} +
) : (

Your cart is empty

@@ -68,32 +70,40 @@ function CartItem({ item, cart, setCart }) { const { title, price, image, qty } = item; return ( -
- {title} -
-

{title}

-

Price: ${currencyFormat(price)} x

-

Qty: {qty}

-
-
- -

{qty}

- -
-
-

total: ${currencyFormat(qty * price)}

- +
+ {title} +
+
+

{title}

+

Price: ${currencyFormat(price)} x

+
+
+ + + +
+
+

total: ${currencyFormat(qty * price)}

+ +
); } +function QuantityInput({ item, cart, setCart }) { + function handleChange(e) { + const newQty = e.target.value; + let obj = { ...cart }; + obj[item.id].qty = newQty; + setCart(obj); + } + + return ; +} + function increaseQty(item, cart, setCart) { if (cart[item.id]) { let obj = { ...cart }; @@ -134,4 +144,10 @@ OrderSummary.propTypes = { cart: PropTypes.object, }; +QuantityInput.propTypes = { + item: PropTypes.object, + cart: PropTypes.object, + setCart: PropTypes.func, +}; + export default Cart; diff --git a/shopping-cart/src/components/navbar.jsx b/shopping-cart/src/components/navbar.jsx index 8871061..6c0c204 100644 --- a/shopping-cart/src/components/navbar.jsx +++ b/shopping-cart/src/components/navbar.jsx @@ -15,7 +15,7 @@ export default function Navbar({ cartItems }) {

{sumCartItems}

) : ( - + )} ); diff --git a/shopping-cart/src/css/cart.module.css b/shopping-cart/src/css/cart.module.css index 8701719..2630488 100644 --- a/shopping-cart/src/css/cart.module.css +++ b/shopping-cart/src/css/cart.module.css @@ -4,5 +4,57 @@ } .summary { - margin-right: 1.5rem; + margin-right: 3rem; + padding: 1rem; + display: inline-block; + min-width: 250px; +} + +.fullwidth { + width: 100%; +} + +.card { + display: flex; + flex-direction: column; + margin: 0 2rem; + justify-content: center; + align-items: center; +} + +.cartItems { + display: flex; + flex-direction: column; + gap: 2.5rem; + align-items: space-between; + justify-content: space-between; + align-content: flex-start; +} + +.cartItem { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); + background-color: gray; +} + +.qtybtn { + display: flex; +} + +.qtyp { + font-size: 1.3rem; + padding: 0.5rem; + margin: 0.5rem; +} + +.img { + width: 100%; + max-height: 300px; + vertical-align: middle; + object-fit: contain; + float: left; +} + +.header { + margin: 1rem; } diff --git a/shopping-cart/src/css/index.css b/shopping-cart/src/css/index.css index b1f74de..cf217eb 100644 --- a/shopping-cart/src/css/index.css +++ b/shopping-cart/src/css/index.css @@ -1,10 +1,10 @@ :root { - font-family: "Roboto Condensed", Inter, system-ui, sans-serif; + font-family: Inter, system-ui, sans-serif; line-height: 1.5; font-weight: 400; - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); + /*color-scheme: light dark;*/ + /*color: rgba(255, 255, 255, 0.87);*/ /*background-color: #242424;*/ font-synthesis: none; diff --git a/shopping-cart/src/utils/currency.js b/shopping-cart/src/utils/currency.js index 03bd066..50589a4 100644 --- a/shopping-cart/src/utils/currency.js +++ b/shopping-cart/src/utils/currency.js @@ -1,3 +1,6 @@ export function currencyFormat(str) { - return (str / 100).toFixed(2); + return (str / 100) + .toFixed(2) + .toString() + .replace(/\B(?=(\d{3})+(?!\d))/g, ","); }