mouris030's picture
Upload components/Header.js with huggingface_hub
1e3f08b verified
Raw History Blame Contribute Delete
7.06 kB
import { useState, useEffect } from 'react';
import Link from 'next/link';
export default function Header({ cartCount, setIsCartOpen }) {
const [searchTerm, setSearchTerm] = useState('');
const [isMenuOpen, setIsMenuOpen] = useState(false);
const handleSearch = (e) => {
e.preventDefault();
if (searchTerm.trim()) {
window.location.href = `/?search=${encodeURIComponent(searchTerm)}`;
}
};
return (
<header className="sticky top-0 z-50">
{/* Top Banner */}
<div className="bg-amazon-dark text-white py-1 px-4 text-xs text-center">
<span>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noopener noreferrer" className="text-amazon-yellow hover:underline">
Built with anycoder
</a>
{' '} - The best AI-powered coding assistant
</span>
</div>
{/* Main Header */}
<div className="bg-amazon-light text-white">
<div className="max-w-7xl mx-auto px-4">
<div className="flex items-center justify-between h-16">
{/* Logo */}
<Link href="/" className="flex items-center space-x-2">
<div className="bg-white text-amazon-light px-3 py-1 rounded font-bold text-xl tracking-wider">
amazon
</div>
<span className="text-sm hidden sm:inline">.clone</span>
</Link>
{/* Search Bar */}
<form onSubmit={handleSearch} className="flex-1 max-w-2xl mx-4 hidden md:flex">
<div className="flex w-full rounded overflow-hidden">
<select className="bg-gray-100 text-gray-800 px-3 py-2 text-sm border-r border-gray-300 outline-none">
<option>All</option>
<option>Electronics</option>
<option>Books</option>
<option>Fashion</option>
<option>Home</option>
</select>
<input
type="text"
placeholder="Search Amazon"
className="flex-1 px-4 py-2 text-gray-800 outline-none"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<button
type="submit"
className="bg-amazon-orange px-6 py-2 hover:bg-orange-600 transition-colors"
>
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
</div>
</form>
{/* Right Section */}
<div className="flex items-center space-x-6">
{/* Language */}
<button className="hidden sm:flex items-center space-x-1 text-sm">
<span>🇺🇸</span>
<span>EN</span>
</button>
{/* Account & Lists */}
<div className="hidden sm:block cursor-pointer">
<div className="text-xs text-gray-300">Hello, Sign in</div>
<div className="text-sm font-bold">Account & Lists</div>
</div>
{/* Returns */}
<div className="hidden sm:block cursor-pointer">
<div className="text-xs text-gray-300">Returns</div>
<div className="text-sm font-bold">& Orders</div>
</div>
{/* Cart */}
<button
onClick={() => setIsCartOpen(true)}
className="flex items-center space-x-1 relative"
>
<svg className="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
<path d="M7 18c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm10 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zM7.2 14.6l.1-.1 1.1-2h7.4c.8 0 1.4-.4 1.7-1l3.9-7-1.7-1-3.9 7H8.5L4.3 2H1v2h2l3.6 7.6-1.4 2.5c-.1.2-.2.5-.2.9 0 1.1.9 2 2 2h12v-2H7.4c-.1 0-.2-.1-.2-.2z"/>
</svg>
<span className="absolute -top-1 -right-1 bg-amazon-orange text-white text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center">
{cartCount}
</span>
<span className="text-sm font-bold hidden sm:inline">Cart</span>
</button>
{/* Mobile Menu Button */}
<button
className="md:hidden"
onClick={() => setIsMenuOpen(!isMenuOpen)}
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
</div>
</div>
</div>
{/* Secondary Header */}
<div className="bg-gray-800 text-white">
<div className="max-w-7xl mx-auto px-4">
<div className="flex items-center space-x-6 h-10 overflow-x-auto">
<button className="flex items-center space-x-1 text-sm hover:text-gray-300">
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>
</svg>
<span className="font-bold">All</span>
</button>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Today's Deals</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Customer Service</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Registry</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Gift Cards</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Sell</a>
</div>
</div>
</div>
{/* Mobile Search */}
<form onSubmit={handleSearch} className="md:hidden bg-amazon-light p-2">
<div className="flex">
<select className="bg-gray-100 text-gray-800 px-3 py-2 text-sm border-r border-gray-300 outline-none rounded-l">
<option>All</option>
</select>
<input
type="text"
placeholder="Search Amazon"
className="flex-1 px-4 py-2 text-gray-800 outline-none"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<button
type="submit"
className="bg-amazon-orange px-4 py-2 rounded-r"
>
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
</div>
</form>
</header>
);
}