Skip to content

Commit fe9873e

Browse files
refactor(breadcrumbs): implement Chakra's Breadcrumb component
1 parent 0bb725b commit fe9873e

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

src/components/Breadcrumbs.tsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import React from "react"
2-
import { Box, UnorderedList, ListItem } from "@chakra-ui/react"
2+
import {
3+
Box,
4+
UnorderedList,
5+
ListItem,
6+
Breadcrumb,
7+
BreadcrumbItem,
8+
BreadcrumbLink,
9+
BreadcrumbProps,
10+
} from "@chakra-ui/react"
311
import { useIntl } from "react-intl"
412

513
import Link from "./Link"
6-
import { isLang, supportedLanguages } from "../utils/languages"
14+
import { isLang } from "../utils/languages"
715
import { isTranslationKey, translateMessageId } from "../utils/translations"
816

9-
export interface IProps {
17+
export interface IProps extends BreadcrumbProps {
1018
slug: string
1119
startDepth?: number
1220
}
@@ -43,56 +51,49 @@ const Breadcrumbs: React.FC<IProps> = ({
4351
: ""
4452

4553
return {
46-
fullPath: slugChunk.slice(0, idx + 2 + startDepth).join("/") + "/",
54+
fullPath: slugChunk.slice(0, idx + 2 + startDepth).join("/"),
4755
text: text.toUpperCase(),
4856
}
4957
})
5058

5159
return (
52-
<Box
53-
aria-label="Breadcrumb"
60+
<Breadcrumb
5461
dir="auto"
62+
sx={{
63+
// TODO: Move this to `listProps` upon upgrading `@chakra-ui/react`
64+
// to at least v2.4.2
65+
ol: {
66+
m: 0,
67+
lineHeight: 1,
68+
},
69+
}}
5570
{...restProps}
56-
as="nav"
57-
marginBottom={8}
58-
listStyleType="none"
59-
position="relative"
60-
zIndex={1}
6171
>
62-
<UnorderedList
63-
display="flex"
64-
flexWrap="wrap"
65-
listStyleType="none"
66-
margin={0}
67-
>
68-
{crumbs.map((crumb, idx) => (
69-
<ListItem
72+
{crumbs.map((crumb, idx) => {
73+
const isCurrentPage = slug === crumb.fullPath
74+
return (
75+
<BreadcrumbItem
7076
key={idx}
71-
margin={0}
72-
marginRight={2}
77+
isCurrentPage={isCurrentPage}
78+
color="textTableOfContents"
7379
fontSize="sm"
74-
lineHeight="140%"
7580
letterSpacing="wider"
81+
lineHeight="140%"
82+
m={0}
7683
>
77-
<Link
84+
<BreadcrumbLink
85+
as={Link}
7886
to={crumb.fullPath}
79-
isPartiallyActive={slug === crumb.fullPath}
80-
textDecoration="none"
81-
color="textTableOfContents"
87+
isPartiallyActive={isCurrentPage}
8288
_hover={{ color: "primary", textDecor: "none" }}
8389
_active={{ color: "primary" }}
8490
>
8591
{crumb.text}
86-
</Link>
87-
{idx < crumbs.length - 1 && (
88-
<Box as="span" marginLeft={2} color="textTableOfContents">
89-
/
90-
</Box>
91-
)}
92-
</ListItem>
93-
))}
94-
</UnorderedList>
95-
</Box>
92+
</BreadcrumbLink>
93+
</BreadcrumbItem>
94+
)
95+
})}
96+
</Breadcrumb>
9697
)
9798
}
9899

0 commit comments

Comments
 (0)