-
Notifications
You must be signed in to change notification settings - Fork 3
/
Breadcrumbs.tsx
73 lines (69 loc) · 2.03 KB
/
Breadcrumbs.tsx
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
import {
Breadcrumbs as MuiBreadcrumbs,
breadcrumbsClasses
} from "@mui/material";
import React, { Children, isValidElement } from "react";
import { BreadcrumbsProps } from "./Breadcrumbs.types";
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
import TruncatedTooltip from "../TruncatedTooltip/TruncatedTooltip";
/**
* Breadcrumbs component.
* Renders components passed as children and wraps
* them in a truncated tooltip with separators.
*/
function Breadcrumbs({
children,
separator = <NavigateNextIcon fontSize="small" />,
...rest
}: BreadcrumbsProps) {
/**
* Map children and wrap the final item in a truncated tooltip with separators
*/
const mappedChildren = Children.map(children, (child, i) =>
child && isValidElement(child) ? (
Children.count(children) === i + 1 ? (
<TruncatedTooltip>{child}</TruncatedTooltip>
) : (
child
)
) : null
);
return (
<MuiBreadcrumbs
aria-label="breadcrumbs"
separator={separator}
// style overrides to style children
sx={{
// Ensure that the breadcrumbs do not wrap
[`& .${breadcrumbsClasses.ol}`]: {
flexWrap: "nowrap",
whiteSpace: "nowrap"
},
[`& .${breadcrumbsClasses.li}`]: {
// All breadcrumb children have styled text, decoration and block for overflow
"& *": {
color: "text.secondary",
textDecoration: "none"
// Ensure children of block level elements are inline for ellipsis rendering
},
"&:last-child": {
flexShrink: 1
},
flexShrink: 0,
overflow: "hidden"
},
[`& .${breadcrumbsClasses.li}:last-child *`]: {
color: "text.primary",
textDecoration: "none"
},
[`& .${breadcrumbsClasses.li}:not(:last-child):hover a`]: {
textDecoration: "underline"
}
}}
{...rest}
>
{children ? mappedChildren : null}
</MuiBreadcrumbs>
);
}
export default Breadcrumbs;