feat: implement collapsible sidebar navigation with icons and active item detection

This commit is contained in:
mlogclub
2026-05-30 20:00:44 +08:00
parent 86ff71596d
commit 9cabee4d6d
6 changed files with 168 additions and 30 deletions
+24
View File
@@ -0,0 +1,24 @@
export type DashboardNavActiveItem = {
url: string
}
function normalizePath(path: string) {
return path !== "/" ? path.replace(/\/+$/, "") : path
}
export function isDashboardNavItemActive(pathname: string, itemUrl: string) {
const currentPath = normalizePath(pathname)
const targetPath = normalizePath(itemUrl)
if (targetPath === "/" || targetPath === "/dashboard") {
return currentPath === targetPath
}
return currentPath === targetPath || currentPath.startsWith(targetPath + "/")
}
export function dashboardNavSectionHasActiveItem(
items: ReadonlyArray<DashboardNavActiveItem>,
pathname: string
) {
return items.some((item) => isDashboardNavItemActive(pathname, item.url))
}