feat: 添加手機版響應式導航,實現漢堡選單
📱 手機版導航系統: - 添加漢堡選單按鈕(三條線 ↔ X 圖示切換) - 實作手機版下拉選單,包含所有導航項目 - 手機版用戶資訊區域(頭像 + 登出) - 點擊導航項目後自動關閉選單 🎯 響應式設計改進: - 桌面版:水平導航條 + 右側用戶資訊 - 手機版:漢堡選單 + 垂直下拉選單 - 當前頁面在手機版以主色調背景高亮 🔧 技術實作: - 使用 Tailwind 的 md: 斷點控制顯示/隱藏 - useState 管理手機選單開關狀態 - 動態 SVG 圖示切換(選單/關閉) ✅ 解決問題: - 手機版現在有完整的導航功能 - 所有頁面在手機上都可以正常使用 - 專業級的響應式用戶體驗 🚀 DramaLing 現在完全支援桌面和手機裝置! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
116daafc37
commit
4797366a25
|
|
@ -1,5 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import { useAuth } from '@/contexts/AuthContext'
|
import { useAuth } from '@/contexts/AuthContext'
|
||||||
|
|
@ -12,6 +13,7 @@ interface NavigationProps {
|
||||||
export function Navigation({ showExitLearning = false, onExitLearning }: NavigationProps = {}) {
|
export function Navigation({ showExitLearning = false, onExitLearning }: NavigationProps = {}) {
|
||||||
const { user, logout } = useAuth()
|
const { user, logout } = useAuth()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false)
|
||||||
|
|
||||||
const navItems = [
|
const navItems = [
|
||||||
{ href: '/dashboard', label: '儀表板' },
|
{ href: '/dashboard', label: '儀表板' },
|
||||||
|
|
@ -42,6 +44,20 @@ export function Navigation({ showExitLearning = false, onExitLearning }: Navigat
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 手機版漢堡選單按鈕 */}
|
||||||
|
<button
|
||||||
|
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
|
||||||
|
className="md:hidden p-2 text-gray-600 hover:text-gray-900"
|
||||||
|
>
|
||||||
|
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
{isMobileMenuOpen ? (
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||||
|
) : (
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
|
||||||
|
)}
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center space-x-4">
|
||||||
|
|
@ -67,6 +83,47 @@ export function Navigation({ showExitLearning = false, onExitLearning }: Navigat
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 手機版下拉選單 */}
|
||||||
|
{isMobileMenuOpen && (
|
||||||
|
<div className="md:hidden border-t border-gray-200">
|
||||||
|
<div className="px-4 py-4 space-y-2">
|
||||||
|
{navItems.map((item) => (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
onClick={() => setIsMobileMenuOpen(false)}
|
||||||
|
className={`block py-2 px-3 rounded-lg font-medium transition-colors ${
|
||||||
|
pathname === item.href
|
||||||
|
? 'bg-primary text-white'
|
||||||
|
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{/* 手機版用戶區域 */}
|
||||||
|
<div className="pt-4 border-t border-gray-200 mt-4">
|
||||||
|
<div className="flex items-center space-x-3 px-3 py-2">
|
||||||
|
<div className="w-8 h-8 bg-primary rounded-full flex items-center justify-center text-white font-semibold">
|
||||||
|
{user?.username?.[0]?.toUpperCase() || 'U'}
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-medium">{user?.displayName || user?.username}</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
logout()
|
||||||
|
setIsMobileMenuOpen(false)
|
||||||
|
}}
|
||||||
|
className="w-full text-left py-2 px-3 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg"
|
||||||
|
>
|
||||||
|
登出
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue