undefined / products.html
zeeleo007's picture
add compare and my bag bottom in website, book and product and make the same layout of these three add noen flip hover effects on cards
07cd639 verified
Raw History Blame Contribute Delete
15.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Products - WebBag Wonders</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body class="bg-gray-50">
<div id="root"></div>
<script type="text/babel">
const { useState } = React;
function Navbar() {
return (
<nav className="bg-white shadow-sm py-4 px-6 flex items-center justify-between sticky top-0 z-50">
<div className="flex items-center space-x-2">
<i className="fas fa-briefcase text-blue-500 text-2xl"></i>
<span className="text-xl font-semibold text-gray-800">WebBag Wonders</span>
</div>
<div className="flex-1 max-w-md mx-4">
<div className="relative">
<input
type="text"
placeholder="Search products..."
className="w-full py-2 px-4 rounded-full border border-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-300"
/>
<button className="absolute right-3 top-2 text-gray-400">
<i className="fas fa-search"></i>
</button>
</div>
</div>
<div className="flex items-center space-x-4">
<button className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-full text-sm font-medium">
Sign In
</button>
<div className="w-10 h-10 rounded-full bg-gray-200 flex items-center justify-center">
<i className="fas fa-user text-gray-600"></i>
</div>
</div>
</nav>
);
}
function ProductCard({ product }) {
const [isFavorite, setIsFavorite] = useState(false);
const [inBag, setInBag] = useState(false);
const [compare, setCompare] = useState(false);
return (
<div className="bg-white rounded-xl p-6 shadow-md border border-gray-100 relative hover:shadow-lg hover:-translate-y-1 transition-all duration-300">
{product.discount > 0 && (
<span className="absolute top-4 right-4 bg-red-500 text-white text-xs px-2 py-1 rounded-full">
{product.discount}% OFF
</span>
)}
<div className="flex justify-between items-start mb-4">
<img
src={product.image || `http://static.photos/products/320x240/${Math.floor(Math.random() * 100)}`}
alt={product.title}
className="w-full h-48 object-cover rounded-lg"
/>
</div>
<h3 className="text-lg font-semibold text-gray-800 mb-1">{product.name}</h3>
<div className="flex items-center mb-2">
{product.discount > 0 ? (
<>
<span className="text-blue-500 font-medium">${(product.price * (1 - product.discount/100)).toFixed(2)}</span>
<span className="text-gray-400 text-sm line-through ml-2">${product.price.toFixed(2)}</span>
</>
) : (
<span className="text-blue-500 font-medium">${product.price.toFixed(2)}</span>
)}
</div>
<p className="text-gray-500 text-sm mb-4">{product.description}</p>
<div className="flex justify-between items-center mb-3">
<span className="text-sm font-medium text-gray-700 capitalize">{product.category}</span>
<span className={`text-xs px-2 py-1 rounded-full ${product.stock > 10 ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`}>
{product.stock > 10 ? 'In Stock' : 'Low Stock'}
</span>
</div>
<div className="flex justify-between items-center">
<button
onClick={() => setCompare(!compare)}
className={`flex items-center text-sm ${compare ? 'text-purple-600' : 'text-gray-500 hover:text-purple-500'}`}
>
<i className={`fas fa-exchange-alt mr-1 ${compare ? 'text-purple-600' : 'text-gray-500'}`}></i>
{compare ? 'Comparing' : 'Compare'}
</button>
<button
onClick={() => setInBag(!inBag)}
className={`flex items-center text-sm ${inBag ? 'text-blue-600' : 'text-gray-500 hover:text-blue-500'}`}
>
<i className={`fas fa-shopping-bag mr-1 ${inBag ? 'text-blue-600' : 'text-gray-500'}`}></i>
{inBag ? 'In Bag' : 'Add to Bag'}
</button>
<button
onClick={() => setIsFavorite(!isFavorite)}
className={`p-2 ${isFavorite ? 'text-red-500' : 'text-gray-400 hover:text-red-500'}`}
>
<i className={`fas ${isFavorite ? 'fa-heart' : 'fa-heart'}`}></i>
</button>
</div>
</div>
);
}
function ProductsPage() {
const [products, setProducts] = useState([
{
id: 1,
name: "Wireless Headphones",
description: "Noise cancelling wireless headphones with 30h battery life and built-in microphone",
price: 199.99,
category: "electronics",
stock: 45,
discount: 15,
image: "http://static.photos/products/320x240/1"
},
{
id: 2,
name: "Mechanical Keyboard",
description: "RGB backlit mechanical gaming keyboard with customizable macros",
price: 89.99,
category: "accessories",
stock: 32,
discount: 0,
image: "http://static.photos/products/320x240/2"
},
{
id: 3,
name: "Smart Watch",
description: "Fitness tracker with heart rate monitor and sleep tracking",
price: 149.99,
category: "wearables",
stock: 18,
discount: 10,
image: "http://static.photos/products/320x240/3"
},
{
id: 4,
name: "Laptop Stand",
description: "Adjustable ergonomic laptop stand with cooling fan",
price: 39.99,
category: "accessories",
stock: 56,
discount: 5,
image: "http://static.photos/products/320x240/4"
},
{
id: 5,
name: "Bluetooth Speaker",
description: "Portable waterproof bluetooth speaker with 20h battery",
price: 59.99,
category: "electronics",
stock: 24,
discount: 20,
image: "http://static.photos/products/320x240/5"
},
{
id: 6,
name: "Wireless Mouse",
description: "Ergonomic wireless mouse with silent clicks and adjustable DPI",
price: 29.99,
category: "accessories",
stock: 78,
discount: 0,
image: "http://static.photos/products/320x240/6"
}
]);
return (
<div className="container mx-auto px-4 py-8">
<div className="flex flex-col md:flex-row justify-between items-start md:items-center mb-6">
<h1 className="text-2xl font-bold text-gray-800">Products</h1>
<div className="flex space-x-4 mt-4 md:mt-0">
<div className="relative">
<select className="appearance-none bg-white border border-gray-300 rounded-lg px-4 py-2 pr-8 focus:outline-none focus:ring-2 focus:ring-blue-300 text-sm">
<option>All Categories</option>
<option>Electronics</option>
<option>Accessories</option>
<option>Wearables</option>
</select>
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
<i className="fas fa-chevron-down text-xs"></i>
</div>
</div>
<div className="relative w-64">
<input
type="text"
placeholder="Search products..."
className="w-full py-2 px-4 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-300 text-sm"
/>
<button className="absolute right-3 top-2 text-gray-400">
<i className="fas fa-search"></i>
</button>
</div>
</div>
</div>
<div className="mb-6 flex overflow-x-auto pb-2">
<button className="whitespace-nowrap px-4 py-2 bg-blue-500 text-white rounded-lg mr-2 text-sm">
All Products
</button>
<button className="whitespace-nowrap px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg mr-2 text-sm">
On Sale
</button>
<button className="whitespace-nowrap px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg mr-2 text-sm">
New Arrivals
</button>
<button className="whitespace-nowrap px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg mr-2 text-sm">
Best Sellers
</button>
<button className="whitespace-nowrap px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg text-sm">
Top Rated
</button>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{products.map(product => (
<ProductCard key={product.id} product={product} />
))}
</div>
<div className="mt-8 flex justify-center">
<nav className="inline-flex rounded-md shadow">
<button className="px-3 py-2 rounded-l-md border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
<i className="fas fa-chevron-left"></i>
</button>
<button className="px-4 py-2 border-t border-b border-gray-300 bg-white text-blue-600 font-medium">
1
</button>
<button className="px-4 py-2 border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
2
</button>
<button className="px-4 py-2 border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
3
</button>
<button className="px-3 py-2 rounded-r-md border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
<i className="fas fa-chevron-right"></i>
</button>
</nav>
</div>
</div>
);
}
function Footer() {
return (
<footer className="bg-white border-t border-gray-200 py-8 mt-12">
<div className="container mx-auto px-4">
<div className="flex flex-col md:flex-row justify-between items-center">
<div className="mb-4 md:mb-0">
<div className="flex items-center space-x-2">
<i className="fas fa-briefcase text-blue-500 text-xl"></i>
<span className="text-lg font-semibold text-gray-800">WebBag Wonders</span>
</div>
<p className="text-gray-500 text-sm mt-2">Your digital companion for all things web</p>
</div>
<div className="flex space-x-6">
<a href="#" className="text-gray-500 hover:text-blue-500">
<i className="fab fa-twitter"></i>
</a>
<a href="#" className="text-gray-500 hover:text-blue-500">
<i className="fab fa-facebook"></i>
</a>
<a href="#" className="text-gray-500 hover:text-blue-500">
<i className="fab fa-instagram"></i>
</a>
<a href="#" className="text-gray-500 hover:text-blue-500">
<i className="fab fa-github"></i>
</a>
</div>
</div>
<div className="border-t border-gray-200 mt-6 pt-6 text-center text-gray-500 text-sm">
<p>© 2023 WebBag Wonders. All rights reserved.</p>
</div>
</div>
</footer>
);
}
function App() {
return (
<div className="min-h-screen flex flex-col">
<Navbar />
<ProductsPage />
<Footer />
</div>
);
}
ReactDOM.render(<App />, document.getElementById('root'));
</script>
</body>
</html>