undefined / books.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
16.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Books - 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 books..."
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 BookCard({ book }) {
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">
{book.discount > 0 && (
<span className="absolute top-4 right-4 bg-red-500 text-white text-xs px-2 py-1 rounded-full">
{book.discount}% OFF
</span>
)}
<div className="flex justify-between items-start mb-4">
<img
src={book.image || `http://static.photos/books/320x240/${Math.floor(Math.random() * 100)}`}
alt={book.title}
className="w-full h-48 object-cover rounded-lg"
/>
</div>
<h3 className="text-lg font-semibold text-gray-800 mb-1">{book.title}</h3>
<p className="text-gray-500 text-sm mb-2">by {book.author}</p>
<div className="flex items-center mb-2">
{book.discount > 0 ? (
<>
<span className="text-blue-500 font-medium">${(book.price * (1 - book.discount/100)).toFixed(2)}</span>
<span className="text-gray-400 text-sm line-through ml-2">${book.price.toFixed(2)}</span>
</>
) : (
<span className="text-blue-500 font-medium">${book.price.toFixed(2)}</span>
)}
</div>
<p className="text-gray-500 text-sm mb-4">{book.description}</p>
<div className="flex justify-between items-center mb-3">
<span className="text-sm font-medium text-gray-700 capitalize">{book.category}</span>
<span className={`text-xs px-2 py-1 rounded-full ${book.stock > 10 ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`}>
{book.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 BooksPage() {
const [books, setBooks] = useState([
{
id: 1,
title: "Clean Code",
author: "Robert C. Martin",
description: "A handbook of agile software craftsmanship with practical advice on writing clean, maintainable code.",
price: 29.99,
category: "programming",
stock: 20,
discount: 10,
year: "2008",
image: "http://static.photos/books/320x240/1"
},
{
id: 2,
title: "Design Patterns",
author: "Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides",
description: "Elements of reusable object-oriented software that help you design flexible and reusable object-oriented software.",
price: 39.99,
category: "programming",
stock: 15,
discount: 0,
year: "1994",
image: "http://static.photos/books/320x240/2"
},
{
id: 3,
title: "You Don't Know JS",
author: "Kyle Simpson",
description: "Series of books diving deep into the core mechanisms of the JavaScript language.",
price: 24.99,
category: "javascript",
stock: 30,
discount: 15,
year: "2015",
image: "http://static.photos/books/320x240/3"
},
{
id: 4,
title: "The Pragmatic Programmer",
author: "Andrew Hunt, David Thomas",
description: "From journeyman to master with practical tips on software construction and philosophy of development.",
price: 34.99,
category: "programming",
stock: 25,
discount: 5,
year: "1999",
image: "http://static.photos/books/320x240/4"
},
{
id: 5,
title: "Eloquent JavaScript",
author: "Marijn Haverbeke",
description: "A modern introduction to programming that teaches you how to write beautiful, effective code.",
price: 27.99,
category: "javascript",
stock: 40,
discount: 0,
year: "2011",
image: "http://static.photos/books/320x240/5"
},
{
id: 6,
title: "Refactoring",
author: "Martin Fowler",
description: "Improving the design of existing code with techniques for improving code quality and maintainability.",
price: 42.99,
category: "programming",
stock: 12,
discount: 20,
year: "1999",
image: "http://static.photos/books/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">Books</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>Programming</option>
<option>JavaScript</option>
<option>Design</option>
<option>Algorithms</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 books..."
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 Books
</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 mr-2 text-sm">
New Releases
</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 text-sm">
Staff Picks
</button>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{books.map(book => (
<BookCard key={book.id} book={book} />
))}
</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 />
<BooksPage />
<Footer />
</div>
);
}
ReactDOM.render(<App />, document.getElementById('root'));
</script>
</body>
</html>