Spaces:
Sleeping
Sleeping
| import React, { useState } from 'react'; | |
| import { Link, useLocation } from 'react-router-dom'; | |
| import { Menu, X, Activity } from 'lucide-react'; | |
| const Navbar: React.FC = () => { | |
| const [isOpen, setIsOpen] = useState(false); | |
| const location = useLocation(); | |
| const navItems = [ | |
| { name: '首页', path: '/' }, | |
| { name: '任务管理', path: '/tasks' }, | |
| { name: '关于', path: '/about' }, | |
| { name: 'API文档', path: '/api-docs' }, | |
| ]; | |
| return ( | |
| <nav className="bg-blue-900 text-white shadow-lg sticky top-0 z-50"> | |
| <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | |
| <div className="flex items-center justify-between h-16"> | |
| <div className="flex items-center"> | |
| <Link to="/" className="flex items-center space-x-2"> | |
| <Activity className="h-8 w-8 text-blue-400" /> | |
| <span className="font-bold text-xl">Koa Web 应用</span> | |
| </Link> | |
| </div> | |
| <div className="hidden md:block"> | |
| <div className="ml-10 flex items-baseline space-x-4"> | |
| {navItems.map((item) => ( | |
| <Link | |
| key={item.path} | |
| to={item.path} | |
| className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${ | |
| location.pathname === item.path | |
| ? 'bg-blue-800 text-white' | |
| : 'text-blue-100 hover:bg-blue-800 hover:text-white' | |
| }`} | |
| > | |
| {item.name} | |
| </Link> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="md:hidden"> | |
| <button | |
| onClick={() => setIsOpen(!isOpen)} | |
| className="inline-flex items-center justify-center p-2 rounded-md text-blue-100 hover:text-white hover:bg-blue-800 focus:outline-none" | |
| > | |
| {isOpen ? <X className="h-6 w-6" /> : <Menu className="h-6 w-6" />} | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| {/* Mobile menu */} | |
| {isOpen && ( | |
| <div className="md:hidden bg-blue-900 border-t border-blue-800"> | |
| <div className="px-2 pt-2 pb-3 space-y-1 sm:px-3"> | |
| {navItems.map((item) => ( | |
| <Link | |
| key={item.path} | |
| to={item.path} | |
| onClick={() => setIsOpen(false)} | |
| className={`block px-3 py-2 rounded-md text-base font-medium ${ | |
| location.pathname === item.path | |
| ? 'bg-blue-800 text-white' | |
| : 'text-blue-100 hover:bg-blue-800 hover:text-white' | |
| }`} | |
| > | |
| {item.name} | |
| </Link> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| </nav> | |
| ); | |
| }; | |
| export default Navbar; | |