From 376e43c4557a4845cacab614a32a4879253c809c Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Tue, 28 Nov 2023 16:06:30 -0500 Subject: [PATCH] Adding renderLink optional prop to Breadcrumbs so we can override the default anchor and pass a Link component --- src/components/Breadcrumbs/Breadcrumbs.tsx | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/components/Breadcrumbs/Breadcrumbs.tsx b/src/components/Breadcrumbs/Breadcrumbs.tsx index 291fc73fd..3868febd1 100644 --- a/src/components/Breadcrumbs/Breadcrumbs.tsx +++ b/src/components/Breadcrumbs/Breadcrumbs.tsx @@ -1,3 +1,5 @@ +import { ReactNode } from 'react' + import { Box, BoxProps } from '~/components/Box' import { Divider } from '~/components/Divider' import { Text } from '~/components/Text' @@ -10,10 +12,11 @@ interface Path { type BreadcrumbsProps = BoxProps & { excludeDivider?: boolean paths: Path[] + renderLink?: (path: Path, children: ReactNode) => JSX.Element } export const Breadcrumbs = (props: BreadcrumbsProps) => { - const { paths, excludeDivider = false, ...rest } = props + const { paths, excludeDivider = false, renderLink, ...rest } = props return ( @@ -22,6 +25,7 @@ export const Breadcrumbs = (props: BreadcrumbsProps) => { key={idx} path={path} active={idx === paths.length - 1} + renderLink={renderLink} /> ))} @@ -33,10 +37,15 @@ export const Breadcrumbs = (props: BreadcrumbsProps) => { interface BreadcrumbSegmentProps { path: Path active?: boolean + renderLink?: (path: Path, children: ReactNode) => JSX.Element } +const defaultRenderLink = (path: Path, children: ReactNode) => ( + {children} +) + const BreadcrumbSegment = (props: BreadcrumbSegmentProps) => { - const { path, active } = props + const { path, active, renderLink = defaultRenderLink } = props return active ? ( { {path.label} ) : ( - - {path.label} - {' / '} - + renderLink( + path, + + {path.label} + {' / '} + + ) ) }