feat(design): restyle shell with flat Modernist sidebar, mobile nav and bell

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 19:06:17 +08:00
co-authored by Claude Haiku 4.5
parent e7416bf236
commit 0b5020b3d0
4 changed files with 107 additions and 97 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ export default async function ProtectedLayout({
if (!session) redirect('/login') if (!session) redirect('/login')
return ( return (
<div className="min-h-screen bg-gray-50"> <div className="min-h-screen bg-ground">
<Sidebar <Sidebar
role={session.role} role={session.role}
userName={session.name} userName={session.name}
+57 -89
View File
@@ -2,6 +2,17 @@
import Link from 'next/link' import Link from 'next/link'
import { usePathname, useRouter } from 'next/navigation' import { usePathname, useRouter } from 'next/navigation'
import {
AlignLeft,
CircleCheck,
ClipboardList,
LayoutDashboard,
LogOut,
Plus,
Settings,
User,
Users,
} from 'lucide-react'
import { NotificationBell } from '@/components/notifications/bell' import { NotificationBell } from '@/components/notifications/bell'
interface NavItem { interface NavItem {
@@ -16,52 +27,15 @@ interface SidebarProps {
userEmail: string userEmail: string
} }
const IconGrid = () => ( const IconGrid = () => <AlignLeft size={20} aria-hidden />
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> const IconList = () => <ClipboardList size={20} aria-hidden />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h7" /> const IconCheck = () => <CircleCheck size={20} aria-hidden />
</svg> const IconChart = () => <LayoutDashboard size={20} aria-hidden />
) const IconSettings = () => <Settings size={20} aria-hidden />
const IconList = () => ( const IconUsers = () => <Users size={20} aria-hidden />
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> const IconPlus = () => <Plus size={20} aria-hidden />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" /> const IconLogout = () => <LogOut size={16} aria-hidden />
</svg> const IconUser = () => <User size={16} aria-hidden />
)
const IconCheck = () => (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
)
const IconChart = () => (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
)
const IconSettings = () => (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
)
const IconUsers = () => (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
)
const IconPlus = () => (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
</svg>
)
const IconLogout = () => (
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
</svg>
)
const IconUser = () => (
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
</svg>
)
const NAV_ITEMS: Record<string, NavItem[]> = { const NAV_ITEMS: Record<string, NavItem[]> = {
reporter: [ reporter: [
@@ -94,6 +68,12 @@ const NAV_ITEMS: Record<string, NavItem[]> = {
], ],
} }
const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
function isActivePath(href: string, pathname: string): boolean {
return EXACT_ROOTS.includes(href) ? pathname === href : pathname.startsWith(href)
}
function initials(name: string): string { function initials(name: string): string {
return name return name
.split(' ') .split(' ')
@@ -107,23 +87,19 @@ function useNavItems(role: string): NavItem[] {
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
} }
function NavLink({ item, pathname }: { item: NavItem; pathname: string }) { const LINK_BASE = 'flex items-center gap-3 px-3 py-2 text-sm border-l-2 transition-colors'
// Exact match for root-level single-page roles, prefix match otherwise const LINK_ACTIVE = 'border-accent text-accent-700 font-extrabold bg-accent-100/50'
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account'] const LINK_IDLE = 'border-transparent text-ink/70 font-medium hover:bg-ink/7 hover:text-ink'
const isActive = exactRoots.includes(item.href)
? pathname === item.href
: pathname.startsWith(item.href)
function NavLink({ item, pathname }: { item: NavItem; pathname: string }) {
const active = isActivePath(item.href, pathname)
return ( return (
<Link <Link
href={item.href} href={item.href}
className={`flex items-center gap-3 px-3 py-2 text-sm font-medium transition-colors ${ aria-current={active ? 'page' : undefined}
isActive className={`${LINK_BASE} ${active ? LINK_ACTIVE : LINK_IDLE}`}
? 'bg-blue-50 text-blue-700'
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
}`}
> >
<span className={isActive ? 'text-blue-600' : 'text-gray-400'}>{item.icon}</span> <span className={active ? 'text-accent-700' : 'text-ink/50'}>{item.icon}</span>
{item.label} {item.label}
</Link> </Link>
) )
@@ -143,74 +119,67 @@ export function Sidebar({ role, userName, userEmail }: SidebarProps) {
const displayName = userName || userEmail || 'User' const displayName = userName || userEmail || 'User'
const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
const accountActive = pathname === '/account'
return ( return (
<> <>
{/* Desktop sidebar */} {/* Desktop sidebar */}
<aside className="hidden sm:flex fixed left-0 top-0 h-full w-60 bg-surface border-r border-divider flex-col z-40"> <aside className="hidden sm:flex fixed left-0 top-0 h-full w-60 bg-ground border-r-2 border-divider flex-col z-40">
{/* Header */} <div className="flex items-center justify-between px-4 py-4 border-b-2 border-divider">
<div className="flex items-center justify-between px-4 py-4 border-b border-divider"> <span className="text-lg font-extrabold tracking-tight text-ink">IMS</span>
<span className="text-base font-bold text-gray-900 tracking-tight">IMS</span>
<NotificationBell /> <NotificationBell />
</div> </div>
{/* Nav */} <nav className="flex-1 overflow-y-auto py-3">
<nav className="flex-1 overflow-y-auto px-3 py-3 space-y-1">
{items.map(item => ( {items.map(item => (
<NavLink key={item.href} item={item} pathname={pathname} /> <NavLink key={item.href} item={item} pathname={pathname} />
))} ))}
</nav> </nav>
{/* User + logout */} <div className="border-t-2 border-divider py-3">
<div className="border-t border-divider px-3 py-3"> <div className="flex items-center gap-2 px-4 py-2 mb-1">
<div className="flex items-center gap-2 px-2 py-2 mb-1"> <div className="w-8 h-8 rounded-full bg-accent flex items-center justify-center text-ground text-xs font-extrabold flex-shrink-0">
<div className="w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white text-xs font-bold flex-shrink-0">
{initials(displayName)} {initials(displayName)}
</div> </div>
<div className="min-w-0"> <div className="min-w-0">
<p className="text-sm font-medium text-gray-900 truncate">{displayName}</p> <p className="text-sm font-extrabold text-ink truncate">{displayName}</p>
<p className="text-xs text-gray-500 truncate">{roleLabel}</p> <p className="text-xs text-ink/60 truncate">{roleLabel}</p>
</div> </div>
</div> </div>
<Link <Link
href="/account" href="/account"
className={`flex items-center gap-2 w-full px-3 py-2 text-sm transition-colors ${ aria-current={accountActive ? 'page' : undefined}
pathname === '/account' className={`${LINK_BASE} ${accountActive ? LINK_ACTIVE : LINK_IDLE}`}
? 'bg-blue-50 text-blue-700'
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
}`}
> >
<span className={pathname === '/account' ? 'text-blue-600' : 'text-gray-400'}> <span className={accountActive ? 'text-accent-700' : 'text-ink/50'}>
<IconUser /> <IconUser />
</span> </span>
Account Account
</Link> </Link>
<button <button
onClick={logout} onClick={logout}
className="flex items-center gap-2 w-full px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900 transition-colors" className={`${LINK_BASE} ${LINK_IDLE} w-full text-left cursor-pointer`}
> >
<IconLogout /> <span className="text-ink/50"><IconLogout /></span>
Logout Logout
</button> </button>
<div className="mt-3 pt-3 border-t border-divider px-2 text-center"> <div className="mt-3 pt-3 border-t border-divider px-4">
<p className="text-xs text-gray-400">v1.2.2</p> <p className="text-xs text-ink/50">v1.2.2</p>
</div> </div>
</div> </div>
</aside> </aside>
{/* Mobile bottom tab bar */} {/* Mobile bottom tab bar */}
<nav className="sm:hidden fixed bottom-0 left-0 right-0 bg-surface border-t border-divider flex z-40 safe-area-pb"> <nav className="sm:hidden fixed bottom-0 left-0 right-0 bg-ground border-t-2 border-divider flex z-40 safe-area-pb">
{mobileItems.map(item => { {mobileItems.map(item => {
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account'] const active = isActivePath(item.href, pathname)
const isActive = exactRoots.includes(item.href)
? pathname === item.href
: pathname.startsWith(item.href)
return ( return (
<Link <Link
key={item.href} key={item.href}
href={item.href} href={item.href}
className={`flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium transition-colors ${ aria-current={active ? 'page' : undefined}
isActive ? 'text-blue-600' : 'text-gray-400' className={`flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-extrabold transition-colors ${
active ? 'text-accent-700' : 'text-ink/55'
}`} }`}
> >
{item.icon} {item.icon}
@@ -218,11 +187,10 @@ export function Sidebar({ role, userName, userEmail }: SidebarProps) {
</Link> </Link>
) )
})} })}
{/* Mobile logout in "More" slot if room */}
{items.length <= 4 && ( {items.length <= 4 && (
<button <button
onClick={logout} onClick={logout}
className="flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium text-gray-400" className="flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-extrabold text-ink/55 cursor-pointer"
> >
<IconLogout /> <IconLogout />
<span className="leading-none">Logout</span> <span className="leading-none">Logout</span>
+7 -6
View File
@@ -2,6 +2,7 @@
import { useCallback, useEffect, useRef, useState } from 'react' import { useCallback, useEffect, useRef, useState } from 'react'
import Link from 'next/link' import Link from 'next/link'
import { Bell } from 'lucide-react'
type Notification = { type Notification = {
id: string id: string
@@ -62,11 +63,11 @@ export function NotificationBell() {
<button <button
onClick={() => setOpen(o => !o)} onClick={() => setOpen(o => !o)}
aria-label={`Notifications${unread > 0 ? ` (${unread} unread)` : ''}`} aria-label={`Notifications${unread > 0 ? ` (${unread} unread)` : ''}`}
className="relative bg-surface rounded-full shadow-sm border border-divider w-10 h-10 flex items-center justify-center hover:shadow-md transition-shadow" className="relative bg-surface border border-divider w-10 h-10 flex items-center justify-center text-ink cursor-pointer transition-colors hover:bg-ink/7 active:bg-ink/15"
> >
<span className="text-lg" aria-hidden>🔔</span> <Bell size={18} strokeWidth={2} aria-hidden />
{unread > 0 && ( {unread > 0 && (
<span className="absolute -top-1 -right-1 bg-red-600 text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] px-1 flex items-center justify-center"> <span className="absolute -top-1 -right-1 bg-accent text-ground text-[10px] font-extrabold min-w-[18px] h-[18px] px-1 flex items-center justify-center">
{unread > 99 ? '99+' : unread} {unread > 99 ? '99+' : unread}
</span> </span>
)} )}
@@ -74,10 +75,10 @@ export function NotificationBell() {
{open && ( {open && (
<div className="absolute right-0 mt-2 w-80 max-h-96 overflow-y-auto bg-surface shadow-lg border border-divider"> <div className="absolute right-0 mt-2 w-80 max-h-96 overflow-y-auto bg-surface shadow-lg border border-divider">
<div className="flex items-center justify-between px-4 py-2 border-b border-divider"> <div className="flex items-center justify-between px-4 py-2 border-b-2 border-divider">
<span className="text-sm font-semibold text-gray-700">Notifications</span> <span className="text-sm font-extrabold text-ink">Notifications</span>
{unread > 0 && ( {unread > 0 && (
<button onClick={markAllRead} className="text-xs text-blue-600 hover:underline"> <button onClick={markAllRead} className="text-xs text-accent-700 hover:underline">
Mark all read Mark all read
</button> </button>
)} )}
+41
View File
@@ -0,0 +1,41 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
vi.mock('next/navigation', () => ({
usePathname: () => '/hse/capa',
useRouter: () => ({ push: vi.fn(), refresh: vi.fn() }),
}))
vi.mock('@/components/notifications/bell', () => ({ NotificationBell: () => null }))
import { Sidebar } from '@/components/layout/sidebar'
describe('Sidebar (Modernist shell)', () => {
it('renders the role nav with Lucide icons instead of inline paths', () => {
const { container } = render(<Sidebar role="hse" userName="Ada Lovelace" userEmail="" />)
expect(screen.getAllByText('Dashboard').length).toBeGreaterThan(0)
expect(screen.getAllByText('CAPA').length).toBeGreaterThan(0)
expect(container.querySelectorAll('svg.lucide').length).toBeGreaterThan(4)
})
it('marks the active link in the accent with an aria-current', () => {
render(<Sidebar role="hse" userName="Ada" userEmail="" />)
const active = screen.getAllByRole('link', { name: /CAPA/ }).find(a => a.getAttribute('aria-current') === 'page')
expect(active).toBeTruthy()
expect(active?.className).toContain('text-accent-700')
expect(active?.className).toContain('border-accent')
})
it('is flat: a 2px divider rule, ground fill and no rounded corners except the avatar', () => {
const { container } = render(<Sidebar role="hse" userName="Ada" userEmail="" />)
const aside = container.querySelector('aside')
expect(aside?.className).toContain('border-r-2')
expect(aside?.className).toContain('bg-ground')
const rounded = container.innerHTML.match(/rounded[\w-]*/g) ?? []
expect(rounded.every(r => r === 'rounded-full')).toBe(true)
})
it('keeps the version label', () => {
render(<Sidebar role="hse" userName="Ada" userEmail="" />)
expect(screen.getByText('v1.2.2')).toBeTruthy()
})
})