/
Breadcrumbs.tsx
47 lines (42 loc) · 1.19 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
import React from "react";
import styled from "styled-components";
import { Link } from "gatsby";
const StyledList = styled.ul`
display: flex;
font-size: 14px;
margin-bottom: ${({ theme }) => theme.orbit.spaceMedium};
`;
const StyledListItem = styled.li<{ current: boolean }>`
a,
span {
color: ${({ theme, current }) =>
current ? theme.orbit.colorTextLinkPrimary : theme.orbit.colorTextSecondary};
margin-right: ${({ theme }) => theme.orbit.spaceXSmall};
}
`;
interface Props {
trail: Array<{
name: string;
url: string;
}>;
}
const Breadcrumbs = ({ trail }: Props) => {
const root = { name: "Orbit.kiwi", url: "/" };
const fullTrail = [root, ...trail];
return (
<StyledList role="navigation" aria-label="breadcrumbs">
{fullTrail.map(({ name, url }, i) => {
const current = i === fullTrail.length - 1;
return (
<StyledListItem key={url} current={current}>
<Link to={url} aria-label={name} aria-current={current && "page"}>
{name}
</Link>
{i + 1 !== fullTrail.length && <span>/</span>}
</StyledListItem>
);
})}
</StyledList>
);
};
export default Breadcrumbs;