diff --git a/package-lock.json b/package-lock.json index 7872d716..fa54c0b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2833,6 +2833,13 @@ "license": "MIT", "dependencies": { "react-router": "7.17.0" +======= + "version": "7.17.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.17.0.tgz", + "integrity": "sha512-fyU2yjGups/hE6Xz0I5ZYbVL8Gx29eCjgpHaRaTaVU+OOAdfRX05KsvyRm0GO8YQwOkhpU3MurW1jyMUJn+zSw==", + "license": "MIT", + "dependencies": { + "react-router": "7.17.0" }, "engines": { "node": ">=20.0.0" diff --git a/src/components/ResponsiveMultiLevelNavigation.tsx b/src/components/ResponsiveMultiLevelNavigation.tsx index 16a49dc1..13bbe607 100644 --- a/src/components/ResponsiveMultiLevelNavigation.tsx +++ b/src/components/ResponsiveMultiLevelNavigation.tsx @@ -99,7 +99,9 @@ function NavNode({ if (item.path) onSelect(item.path); }} className={`flex w-full items-center justify-between gap-2 rounded-2xl px-4 py-3 text-left transition ${ - isActive ? "bg-slate-900 text-white" : "bg-white hover:bg-slate-50" + isActive + ? "bg-slate-900 text-white dark:bg-white dark:text-slate-900" + : "bg-white text-slate-700 hover:bg-slate-50 dark:bg-slate-800 dark:text-slate-200 dark:hover:bg-slate-700/80" }`} style={{ paddingLeft: `${16 + depth * 18}px` }} > @@ -107,17 +109,17 @@ function NavNode({
{item.label} {item.badge ? ( - + {item.badge} ) : null}
{item.path ? ( - onSelect(item.path!)}>{item.path} + onSelect(item.path!)}>{item.path} ) : null} {hasChildren ? ( - {isOpen ? "−" : "+"} + {isOpen ? "−" : "+"} ) : null} {hasChildren && isOpen ? ( @@ -151,6 +153,29 @@ export default function ResponsiveMultiLevelNavigation() { const [mobileOpen, setMobileOpen] = useState(false); const [compact, setCompact] = useState(false); + // Sync dark mode state with localStorage and document element + const [isDark, setIsDark] = useState(() => { + if (typeof window !== 'undefined') { + const stored = localStorage.getItem('theme'); + if (stored) return stored === 'dark'; + return document.documentElement.classList.contains('dark') || !stored; + } + return true; + }); + + useEffect(() => { + const root = window.document.documentElement; + if (isDark) { + root.classList.add('dark'); + root.classList.remove('light'); + localStorage.setItem('theme', 'dark'); + } else { + root.classList.add('light'); + root.classList.remove('dark'); + localStorage.setItem('theme', 'light'); + } + }, [isDark]); + useEffect(() => { const onResize = () => setCompact(window.innerWidth < 900); onResize(); @@ -182,38 +207,49 @@ export default function ResponsiveMultiLevelNavigation() { }; return ( -
-
+
+
-

Responsive Multi-Level Navigation

-

Nested routes, adaptive collapse, and route awareness.

+

Responsive Multi-Level Navigation

+

Nested routes, adaptive collapse, and route awareness.

- {compact ? ( +
+ {/* Theme Toggle Button */} - ) : null} + + {compact ? ( + + ) : null} +
-
+
-

Active route

-

+

Active route

+

The current selection is highlighted in the tree and the matching ancestor groups stay open so users never lose context inside a dense information hierarchy.

-
-
Route
-
{activePath}
+
+
Route
+
{activePath}
-
-
Presentation
-
{compact ? "Mobile drawer" : "Desktop sidebar"}
+
+
Presentation
+
{compact ? "Mobile drawer" : "Desktop sidebar"}
-
-
Open sections
-
+
+
Open sections
+
{Object.values(expanded).filter(Boolean).length}
-
-

Preview content

-

+

+

Preview content

+

This layout is designed for admin panels and content-heavy applications. The recursive tree can support additional levels without changing the rendering model, and the mobile drawer preserves usable navigation in narrow screens. @@ -276,7 +312,9 @@ export default function ResponsiveMultiLevelNavigation() { key={path} onClick={() => selectPath(path)} className={`rounded-2xl px-4 py-3 text-left text-sm transition ${ - path === activePath ? "bg-slate-900 text-white" : "bg-slate-50 hover:bg-slate-100" + path === activePath + ? "bg-slate-900 text-white dark:bg-white dark:text-slate-900" + : "bg-slate-50 hover:bg-slate-100 dark:bg-slate-800 dark:hover:bg-slate-700/80 text-slate-700 dark:text-slate-200" }`} > {path} diff --git a/src/index.css b/src/index.css index 99ecbf72..6ca7a387 100644 --- a/src/index.css +++ b/src/index.css @@ -105,3 +105,18 @@ html, body { * { min-width: 0; } + +/* Responsive media */ +img, video { + max-width: 100%; + height: auto; +} + +/* Prevent horizontal scroll on mobile */ +html, body { + overflow-x: hidden; +} + +* { + min-width: 0; +}