This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBreadCrumbs.tsx
More file actions
65 lines (56 loc) · 1.74 KB
/
BreadCrumbs.tsx
File metadata and controls
65 lines (56 loc) · 1.74 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
import { ReactElement } from 'react';
import BreadCrumbArrowIcon from '../../icons/ui/BreadCrumbArrowIcon';
import { useStoreActions, useStoreState } from '../../state/Hooks';
import { NavigationModel } from '../../state/Store';
const BreadCrumbs = () => {
const navigation = useStoreState((state) => state.navigation);
const navigateBack = useStoreActions((actions) => actions.navigateBack);
let components: ReactElement[] = [];
let navAt: NavigationModel | undefined = navigation;
let depth = 0;
do {
const curDepth = depth;
if (depth > 0) {
components.push(
<BreadCrumbArrowIcon
className="pl-1 w-5 h-5"
key={`breadcrumb-${curDepth}-arrow`}
color="#6A6A6A"
/>,
);
}
components.push(
<button
className={
curDepth === 0
? 'font-medium text-black ml-1 cursor-default whitespace-nowrap'
: 'text-circle-gray-500 hover:underline hover:text-black overflow-ellipsis whitespace-nowrap'
}
key={`breadcrumb-${curDepth}-link`}
onClick={() => {
curDepth > 0 && navigateBack({ distance: curDepth });
}}
>
{curDepth > 1
? '...'
: navAt.component.Label(navAt.props, navigation.props)}
</button>,
);
if (navAt.component.Icon) {
const Icon = navAt.component.Icon(navAt.props);
Icon &&
components.push(<div key={`breadcrumb-${curDepth}-icon`}>{Icon}</div>);
}
depth++;
navAt = navAt.from;
} while (navAt !== undefined);
components.reverse();
return (
<nav className="px-6">
<div className="flex items-center">
{components.map((component) => component)}
</div>
</nav>
);
};
export default BreadCrumbs;