Skip to content

Commit c974a73

Browse files
authored
Merge pull request #8810 from TylerAPfledderer/refactor/use-chakra-breadcrumbs
refactor(breadcrumbs): implement Chakra's `Breadcrumb` component
2 parents 33165ff + e33d876 commit c974a73

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

src/components/Breadcrumbs.tsx

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

510
import Link from "./Link"
6-
import { isLang, supportedLanguages } from "../utils/languages"
11+
import { isLang } from "../utils/languages"
712
import { isTranslationKey, translateMessageId } from "../utils/translations"
813

9-
export interface IProps {
14+
export interface IProps extends BreadcrumbProps {
1015
slug: string
1116
startDepth?: number
1217
}
@@ -49,50 +54,46 @@ const Breadcrumbs: React.FC<IProps> = ({
4954
})
5055

5156
return (
52-
<Box
53-
aria-label="Breadcrumb"
57+
<Breadcrumb
5458
dir="auto"
55-
{...restProps}
56-
as="nav"
57-
marginBottom={8}
58-
listStyleType="none"
5959
position="relative"
60-
zIndex={1}
60+
zIndex="1"
61+
mb={8}
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+
}}
70+
{...restProps}
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)