Skip to content

Commit 0e3a319

Browse files
authored
Merge pull request #8641 from Master7130/bread-crumbs-refactor
Breadcrumbs.tsx Refactor
2 parents c8ebaa4 + 3842b48 commit 0e3a319

File tree

1 file changed

+38
-51
lines changed

1 file changed

+38
-51
lines changed

src/components/Breadcrumbs.tsx

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,11 @@
11
import React from "react"
2-
import styled from "@emotion/styled"
32
import { useTranslation } from "gatsby-plugin-react-i18next"
3+
import { Box, UnorderedList, ListItem } from "@chakra-ui/react"
44

55
import Link from "./Link"
66
import { isLang } from "../utils/languages"
77
import { isTranslationKey } from "../utils/translations"
88

9-
const ListContainer = styled.nav`
10-
margin-bottom: 2rem;
11-
list-style-type: none;
12-
/* Avoid header overlap: */
13-
position: relative;
14-
z-index: 1;
15-
`
16-
17-
const List = styled.ol`
18-
margin: 0;
19-
list-style-type: none;
20-
display: flex;
21-
flex-wrap: wrap;
22-
`
23-
24-
const ListItem = styled.li`
25-
margin: 0;
26-
margin-right: 0.5rem;
27-
font-size: 0.875rem;
28-
line-height: 140%;
29-
letter-spacing: 0.04em;
30-
`
31-
32-
const Slash = styled.span`
33-
margin-left: 0.5rem;
34-
color: ${(props) => props.theme.colors.textTableOfContents};
35-
`
36-
37-
const CrumbLink = styled(Link)`
38-
text-decoration: none;
39-
color: ${(props) => props.theme.colors.textTableOfContents};
40-
41-
&:hover {
42-
text-decoration: none;
43-
color: ${(props) => props.theme.colors.primary};
44-
}
45-
46-
&.active {
47-
color: ${(props) => props.theme.colors.primary};
48-
}
49-
`
50-
519
export interface IProps {
5210
slug: string
5311
startDepth?: number
@@ -91,21 +49,50 @@ const Breadcrumbs: React.FC<IProps> = ({
9149
})
9250

9351
return (
94-
<ListContainer aria-label="Breadcrumb" dir="auto" {...restProps}>
95-
<List>
52+
<Box
53+
aria-label="Breadcrumb"
54+
dir="auto"
55+
{...restProps}
56+
as="nav"
57+
marginBottom={8}
58+
listStyleType="none"
59+
position="relative"
60+
zIndex={1}
61+
>
62+
<UnorderedList
63+
display="flex"
64+
flexWrap="wrap"
65+
listStyleType="none"
66+
margin={0}
67+
>
9668
{crumbs.map((crumb, idx) => (
97-
<ListItem key={idx}>
98-
<CrumbLink
69+
<ListItem
70+
key={idx}
71+
margin={0}
72+
marginRight={2}
73+
fontSize="sm"
74+
lineHeight="140%"
75+
letterSpacing="wider"
76+
>
77+
<Link
9978
to={crumb.fullPath}
10079
isPartiallyActive={slug === crumb.fullPath}
80+
textDecoration="none"
81+
color="textTableOfContents"
82+
_hover={{ color: "primary", textDecor: "none" }}
83+
_active={{ color: "primary" }}
10184
>
10285
{crumb.text}
103-
</CrumbLink>
104-
{idx < crumbs.length - 1 && <Slash>/</Slash>}
86+
</Link>
87+
{idx < crumbs.length - 1 && (
88+
<Box as="span" marginLeft={2} color="textTableOfContents">
89+
/
90+
</Box>
91+
)}
10592
</ListItem>
10693
))}
107-
</List>
108-
</ListContainer>
94+
</UnorderedList>
95+
</Box>
10996
)
11097
}
11198

0 commit comments

Comments
 (0)