-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathExampleBreadcrumbs.tsx
More file actions
130 lines (118 loc) · 5.66 KB
/
Copy pathExampleBreadcrumbs.tsx
File metadata and controls
130 lines (118 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { ReactNode, useMemo } from "react";
import { Button, Typography } from "@mui/material";
import HomeIcon from "@mui/icons-material/Home";
import { getExampleCategoryPath, MENU_ITEMS_HIERARCHY } from "../AppRouter/examples";
import { BreadcrumbsWithMenu, TBreadcrumbItem, TBreadcrumbPath } from "./GenericBreadcrumbs";
import { appTheme } from "../Examples/theme";
import { TExamplePage } from "../AppRouter/examplePages";
import { useExampleRouteParams, getFrameworkContent } from "../../helpers/shared/Helpers/frameworkParametrization";
import { useNavigate } from "react-router-dom";
// TODO TMenuItem is not consistent with tree-like format and doesn't really fit this structure, thus special handling of the leaf nodes is required
const onBreadcrumbPathChange = (value: TBreadcrumbPath) => {};
export const ExampleBreadcrumbs = () => {
const { isIFrame, currentExample, framework: selectedFramework } = useExampleRouteParams();
const memoizedMenuPath = useMemo(() => getExampleCategoryPath(currentExample), [currentExample]);
return (
<BreadcrumbsWithMenu
items={MENU_ITEMS_HIERARCHY as TBreadcrumbItem[]}
path={memoizedMenuPath}
onChange={onBreadcrumbPathChange}
breadcrumbPropsMapper={(breadcrumb: TBreadcrumbItem) => {
let link: string;
let title: string;
let labelContent: ReactNode;
let menuItems: TBreadcrumbItem[] = undefined;
if (!breadcrumb.submenu) {
// leaf nodes (specific examples handling)
link = (breadcrumb as TExamplePage).path;
title = getFrameworkContent(breadcrumb.title, selectedFramework);
labelContent = getFrameworkContent(breadcrumb.title, selectedFramework) || "Loading...";
} else if (breadcrumb.id === "home") {
// Home menu item handling
link = `/${selectedFramework}`;
title = "Home Page Gallery";
labelContent = (
<HomeIcon
sx={{
// align in center
verticalAlign: "middle",
}}
/>
);
menuItems = [];
} else {
// inner menu category handling
link = `/${selectedFramework}#${breadcrumb.id}`;
title = breadcrumb.title;
labelContent = breadcrumb.title;
}
const label = (
<Button
sx={{
display: "inline-block",
padding: 0,
minWidth: "unset",
textWrap: "nowrap",
overflow: "hidden",
textOverflow: { xs: "ellipsis", md: "unset", lg: "unset" },
textTransform: "unset",
color: "var(--light-blue)",
"&:hover": { textDecoration: "underline" },
}}
>
{labelContent}
</Button>
);
return { link, label, title, menuItems };
}}
breadcrumbMenuItemsMapper={(breadcrumb: TBreadcrumbItem) => {
let link: string;
let title: string;
let labelContent: ReactNode;
if (!breadcrumb.submenu) {
// leaf nodes (specific examples handling)
link = (breadcrumb as TExamplePage).path;
title = getFrameworkContent(breadcrumb.title, selectedFramework);
labelContent = getFrameworkContent(breadcrumb.title, selectedFramework);
} else {
// inner menu category handling
link = `/${selectedFramework}#${breadcrumb.id}`;
title = breadcrumb.title;
labelContent = breadcrumb.title;
}
const label = (
<Typography
sx={{
padding: 0,
minWidth: "unset",
textTransform: "unset",
textDecoration: "none",
color: "var(--text)",
// "&:hover": { textDecoration: "underline" },
}}
onClick={(e) => {
e.preventDefault();
// Handle same-page navigation
if (window.location.pathname === `/${selectedFramework}`) {
const hash = link.split("#")[1];
const element = document.getElementById(hash);
if (element) {
element.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
window.history.replaceState(null, "", link);
} else {
window.location.href = link;
}
}}
>
{labelContent}
</Typography>
);
return { link, label, title };
}}
/>
);
};