Spaces:
Running
Running
Download src/components/Cart.jsx from Abanee/reactshop-bazaar: direct link, hf CLI and curl.
- Browser
- Download file 3.78 kB
-
https://huggingface.co/spaces/Abanee/reactshop-bazaar/resolve/main/src/components/Cart.jsx
- Command line
-
hf download hf://spaces/Abanee/reactshop-bazaar/src/components/Cart.jsx
-
curl -L -o Cart.jsx https://huggingface.co/spaces/Abanee/reactshop-bazaar/resolve/main/src/components/Cart.jsx
3.78 kB
| import React from 'react' | |
| const Cart = ({ show, onHide, cart, onUpdateQuantity, onRemoveFromCart, totalPrice }) => { | |
| return ( | |
| <> | |
| {show && <div className="cart-overlay" onClick={onHide}></div> | |
| <div className={`cart-sidebar ${show ? 'show' : ''}`}> | |
| <div className="d-flex flex-column h-100"> | |
| <div className="d-flex justify-content-between align-items-center p-3 border-bottom"> | |
| <h5 className="mb-0"> | |
| <i className="bi bi-cart3 me-2"></i> | |
| Shopping Cart | |
| </h5> | |
| <button | |
| className="btn btn-outline-secondary btn-sm" | |
| onClick={onHide} | |
| > | |
| <i className="bi bi-x-lg"></i> | |
| </button> | |
| </div> | |
| <div className="flex-grow-1 overflow-auto p-3"> | |
| {cart.length === 0 ? ( | |
| <div className="text-center text-muted py-5"> | |
| <i className="bi bi-cart-x display-1"></i> | |
| <p className="mt-3">Your cart is empty</p> | |
| ) : ( | |
| cart.map(item => ( | |
| <div key={item.id} className="card mb-3"> | |
| <div className="card-body"> | |
| <div className="row align-items-center"> | |
| <div className="col-3"> | |
| <img | |
| src={item.image} | |
| alt={item.title} | |
| className="img-fluid rounded" | |
| /> | |
| </div> | |
| <div className="col-9"> | |
| <h6 className="card-title text-truncate">{item.title}</h6> | |
| <div className="d-flex justify-content-between align-items-center"> | |
| <span className="fw-bold text-primary">${item.price}</span> | |
| <div className="d-flex align-items-center mt-2"> | |
| <button | |
| className="btn btn-outline-secondary btn-sm" | |
| onClick={() => onUpdateQuantity(item.id, item.quantity - 1)} | |
| > | |
| <i className="bi bi-dash"></i> | |
| </button> | |
| <span className="mx-3 fw-bold">{item.quantity}</span> | |
| <button | |
| className="btn btn-outline-secondary btn-sm" | |
| onClick={() => onUpdateQuantity(item.id, item.quantity + 1)} | |
| > | |
| <i className="bi bi-plus"></i> | |
| </button> | |
| <button | |
| className="btn btn-outline-danger btn-sm ms-2" | |
| onClick={() => onRemoveFromCart(item.id)} | |
| > | |
| <i className="bi bi-trash"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )) | |
| )} | |
| </div> | |
| {cart.length > 0 && ( | |
| <div className="border-top p-3"> | |
| <div className="d-flex justify-content-between align-items-center mb-3"> | |
| <h5 className="mb-0">Total: ${totalPrice.toFixed(2)}</h5> | |
| </div> | |
| <button className="btn btn-primary w-100"> | |
| Checkout <i className="bi bi-arrow-right ms-2"></i> | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </> | |
| ) | |
| } | |
| export default Cart |