@@ -10,29 +10,33 @@ import { cx } from "./tools/cx";
1010
1111export type BreadcrumbProps = {
1212 className ?: string ;
13- links : BreadcrumbProps . Link [ ] ;
13+ homeLinkProps ?: RegisteredLinkProps ;
14+ segments : {
15+ label : ReactNode ;
16+ linkProps : RegisteredLinkProps ;
17+ } [ ] ;
18+ currentPageLabel : ReactNode ;
1419 classes ?: Partial < Record < "root" | "button" | "collapse" | "list" | "link" | "text" , string > > ;
1520} ;
1621
17- export namespace BreadcrumbProps {
18- export type Link = {
19- text : ReactNode ;
20- linkProps : RegisteredLinkProps ;
21- isActive ?: boolean ;
22- } ;
23- }
24-
2522/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-breadcrumb> */
2623export const Breadcrumb = memo (
2724 forwardRef < HTMLDivElement , BreadcrumbProps > ( ( props , ref ) => {
28- const { links, className, classes = { } , ...rest } = props ;
25+ const {
26+ className,
27+ homeLinkProps,
28+ segments,
29+ currentPageLabel,
30+ classes = { } ,
31+ ...rest
32+ } = props ;
2933
3034 assert < Equals < keyof typeof rest , never > > ( ) ;
3135
3236 const { t } = useTranslation ( ) ;
3337
3438 const { Link } = getLink ( ) ;
35- const breadcrumbId = useId ( ) ;
39+ const breadcrumbId = `breadcrumb- ${ useId ( ) } ` ;
3640
3741 return (
3842 < nav
@@ -52,21 +56,30 @@ export const Breadcrumb = memo(
5256 < div className = { cx ( fr . cx ( "fr-collapse" ) , classes . collapse ) } id = { breadcrumbId } >
5357 < ol className = { cx ( fr . cx ( "fr-breadcrumb__list" ) , classes . list ) } >
5458 < >
55- { links . map ( link => (
56- < li key = { link . linkProps . href } >
59+ { [
60+ ...( homeLinkProps === undefined
61+ ? [ ]
62+ : [ { "linkProps" : homeLinkProps , "label" : t ( "home" ) } ] ) ,
63+ ...segments
64+ ] . map ( ( { linkProps, label } , i ) => (
65+ < li key = { i } >
5766 < Link
58- { ...link . linkProps }
67+ { ...linkProps }
5968 className = { cx (
6069 fr . cx ( "fr-breadcrumb__link" ) ,
6170 classes . link ,
62- link . linkProps . className
71+ linkProps . className
6372 ) }
64- aria-current = { link . isActive ? "page" : undefined }
6573 >
66- { link . text }
74+ { label }
6775 </ Link >
6876 </ li >
6977 ) ) }
78+ < li >
79+ < a className = { fr . cx ( "fr-breadcrumb__link" ) } aria-current = "page" >
80+ { currentPageLabel }
81+ </ a >
82+ </ li >
7083 </ >
7184 </ ol >
7285 </ div >
@@ -82,7 +95,8 @@ const { useTranslation, addBreadcrumbTranslations } = createComponentI18nApi({
8295 "frMessages" : {
8396 /* spell-checker: disable */
8497 "show breadcrumb" : "Voir le fil d’Ariane" ,
85- "navigation label" : "vous êtes ici"
98+ "navigation label" : "vous êtes ici" ,
99+ "home" : "Acceuil"
86100 /* spell-checker: enable */
87101 }
88102} ) ;
@@ -91,7 +105,8 @@ addBreadcrumbTranslations({
91105 "lang" : "en" ,
92106 "messages" : {
93107 "show breadcrumb" : "Show navigation" ,
94- "navigation label" : "you are here"
108+ "navigation label" : "you are here" ,
109+ "home" : "Home"
95110 }
96111} ) ;
97112
0 commit comments