Skip to content

Commit 3c5155c

Browse files
committed
Breadcrumbs.tsx Refactor
1 parent 82037ae commit 3c5155c

File tree

1 file changed

+40
-51
lines changed

1 file changed

+40
-51
lines changed

src/components/Breadcrumbs.tsx

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,11 @@
11
import React from "react"
2-
import styled from "@emotion/styled"
32
import { useIntl } from "react-intl"
43

54
import Link from "./Link"
65
import { isLang, supportedLanguages } from "../utils/languages"
76
import { isTranslationKey, translateMessageId } from "../utils/translations"
8-
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-
`
7+
import { Box, UnorderedList, ListItem } from "@chakra-ui/react"
8+
import ButtonLink from "./ButtonLink"
509

5110
export interface IProps {
5211
slug: string
@@ -91,21 +50,51 @@ const Breadcrumbs: React.FC<IProps> = ({
9150
})
9251

9352
return (
94-
<ListContainer aria-label="Breadcrumb" dir="auto" {...restProps}>
95-
<List>
53+
<Box
54+
aria-label="Breadcrumb"
55+
dir="auto"
56+
{...restProps}
57+
as="nav"
58+
marginBottom={8}
59+
listStyleType="none"
60+
position="relative"
61+
zIndex={1}
62+
>
63+
<UnorderedList
64+
display="flex"
65+
flexWrap="wrap"
66+
listStyleType="none"
67+
margin={0}
68+
>
9669
{crumbs.map((crumb, idx) => (
97-
<ListItem key={idx}>
98-
<CrumbLink
70+
<ListItem
71+
key={idx}
72+
margin={0}
73+
marginRight={2}
74+
fontSize="sm"
75+
lineHeight="140%"
76+
letterSpacing="wider"
77+
>
78+
<ButtonLink
79+
as={Link}
9980
to={crumb.fullPath}
10081
isPartiallyActive={slug === crumb.fullPath}
82+
textDecoration="none"
83+
color="textTableOfContents"
84+
_hover={{ color: "primary", textDecor: "none" }}
85+
_active={{ color: "primary" }}
10186
>
10287
{crumb.text}
103-
</CrumbLink>
104-
{idx < crumbs.length - 1 && <Slash>/</Slash>}
88+
</ButtonLink>
89+
{idx < crumbs.length - 1 && (
90+
<Box as="span" marginLeft={2} color="textTableOfContents">
91+
/
92+
</Box>
93+
)}
10594
</ListItem>
10695
))}
107-
</List>
108-
</ListContainer>
96+
</UnorderedList>
97+
</Box>
10998
)
11099
}
111100

0 commit comments

Comments
 (0)