Spaces:
Running
Running
create a e-commerce website using reactjs ,bootsrap
Browse files- README.md +6 -3
- components/navbar.js +24 -0
- index.html +15 -19
- package.json +21 -0
- script.js +22 -0
- src/App.css +62 -0
- src/App.jsx +87 -0
- src/components/Cart.jsx +95 -0
- src/components/Header.jsx +29 -0
- src/components/ProductCard.jsx +59 -0
- src/components/ProductGrid.jsx +16 -0
- src/main.jsx +11 -0
- style.css +22 -18
- vite.config.js +9 -0
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: ⚡
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: purple
|
|
|
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ReactShop Bazaar 🛍️
|
|
|
|
| 3 |
colorFrom: green
|
| 4 |
colorTo: purple
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
components/navbar.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
nav {
|
| 7 |
+
backdrop-filter: blur(10px);
|
| 8 |
+
-webkit-backdrop-filter: blur(10px);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.theme-toggle {
|
| 12 |
+
transition: transform 0.3s ease;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.theme-toggle:hover {
|
| 16 |
+
transform: rotate(30deg);
|
| 17 |
+
}
|
| 18 |
+
</style>
|
| 19 |
+
<nav class="sticky top-0 z-50 bg-white/80 dark:bg-gray-900/80 border-b border-gray-200 dark:border-gray-800">
|
| 20 |
+
<div class="container mx-auto px-4">
|
| 21 |
+
<div class="flex items-center justify-between h-16">
|
| 22 |
+
<a href="/" class="flex items-center space-x-2">
|
| 23 |
+
<div class="w-8 h-8 rounded-lg bg-primary-500 flex items-center justify-center">
|
| 24 |
+
<i data-feather="droplet" class="
|
index.html
CHANGED
|
@@ -1,19 +1,15 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
</p>
|
| 17 |
-
</div>
|
| 18 |
-
</body>
|
| 19 |
-
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>ReactShop Bazaar 🛍️</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div id="root"></div>
|
| 12 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 13 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 14 |
+
</body>
|
| 15 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```json
|
| 2 |
+
{
|
| 3 |
+
"name": "reactshop-bazaar",
|
| 4 |
+
"version": "1.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"preview": "vite preview"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"react": "^18.2.0",
|
| 13 |
+
"react-dom": "^18.2.0",
|
| 14 |
+
"bootstrap": "^5.3.0"
|
| 15 |
+
},
|
| 16 |
+
"devDependencies": {
|
| 17 |
+
"@vitejs/plugin-react": "^4.0.0",
|
| 18 |
+
"vite": "^4.4.0"
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
```
|
script.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Theme toggle functionality
|
| 2 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 3 |
+
// Check for saved theme preference or use system preference
|
| 4 |
+
const savedTheme = localStorage.getItem('theme');
|
| 5 |
+
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 6 |
+
|
| 7 |
+
if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) {
|
| 8 |
+
document.documentElement.classList.add('dark');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// Theme toggle button event listener will be handled in navbar component
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
// Utility function to toggle theme
|
| 15 |
+
function toggleTheme() {
|
| 16 |
+
const html = document.documentElement;
|
| 17 |
+
html.classList.toggle('dark');
|
| 18 |
+
|
| 19 |
+
// Save preference to localStorage
|
| 20 |
+
const isDark = html.classList.contains('dark');
|
| 21 |
+
localStorage.setItem('theme', isDark ? 'dark' : 'light');
|
| 22 |
+
}
|
src/App.css
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.App {
|
| 2 |
+
min-height: 100vh;
|
| 3 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
.product-card {
|
| 7 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 8 |
+
border: none;
|
| 9 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
.product-card:hover {
|
| 13 |
+
transform: translateY(-5px);
|
| 14 |
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.cart-sidebar {
|
| 18 |
+
position: fixed;
|
| 19 |
+
top: 0;
|
| 20 |
+
right: -400px;
|
| 21 |
+
width: 400px;
|
| 22 |
+
height: 100vh;
|
| 23 |
+
background: white;
|
| 24 |
+
box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
|
| 25 |
+
transition: right 0.3s ease;
|
| 26 |
+
z-index: 1050;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.cart-sidebar.show {
|
| 30 |
+
right: 0;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.cart-overlay {
|
| 34 |
+
position: fixed;
|
| 35 |
+
top: 0;
|
| 36 |
+
left: 0;
|
| 37 |
+
width: 100vw;
|
| 38 |
+
height: 100vh;
|
| 39 |
+
background: rgba(0, 0, 0, 0.5);
|
| 40 |
+
z-index: 1040;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.product-image {
|
| 44 |
+
height: 200px;
|
| 45 |
+
object-fit: contain;
|
| 46 |
+
padding: 1rem;
|
| 47 |
+
background: #f8f9fa;
|
| 48 |
+
border-radius: 8px;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.rating {
|
| 52 |
+
color: #ffc107;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.btn-primary {
|
| 56 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 57 |
+
border: none;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.btn-primary:hover {
|
| 61 |
+
background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
|
| 62 |
+
}
|
src/App.jsx
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react'
|
| 2 |
+
import Header from './components/Header'
|
| 3 |
+
import ProductGrid from './components/ProductGrid'
|
| 4 |
+
import Cart from './components/Cart'
|
| 5 |
+
import './App.css'
|
| 6 |
+
|
| 7 |
+
function App() {
|
| 8 |
+
const [cart, setCart] = useState([])
|
| 9 |
+
const [showCart, setShowCart] = useState(false)
|
| 10 |
+
const [products, setProducts] = useState([])
|
| 11 |
+
|
| 12 |
+
useEffect(() => {
|
| 13 |
+
// Fetch products from Fake Store API
|
| 14 |
+
fetch('https://fakestoreapi.com/products')
|
| 15 |
+
.then(res => res.json())
|
| 16 |
+
.then(data => setProducts(data))
|
| 17 |
+
}, [])
|
| 18 |
+
|
| 19 |
+
const addToCart = (product) => {
|
| 20 |
+
setCart(prevCart => {
|
| 21 |
+
const existingItem = prevCart.find(item => item.id === product.id)
|
| 22 |
+
if (existingItem) {
|
| 23 |
+
return prevCart.map(item =>
|
| 24 |
+
item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item
|
| 25 |
+
)
|
| 26 |
+
}
|
| 27 |
+
return [...prevCart, { ...product, quantity: 1 }]
|
| 28 |
+
})
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
const removeFromCart = (productId) => {
|
| 32 |
+
setCart(prevCart => prevCart.filter(item => item.id !== productId))
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
const updateQuantity = (productId, quantity) => {
|
| 36 |
+
if (quantity === 0) {
|
| 37 |
+
removeFromCart(productId)
|
| 38 |
+
} else {
|
| 39 |
+
setCart(prevCart =>
|
| 40 |
+
prevCart.map(item =>
|
| 41 |
+
item.id === productId ? { ...item, quantity } : item
|
| 42 |
+
)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const getTotalItems = () => {
|
| 48 |
+
return cart.reduce((total, item) => total + item.quantity, 0)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
const getTotalPrice = () => {
|
| 52 |
+
return cart.reduce((total, item) => total + (item.price * item.quantity), 0)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return (
|
| 56 |
+
<div className="App">
|
| 57 |
+
<Header
|
| 58 |
+
cartItemsCount={getTotalItems()}
|
| 59 |
+
onCartClick={() => setShowCart(true)}
|
| 60 |
+
/>
|
| 61 |
+
|
| 62 |
+
<main className="container-fluid py-4">
|
| 63 |
+
<div className="row">
|
| 64 |
+
<div className="col-12">
|
| 65 |
+
<div className="text-center mb-5">
|
| 66 |
+
<h1 className="display-4 fw-bold text-primary">ReactShop Bazaar</h1>
|
| 67 |
+
<p className="lead text-muted">Your one-stop shop for everything amazing! 🛍️</p>
|
| 68 |
+
</div>
|
| 69 |
+
|
| 70 |
+
<ProductGrid products={products} onAddToCart={addToCart} />
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</main>
|
| 74 |
+
|
| 75 |
+
<Cart
|
| 76 |
+
show={showCart}
|
| 77 |
+
onHide={() => setShowCart(false)}
|
| 78 |
+
cart={cart}
|
| 79 |
+
onUpdateQuantity={updateQuantity}
|
| 80 |
+
onRemoveFromCart={removeFromCart}
|
| 81 |
+
totalPrice={getTotalPrice()}
|
| 82 |
+
/>
|
| 83 |
+
</div>
|
| 84 |
+
)
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
export default App
|
src/components/Cart.jsx
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
|
| 3 |
+
const Cart = ({ show, onHide, cart, onUpdateQuantity, onRemoveFromCart, totalPrice }) => {
|
| 4 |
+
return (
|
| 5 |
+
<>
|
| 6 |
+
{show && <div className="cart-overlay" onClick={onHide}></div>
|
| 7 |
+
|
| 8 |
+
<div className={`cart-sidebar ${show ? 'show' : ''}`}>
|
| 9 |
+
<div className="d-flex flex-column h-100">
|
| 10 |
+
<div className="d-flex justify-content-between align-items-center p-3 border-bottom">
|
| 11 |
+
<h5 className="mb-0">
|
| 12 |
+
<i className="bi bi-cart3 me-2"></i>
|
| 13 |
+
Shopping Cart
|
| 14 |
+
</h5>
|
| 15 |
+
<button
|
| 16 |
+
className="btn btn-outline-secondary btn-sm"
|
| 17 |
+
onClick={onHide}
|
| 18 |
+
>
|
| 19 |
+
<i className="bi bi-x-lg"></i>
|
| 20 |
+
</button>
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
<div className="flex-grow-1 overflow-auto p-3">
|
| 24 |
+
{cart.length === 0 ? (
|
| 25 |
+
<div className="text-center text-muted py-5">
|
| 26 |
+
<i className="bi bi-cart-x display-1"></i>
|
| 27 |
+
<p className="mt-3">Your cart is empty</p>
|
| 28 |
+
) : (
|
| 29 |
+
cart.map(item => (
|
| 30 |
+
<div key={item.id} className="card mb-3">
|
| 31 |
+
<div className="card-body">
|
| 32 |
+
<div className="row align-items-center">
|
| 33 |
+
<div className="col-3">
|
| 34 |
+
<img
|
| 35 |
+
src={item.image}
|
| 36 |
+
alt={item.title}
|
| 37 |
+
className="img-fluid rounded"
|
| 38 |
+
/>
|
| 39 |
+
</div>
|
| 40 |
+
|
| 41 |
+
<div className="col-9">
|
| 42 |
+
<h6 className="card-title text-truncate">{item.title}</h6>
|
| 43 |
+
<div className="d-flex justify-content-between align-items-center">
|
| 44 |
+
<span className="fw-bold text-primary">${item.price}</span>
|
| 45 |
+
|
| 46 |
+
<div className="d-flex align-items-center mt-2">
|
| 47 |
+
<button
|
| 48 |
+
className="btn btn-outline-secondary btn-sm"
|
| 49 |
+
onClick={() => onUpdateQuantity(item.id, item.quantity - 1)}
|
| 50 |
+
>
|
| 51 |
+
<i className="bi bi-dash"></i>
|
| 52 |
+
</button>
|
| 53 |
+
|
| 54 |
+
<span className="mx-3 fw-bold">{item.quantity}</span>
|
| 55 |
+
|
| 56 |
+
<button
|
| 57 |
+
className="btn btn-outline-secondary btn-sm"
|
| 58 |
+
onClick={() => onUpdateQuantity(item.id, item.quantity + 1)}
|
| 59 |
+
>
|
| 60 |
+
<i className="bi bi-plus"></i>
|
| 61 |
+
</button>
|
| 62 |
+
|
| 63 |
+
<button
|
| 64 |
+
className="btn btn-outline-danger btn-sm ms-2"
|
| 65 |
+
onClick={() => onRemoveFromCart(item.id)}
|
| 66 |
+
>
|
| 67 |
+
<i className="bi bi-trash"></i>
|
| 68 |
+
</button>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
))
|
| 75 |
+
)}
|
| 76 |
+
</div>
|
| 77 |
+
|
| 78 |
+
{cart.length > 0 && (
|
| 79 |
+
<div className="border-top p-3">
|
| 80 |
+
<div className="d-flex justify-content-between align-items-center mb-3">
|
| 81 |
+
<h5 className="mb-0">Total: ${totalPrice.toFixed(2)}</h5>
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<button className="btn btn-primary w-100">
|
| 85 |
+
Checkout <i className="bi bi-arrow-right ms-2"></i>
|
| 86 |
+
</button>
|
| 87 |
+
</div>
|
| 88 |
+
)}
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
</>
|
| 92 |
+
)
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
export default Cart
|
src/components/Header.jsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
|
| 3 |
+
const Header = ({ cartItemsCount, onCartClick }) => {
|
| 4 |
+
return (
|
| 5 |
+
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
|
| 6 |
+
<div className="container">
|
| 7 |
+
<a className="navbar-brand fw-bold" href="#">
|
| 8 |
+
<i className="bi bi-cart3 me-2"></i>
|
| 9 |
+
ReactShop Bazaar
|
| 10 |
+
</a>
|
| 11 |
+
|
| 12 |
+
<div className="navbar-nav ms-auto">
|
| 13 |
+
<button
|
| 14 |
+
className="btn btn-outline-light position-relative"
|
| 15 |
+
onClick={onCartClick}
|
| 16 |
+
>
|
| 17 |
+
<i className="bi bi-cart3"></i>
|
| 18 |
+
{cartItemsCount > 0 && (
|
| 19 |
+
<span className="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
|
| 20 |
+
{cartItemsCount}
|
| 21 |
+
</span>
|
| 22 |
+
</button>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
)
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export default Header
|
src/components/ProductCard.jsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
|
| 3 |
+
const ProductCard = ({ product, onAddToCart }) => {
|
| 4 |
+
const renderStars = (rating) => {
|
| 5 |
+
const stars = []
|
| 6 |
+
const fullStars = Math.floor(rating)
|
| 7 |
+
const hasHalfStar = rating % 1 !== 0
|
| 8 |
+
|
| 9 |
+
for (let i = 0; i < fullStars; i++) {
|
| 10 |
+
stars.push(<i key={i} className="bi bi-star-fill"></i>)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (hasHalfStar) {
|
| 14 |
+
stars.push(<i key="half" className="bi bi-star-half"></i>)
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const emptyStars = 5 - Math.ceil(rating)
|
| 18 |
+
for (let i = 0; i < emptyStars; i++) {
|
| 19 |
+
stars.push(<i key={`empty-${i}`} className="bi bi-star"></i>)
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
return stars
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
return (
|
| 26 |
+
<div className="card product-card h-100">
|
| 27 |
+
<img
|
| 28 |
+
src={product.image}
|
| 29 |
+
className="card-img-top product-image"
|
| 30 |
+
alt={product.title}
|
| 31 |
+
/>
|
| 32 |
+
<div className="card-body d-flex flex-column">
|
| 33 |
+
<h6 className="card-title text-truncate">{product.title}</h6>
|
| 34 |
+
<p className="card-text text-muted small flex-grow-1">
|
| 35 |
+
{product.description.substring(0, 100)}...
|
| 36 |
+
</p>
|
| 37 |
+
|
| 38 |
+
<div className="d-flex align-items-center mb-2">
|
| 39 |
+
<div className="rating me-2">
|
| 40 |
+
{renderStars(product.rating.rate)}
|
| 41 |
+
</div>
|
| 42 |
+
<small className="text-muted">({product.rating.count})</small>
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
<div className="d-flex justify-content-between align-items-center mt-auto">
|
| 46 |
+
<span className="h5 text-primary mb-0">${product.price}</span>
|
| 47 |
+
<button
|
| 48 |
+
className="btn btn-primary btn-sm"
|
| 49 |
+
onClick={() => onAddToCart(product)}
|
| 50 |
+
>
|
| 51 |
+
<i className="bi bi-cart-plus"></i>
|
| 52 |
+
</button>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
export default ProductCard
|
src/components/ProductGrid.jsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import ProductCard from './ProductCard'
|
| 3 |
+
|
| 4 |
+
const ProductGrid = ({ products, onAddToCart }) => {
|
| 5 |
+
return (
|
| 6 |
+
<div className="row g-4">
|
| 7 |
+
{products.map(product => (
|
| 8 |
+
<div key={product.id} className="col-md-6 col-lg-4 col-xl-3">
|
| 9 |
+
<ProductCard product={product} onAddToCart={onAddToCart} />
|
| 10 |
+
</div>
|
| 11 |
+
))}
|
| 12 |
+
</div>
|
| 13 |
+
)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export default ProductGrid
|
src/main.jsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import ReactDOM from 'react-dom/client'
|
| 3 |
+
import App from './App.jsx'
|
| 4 |
+
import 'bootstrap/dist/css/bootstrap.min.css'
|
| 5 |
+
import 'bootstrap/dist/js/bootstrap.bundle.min.js'
|
| 6 |
+
|
| 7 |
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
| 8 |
+
<React.StrictMode>
|
| 9 |
+
<App />
|
| 10 |
+
</React.StrictMode>
|
| 11 |
+
)
|
style.css
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
font-size: 15px;
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
padding: 16px;
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
.
|
| 27 |
-
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
| 2 |
+
|
| 3 |
body {
|
| 4 |
+
font-family: 'Inter', sans-serif;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
/* Smooth transitions for dark mode */
|
| 8 |
+
* {
|
| 9 |
+
transition: background-color 0.3s ease, border-color 0.3s ease;
|
| 10 |
}
|
| 11 |
|
| 12 |
+
/* Custom scrollbar */
|
| 13 |
+
::-webkit-scrollbar {
|
| 14 |
+
width: 8px;
|
| 15 |
}
|
| 16 |
|
| 17 |
+
::-webkit-scrollbar-track {
|
| 18 |
+
background: #f1f1f1;
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
+
::-webkit-scrollbar-thumb {
|
| 22 |
+
background: #6366f1;
|
| 23 |
+
border-radius: 4px;
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
+
.dark ::-webkit-scrollbar-track {
|
| 27 |
+
background: #1f2937;
|
| 28 |
}
|
| 29 |
+
|
| 30 |
+
.dark ::-webkit-scrollbar-thumb {
|
| 31 |
+
background: #818cf8;
|
| 32 |
+
}
|
vite.config.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'vite'
|
| 2 |
+
import react from '@vitejs/plugin-react'
|
| 3 |
+
|
| 4 |
+
export default defineConfig({
|
| 5 |
+
plugins: [react()],
|
| 6 |
+
server: {
|
| 7 |
+
port: 3000
|
| 8 |
+
}
|
| 9 |
+
})
|