ui improvemnt

This commit is contained in:
Marshal
2026-06-06 21:17:20 +00:00
parent b62ea3f95f
commit 08b46c306f
35 changed files with 2731 additions and 1604 deletions

View File

@@ -9,14 +9,10 @@ import {
Sun,
User,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { Group, Stack, Text, Avatar, Menu, ActionIcon, Badge } from "@mantine/core";
import type { PageMeta } from "./types";
const iconButtonClass =
"relative inline-flex h-10 w-10 items-center justify-center rounded-xl border border-gray-200 bg-white text-gray-600 shadow-sm transition hover:border-primary/30 hover:bg-gray-50 hover:text-gray-900";
export interface FreightDashboardHeaderProps {
pageMeta: PageMeta;
headerRight?: ReactNode;
@@ -77,120 +73,145 @@ const FreightDashboardHeader = ({
}, [isUserMenuOpen]);
return (
<header className="flex h-20 shrink-0 items-center justify-between gap-4 px-6">
<div className="min-w-0">
<h1 className="truncate text-xl font-bold tracking-tight text-foreground">
<header
style={{
display: "flex",
height: "80px",
alignItems: "center",
justifyContent: "space-between",
gap: "16px",
padding: "0 24px",
}}
>
<Stack gap={2} style={{ flex: 1, minWidth: 0 }}>
<Text size="lg" fw={700} truncate>
{pageMeta.title}
</h1>
<p className="mt-0.5 truncate text-sm text-secondary-foreground">
</Text>
<Text size="sm" c="dimmed" truncate>
{pageMeta.subtitle}
</p>
</div>
</Text>
</Stack>
<div className="flex shrink-0 items-center gap-2">
{enableThemeToggle ? (
<button
type="button"
<Group gap="sm" wrap="nowrap">
{enableThemeToggle && (
<ActionIcon
variant="default"
size={40}
radius="lg"
onClick={onToggleTheme}
aria-label={
theme === "dark" ? "Switch to light mode" : "Switch to dark mode"
}
className={iconButtonClass}
style={{
background: "var(--mantine-color-gray-1)",
border: "1px solid var(--mantine-color-gray-2)",
color: "var(--mantine-color-gray-7)",
}}
>
{theme === "dark" ? (
<Sun className="h-5 w-5" />
) : (
<Moon className="h-5 w-5" />
)}
</button>
) : null}
{theme === "dark" ? <Sun size={18} /> : <Moon size={18} />}
</ActionIcon>
)}
<button
type="button"
aria-label="Change language"
className={iconButtonClass}
<ActionIcon
variant="default"
size={40}
radius="lg"
style={{
background: "var(--mantine-color-gray-1)",
border: "1px solid var(--mantine-color-gray-2)",
color: "var(--mantine-color-gray-7)",
}}
>
<Languages className="h-5 w-5" />
</button>
<Languages size={18} />
</ActionIcon>
<button type="button" aria-label="Messages" className={iconButtonClass}>
<MessageSquare className="h-5 w-5" />
<span className="absolute right-2 top-2 h-2 w-2 rounded-full bg-red-500 ring-2 ring-white" />
</button>
<button
type="button"
aria-label="Notifications"
className={iconButtonClass}
<ActionIcon
variant="default"
size={40}
radius="lg"
style={{
background: "var(--mantine-color-gray-1)",
border: "1px solid var(--mantine-color-gray-2)",
color: "var(--mantine-color-gray-7)",
position: "relative",
}}
>
<Bell className="h-5 w-5" />
<span className="absolute right-2 top-2 h-2 w-2 rounded-full bg-red-500 ring-2 ring-white" />
</button>
<MessageSquare size={18} />
<Badge
size="xs"
color="red"
circle
style={{
position: "absolute",
top: "-3px",
right: "-3px",
}}
/>
</ActionIcon>
<div ref={userMenuRef} className="relative ml-1">
<button
type="button"
aria-haspopup="menu"
aria-expanded={isUserMenuOpen}
onClick={() => setIsUserMenuOpen((open) => !open)}
className={cn(
"flex items-center gap-2 rounded-xl border border-transparent px-2 py-1.5 transition",
isUserMenuOpen
? "border-primary/30 bg-primary/5"
: "hover:border-primary/20 hover:bg-gray-50",
)}
>
<div className="flex h-9 w-9 items-center justify-center rounded-full bg-primary text-xs font-semibold text-primary-foreground">
{initials}
</div>
<ChevronDown
className={cn(
"hidden h-4 w-4 text-gray-400 transition sm:block",
isUserMenuOpen && "rotate-180 text-primary",
)}
/>
</button>
<ActionIcon
variant="default"
size={40}
radius="lg"
style={{
background: "var(--mantine-color-gray-1)",
border: "1px solid var(--mantine-color-gray-2)",
color: "var(--mantine-color-gray-7)",
position: "relative",
}}
>
<Bell size={18} />
<Badge
size="xs"
color="red"
circle
style={{
position: "absolute",
top: "-3px",
right: "-3px",
}}
/>
</ActionIcon>
{isUserMenuOpen ? (
<div
role="menu"
className="absolute right-0 top-full z-50 mt-2 w-52 overflow-hidden rounded-xl border border-gray-200 bg-white py-1 shadow-lg"
>
<div className="border-b border-gray-100 px-4 py-3">
<p className="text-sm font-semibold text-gray-900">
<Menu position="bottom-end" shadow="md" opened={isUserMenuOpen} onOpen={() => setIsUserMenuOpen(true)} onClose={() => setIsUserMenuOpen(false)}>
<Menu.Target>
<Group gap="sm" p="xs" style={{ cursor: "pointer", borderRadius: "12px" }}>
<Avatar name={initials} color="green" size="md" />
<ChevronDown size={16} style={{ transition: "transform 0.2s", transform: isUserMenuOpen ? "rotate(180deg)" : "rotate(0deg)" }} />
</Group>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item disabled>
<Stack gap={0}>
<Text size="sm" fw={600}>
{userName}
</p>
{userEmail ? (
<p className="text-xs text-gray-500">{userEmail}</p>
) : null}
</div>
<a
href="#profile"
role="menuitem"
onClick={() => setIsUserMenuOpen(false)}
className="flex items-center gap-2 px-4 py-2 text-sm text-gray-700 transition hover:bg-gray-50"
>
<User className="h-4 w-4" />
Profile
</a>
<button
type="button"
role="menuitem"
onClick={() => {
setIsUserMenuOpen(false);
onLogout?.();
}}
className="flex w-full items-center gap-2 px-4 py-2 text-sm text-red-600 transition hover:bg-red-50"
>
<LogOut className="h-4 w-4" />
Logout
</button>
</div>
) : null}
</div>
</Text>
{userEmail && (
<Text size="xs" c="dimmed">
{userEmail}
</Text>
)}
</Stack>
</Menu.Item>
<Menu.Divider />
<Menu.Item
leftSection={<User size={14} />}
onClick={() => setIsUserMenuOpen(false)}
>
Profile
</Menu.Item>
<Menu.Item
leftSection={<LogOut size={14} />}
color="red"
onClick={() => {
setIsUserMenuOpen(false);
onLogout?.();
}}
>
Logout
</Menu.Item>
</Menu.Dropdown>
</Menu>
{headerRight}
</div>
</Group>
</header>
);
};

View File

@@ -1,4 +1,5 @@
import { type ReactNode, useEffect, useState } from "react";
import { Box, Paper, MantineProvider } from "@mantine/core";
import FreightDashboardHeader from "./FreightDashboardHeader";
import FreightSidebar from "./FreightSidebar";
@@ -30,9 +31,6 @@ export interface FreightDashboardLayoutProps {
children: ReactNode;
}
const panelClass =
"rounded-lg border border-gray-200/80 bg-white shadow-[0_1px_3px_rgba(15,23,42,0.06)]";
const FreightDashboardLayout = ({
sidebarSections,
activeHref = "",
@@ -73,40 +71,79 @@ const FreightDashboardLayout = ({
rel="stylesheet"
/>
<div
className="flex h-[100dvh] overflow-hidden bg-[#eceef2] p-2 antialiased"
style={{ fontFamily: "'Outfit', var(--font-sans)" }}
>
<div className="flex h-full min-h-0 w-full gap-2">
<FreightSidebar
sections={sidebarSections}
activeHref={activeHref}
onNavigate={onNavigate}
/>
<MantineProvider>
<Box
style={{
display: "flex",
height: "100dvh",
overflow: "hidden",
background: "var(--mantine-color-gray-1)",
padding: "8px",
fontFamily: "'Outfit', var(--font-sans)",
}}
>
<Box style={{ display: "flex", height: "100%", minHeight: 0, width: "100%", gap: "8px" }}>
<FreightSidebar
sections={sidebarSections}
activeHref={activeHref}
onNavigate={onNavigate}
/>
<div className="flex h-full min-h-0 min-w-0 flex-1 flex-col gap-2">
<div className={`shrink-0 ${panelClass}`}>
<FreightDashboardHeader
pageMeta={pageMeta}
headerRight={headerRight}
enableThemeToggle={enableThemeToggle}
userName={userName}
userEmail={userEmail}
userInitials={userInitials}
onLogout={onLogout}
theme={theme}
onToggleTheme={toggleTheme}
/>
</div>
<main
className={`min-h-0 flex-1 overflow-y-auto overscroll-contain ${panelClass} p-4 md:p-6`}
<Box
style={{
display: "flex",
height: "100%",
minHeight: 0,
minWidth: 0,
flex: 1,
flexDirection: "column",
gap: "8px",
}}
>
{children}
</main>
</div>
</div>
</div>
<Paper
p={0}
radius="lg"
withBorder
style={{
flexShrink: 0,
background: "white",
border: "1px solid var(--mantine-color-gray-2)",
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.05)",
}}
>
<FreightDashboardHeader
pageMeta={pageMeta}
headerRight={headerRight}
enableThemeToggle={enableThemeToggle}
userName={userName}
userEmail={userEmail}
userInitials={userInitials}
onLogout={onLogout}
theme={theme}
onToggleTheme={toggleTheme}
/>
</Paper>
<Paper
p={{ base: 16, md: 24 }}
radius="lg"
withBorder
style={{
minHeight: 0,
flex: 1,
overflowY: "auto",
overscrollBehavior: "contain",
background: "white",
border: "1px solid var(--mantine-color-gray-2)",
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.05)",
}}
>
{children}
</Paper>
</Box>
</Box>
</Box>
</MantineProvider>
</>
);
};

View File

@@ -5,14 +5,11 @@ import {
useMemo,
useState,
} from "react";
import { ChevronDown, ChevronRight } from "lucide-react";
import { cn } from "@/lib/utils";
import { ChevronDown, ChevronRight, Train } from "lucide-react";
import { Stack, Group, Text, Box, UnstyledButton, NavLink } from "@mantine/core";
import type { SidebarItem, SidebarSection } from "./types";
const EDR_LOGO = "/assets/logo.svg";
export interface FreightSidebarProps {
sections: SidebarSection[];
activeHref?: string;
@@ -103,25 +100,6 @@ const FreightSidebar = ({
setExpanded((current) => ({ ...current, [key]: !current[key] }));
};
const navLinkClass = (active: boolean, depth: number) =>
cn(
"flex items-center justify-between rounded-md px-3 py-2.5 text-base font-medium leading-snug transition-colors",
active
? "bg-primary text-primary-foreground shadow-sm"
: "text-gray-900 hover:bg-gray-100",
depth > 0 && "text-[15px]",
);
const iconClass = (active: boolean, sectionActive: boolean) =>
cn(
"flex h-5 w-5 shrink-0 items-center justify-center [&_svg]:h-5 [&_svg]:w-5",
active
? "text-primary-foreground"
: sectionActive
? "text-gray-900"
: "text-gray-900",
);
const renderNavBranch = (
children: SidebarItem[],
depth: number,
@@ -136,37 +114,37 @@ const FreightSidebar = ({
const groupActive = branchContainsActive(child.children!);
return (
<div key={key} className="flex flex-col gap-0.5">
<button
type="button"
aria-expanded={isOpen}
<Stack key={key} gap={4}>
<UnstyledButton
onClick={() => toggleExpanded(key)}
className={cn(
"flex w-full items-center justify-between rounded-md px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide transition-colors",
groupActive
? "bg-gray-100 text-gray-900"
: "text-gray-900 hover:bg-gray-100",
)}
style={{
background: groupActive ? "var(--mantine-color-green-1)" : "transparent",
padding: "8px 12px",
borderRadius: "8px",
width: "100%",
cursor: "pointer",
}}
>
<span className="truncate">{child.label}</span>
<ChevronDown
className={cn(
"h-4 w-4 shrink-0 text-gray-900 transition-transform",
isOpen ? "rotate-0" : "-rotate-90",
)}
/>
</button>
{isOpen ? (
<div
className={cn(
"flex flex-col gap-0.5 border-l border-gray-200",
depth === 0 ? "ml-3 pl-2" : "ml-2 pl-2",
)}
>
<Group justify="space-between">
<Text size="xs" fw={600} c={groupActive ? "green" : "dimmed"} tt="uppercase">
{child.label}
</Text>
<ChevronDown
size={14}
style={{
transform: isOpen ? "rotate(0deg)" : "rotate(-90deg)",
transition: "transform 0.2s",
color: groupActive ? "var(--mantine-color-green-6)" : "var(--mantine-color-gray-5)",
}}
/>
</Group>
</UnstyledButton>
{isOpen && (
<Stack gap={2} style={{ paddingLeft: "12px", borderLeft: "2px solid var(--mantine-color-green-2)" }}>
{renderNavBranch(child.children!, depth + 1, key)}
</div>
) : null}
</div>
</Stack>
)}
</Stack>
);
}
@@ -176,24 +154,49 @@ const FreightSidebar = ({
const childActiveHref = isHrefActive(childHref);
return (
<a
<NavLink
key={key}
component="a"
href={child.href}
onClick={(event) => navigateTo(event, child.href!)}
aria-current={childActiveHref ? "page" : undefined}
className={navLinkClass(childActiveHref, depth)}
>
<span className="truncate">{child.label}</span>
<ChevronRight
className={cn(
"h-4 w-4 shrink-0",
childActiveHref ? "text-primary-foreground/80" : "text-gray-900",
)}
/>
</a>
onClick={(e) => navigateTo(e as any, child.href!)}
label={child.label}
active={childActiveHref}
color="green"
style={{
borderRadius: "8px",
cursor: "pointer",
fontSize: "14px",
}}
rightSection={<ChevronRight size={16} />}
/>
);
});
const renderIconWell = (icon: React.ReactNode, active: boolean) => {
if (!icon) return null;
return (
<Box
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "30px",
height: "30px",
borderRadius: "8px",
flexShrink: 0,
background: active
? "linear-gradient(135deg, #10b981 0%, #059669 100%)"
: "var(--mantine-color-gray-1)",
color: active ? "white" : "var(--mantine-color-gray-6)",
boxShadow: active ? "0 2px 6px rgba(16, 185, 129, 0.25)" : "none",
transition: "all 0.2s ease",
}}
>
{icon}
</Box>
);
};
const renderTopLevelItem = (item: SidebarItem) => {
if (!item.href) return null;
@@ -211,99 +214,127 @@ const FreightSidebar = ({
const leafActive = isCurrentItem && !hasChildren;
return (
<div key={item.href} className="flex flex-col gap-0.5">
<div
className={cn(
"group flex items-center rounded-md transition-colors",
leafActive
? "bg-primary text-primary-foreground shadow-sm"
: isSectionActive || (hasChildren && isCurrentItem)
? "bg-gray-100 text-gray-900"
: "text-gray-900 hover:bg-gray-100",
)}
>
<a
href={item.href}
onClick={(event) => navigateTo(event, item.href!)}
aria-current={isCurrentItem ? "page" : undefined}
className="flex min-w-0 flex-1 items-center gap-3 px-3 py-2.5 text-sm leading-snug"
>
{item.icon ? (
<span className={iconClass(leafActive, isActive)}>
{item.icon}
</span>
) : null}
<span className="truncate">{item.label}</span>
</a>
{hasChildren ? (
<button
type="button"
aria-label={`Toggle ${item.label}`}
aria-expanded={isOpen}
onClick={() => toggleExpanded(item.href!)}
className={cn(
"mr-2 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md transition-colors",
leafActive
? "text-primary-foreground hover:bg-white/10"
: "text-gray-900 hover:bg-gray-200/80",
)}
>
<Stack key={item.href} gap={0}>
<NavLink
component="a"
href={item.href}
onClick={(e) => navigateTo(e as any, item.href!)}
label={item.label}
leftSection={renderIconWell(item.icon, isActive)}
active={leafActive}
color="green"
variant="light"
style={{
borderRadius: "10px",
cursor: "pointer",
fontSize: "14px",
fontWeight: 500,
padding: "8px 10px",
}}
rightSection={
hasChildren ? (
<ChevronDown
className={cn(
"h-4 w-4 transition-transform",
isOpen ? "rotate-0" : "-rotate-90",
)}
size={16}
style={{
transform: isOpen ? "rotate(0deg)" : "rotate(-90deg)",
transition: "transform 0.2s",
}}
onClick={(e) => {
e.preventDefault();
toggleExpanded(item.href!);
}}
/>
</button>
) : (
<span
className={cn(
"mr-3 flex h-4 w-4 shrink-0 items-center justify-center",
leafActive ? "text-primary-foreground/80" : "text-gray-900",
)}
aria-hidden
>
<ChevronRight className="h-4 w-4" />
</span>
)}
</div>
) : (
<ChevronRight size={16} />
)
}
/>
{hasChildren && isOpen ? (
<div className="ml-3 flex flex-col gap-1 border-l border-gray-200 pl-2">
{hasChildren && isOpen && (
<Stack gap={4} style={{ paddingLeft: "16px", borderLeft: "2px solid var(--mantine-color-green-2)" }}>
{renderNavBranch(item.children!, 0, item.href)}
</div>
) : null}
</div>
</Stack>
)}
</Stack>
);
};
return (
<aside className="flex h-full max-h-full w-[280px] shrink-0 flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-sm">
<div className="flex shrink-0 items-center gap-2.5 border-b border-gray-100 px-5 py-5">
<img src={EDR_LOGO} alt="EDR Freight" className="h-9 w-auto" />
<span className="text-lg font-semibold tracking-tight text-gray-900">
EDR Freight
</span>
</div>
<Box
component="aside"
style={{
height: "100%",
maxHeight: "100%",
width: "280px",
flexShrink: 0,
borderRadius: "12px",
border: "1px solid var(--mantine-color-gray-2)",
background: "white",
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.05)",
display: "flex",
flexDirection: "column",
overflow: "hidden",
}}
>
<Group
gap={12}
px="lg"
py="md"
style={{
borderBottom: "1px solid var(--mantine-color-gray-2)",
flexShrink: 0,
height: "80px",
}}
wrap="nowrap"
>
<Box
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "44px",
height: "44px",
borderRadius: "12px",
background: "linear-gradient(135deg, #10b981 0%, #059669 100%)",
boxShadow: "0 4px 12px rgba(16, 185, 129, 0.3)",
flexShrink: 0,
}}
>
<Train size={24} color="white" strokeWidth={2} />
</Box>
<Stack gap={0} style={{ minWidth: 0 }}>
<Text size="md" fw={700} style={{ letterSpacing: "-0.3px", lineHeight: 1.2 }}>
EDR Freight
</Text>
<Text size="xs" c="dimmed" fw={500} style={{ letterSpacing: "0.3px" }}>
Backoffice
</Text>
</Stack>
</Group>
<nav className="flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto overscroll-contain px-3 py-4">
<Stack
component="nav"
gap="lg"
p="md"
style={{
flex: 1,
minHeight: 0,
overflowY: "auto",
overscrollBehavior: "contain",
}}
>
{sections.map((section) => (
<div key={section.title} className="flex flex-col gap-1">
<p
className={cn(
"px-3 pb-1 text-xs font-semibold uppercase tracking-wide",
// Use a very light gray for ALL section titles, not just when mutedTitle is specified
"text-sidebar-secondary-foreground",
)}
>
<Stack key={section.title} gap={8}>
<Text size="xs" fw={600} c="dimmed" tt="uppercase" style={{ letterSpacing: "0.5px", paddingLeft: "8px" }}>
{section.title}
</p>
{section.items.map((item) => renderTopLevelItem(item))}
</div>
</Text>
<Stack gap={2}>
{section.items.map((item) => renderTopLevelItem(item))}
</Stack>
</Stack>
))}
</nav>
</aside>
</Stack>
</Box>
);
};