-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from bcgov/set-up-breadcrumb-nav
Set up breadcrumb nav
- Loading branch information
Showing
14 changed files
with
255 additions
and
127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
submit-web/src/components/Shared/layout/SideNav/BreadcrumbNav.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from "react"; | ||
import { Box, Breadcrumbs, Typography } from "@mui/material"; | ||
import { Link, useRouterState } from "@tanstack/react-router"; | ||
import { theme } from "@/styles/theme"; | ||
|
||
interface RouteSegment { | ||
title: string; | ||
path: string; | ||
} | ||
|
||
const filterUniqueRoutes = (breadcrumbs: RouteSegment[]) => { | ||
const seenPaths = new Set(); | ||
return breadcrumbs.filter((segment) => { | ||
const isUnique = !seenPaths.has(segment.path); | ||
if (isUnique) { | ||
seenPaths.add(segment.path); | ||
} | ||
return isUnique; | ||
}); | ||
}; | ||
|
||
const BreadcrumbNav: React.FC = () => { | ||
const router = useRouterState(); | ||
const breadcrumbs = router.matches.map((match) => { | ||
const { meta, pathname } = match; | ||
if (meta) | ||
return { | ||
title: meta[0].title, | ||
path: pathname, | ||
}; | ||
}); | ||
|
||
const uniqueBreadcrumbs = filterUniqueRoutes(breadcrumbs as RouteSegment[]); | ||
const isRoot = uniqueBreadcrumbs.length === 1; | ||
|
||
return ( | ||
<> | ||
{!isRoot && ( | ||
<Box | ||
sx={{ | ||
p: 1, | ||
paddingLeft: 5, | ||
borderBottom: "1px solid #0000001A", | ||
}} | ||
> | ||
<Breadcrumbs aria-label="breadcrumb"> | ||
{uniqueBreadcrumbs.map( | ||
(segment: { title: string; path: string }, index: number) => { | ||
const { title, path } = segment; | ||
const isLast = index === uniqueBreadcrumbs.length - 1; | ||
return isLast ? ( | ||
<Typography key={path} color="text.primary"> | ||
{title} | ||
</Typography> | ||
) : ( | ||
<Link | ||
key={path} | ||
style={{ color: theme.palette.primary.dark }} | ||
to={path} | ||
> | ||
{title} | ||
</Link> | ||
); | ||
} | ||
)} | ||
</Breadcrumbs> | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default BreadcrumbNav; |
131 changes: 131 additions & 0 deletions
131
submit-web/src/components/Shared/layout/SideNav/SideNavBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { useState } from "react"; | ||
import { | ||
Box, | ||
List, | ||
ListItem, | ||
ListItemButton, | ||
ListItemText, | ||
} from "@mui/material"; | ||
import { Link } from "@tanstack/react-router"; | ||
import { theme } from "@/styles/theme"; | ||
import { useAuth } from "react-oidc-context"; | ||
import { AuthenticatedRoutes, Routes } from "./SideNavElements"; | ||
import { alpha } from "@mui/system"; | ||
import { useIsMobile } from "@/hooks/common"; | ||
|
||
export default function SideNavBar() { | ||
const { isAuthenticated } = useAuth(); | ||
const [currentPath, setCurrentPath] = useState(window.location.pathname); | ||
const isMobile = useIsMobile(); | ||
|
||
let routeMenuItems = Routes; | ||
|
||
if (isAuthenticated) { | ||
routeMenuItems = routeMenuItems.concat(AuthenticatedRoutes); | ||
} | ||
|
||
return ( | ||
<div> | ||
{!isMobile && ( | ||
<Box | ||
sx={{ | ||
overflow: "auto", | ||
borderRight: "1px solid #0000001A", | ||
width: 240, | ||
height: "calc(100vh - 88px)", | ||
zIndex: 0, | ||
position: "static", | ||
}} | ||
> | ||
<List> | ||
{routeMenuItems.map((route) => ( | ||
<> | ||
<ListItem key={route.name}> | ||
<Link | ||
to={route.path} | ||
onClick={() => setCurrentPath(route.path)} | ||
style={{ | ||
color: theme.palette.primary.light, | ||
fontWeight: "bold", | ||
textDecoration: "none", | ||
width: "100%", | ||
}} | ||
> | ||
<ListItemButton | ||
sx={{ | ||
pl: "2rem", | ||
backgroundColor: | ||
currentPath === route.path | ||
? alpha(theme.palette.secondary.main, 0.1) | ||
: theme.palette.primary.light, | ||
borderLeft: `4px solid ${theme.palette.primary.main}`, | ||
}} | ||
> | ||
<span | ||
style={{ | ||
color: alpha(theme.palette.primary.main, 0.8), | ||
}} | ||
> | ||
{route.name} | ||
</span> | ||
</ListItemButton> | ||
</Link> | ||
</ListItem> | ||
{route.routes && route.routes?.length > 0 && ( | ||
<List disablePadding key={`list-${route.name}`}> | ||
{route.routes?.map((subRoute) => ( | ||
<ListItem | ||
key={`sub-list-${subRoute?.name}`} | ||
sx={{ margin: 0, padding: 0 }} | ||
> | ||
<Link | ||
to={subRoute.path} | ||
onClick={() => setCurrentPath(subRoute.path)} | ||
style={{ | ||
textDecoration: "none", | ||
margin: 0, | ||
padding: 0, | ||
color: "inherit", | ||
}} | ||
activeProps={{ | ||
style: { | ||
color: theme.palette.primary.main, | ||
fontWeight: | ||
currentPath === subRoute.path | ||
? "bold" | ||
: "normal", | ||
width: "100%", | ||
}, | ||
}} | ||
> | ||
<ListItemButton | ||
key={`sub-list-button-${subRoute?.name}`} | ||
sx={{ | ||
marginLeft: "40px", | ||
borderLeft: | ||
currentPath === subRoute.path | ||
? `4px solid ${theme.palette.primary.main}` | ||
: `1px solid ${theme.palette.divider}`, | ||
}} | ||
> | ||
<ListItemText | ||
key={`sub-list-text-${subRoute?.name}`} | ||
> | ||
<span style={{ color: "inherit" }}> | ||
{subRoute.name} | ||
</span> | ||
</ListItemText> | ||
</ListItemButton> | ||
</Link> | ||
</ListItem> | ||
))} | ||
</List> | ||
)} | ||
</> | ||
))} | ||
</List> | ||
</Box> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useMediaQuery, useTheme } from "@mui/material"; | ||
|
||
export const useIsMobile = () => { | ||
const theme = useTheme(); | ||
const isMobile = useMediaQuery(theme.breakpoints.down("sm")); | ||
|
||
return isMobile; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.