blob: fd29f90bd241d18c2f5921c9d09a5ece2f43803b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
import { type ForwardRefRenderFunction, forwardRef } from 'react';
import { Nav, VisuallyHidden, type NavProps } from '../../../atoms';
import { NavItem, NavLink, NavList } from '../../../molecules';
import styles from './breadcrumbs.module.scss';
export type BreadcrumbsItem = {
/**
* The item id.
*/
id: string;
/**
* The item label.
*/
label: string;
/**
* The item slug.
*/
slug: string;
};
export type BreadcrumbsProps = Omit<NavProps, 'children'> & {
/**
* The breadcrumbs items.
*/
items: BreadcrumbsItem[];
};
const BreadcrumbsWithRef: ForwardRefRenderFunction<
HTMLElement,
BreadcrumbsProps
> = ({ items, ...props }, ref) => {
const sep = '>';
return (
<Nav {...props} ref={ref}>
<NavList
isInline
isOrdered
// eslint-disable-next-line react/jsx-no-literals
spacing="xs"
>
{items.map((item, index) => {
const isLastItem = items.length === index + 1;
return (
<NavItem key={item.id}>
{isLastItem ? (
<VisuallyHidden>{item.label}</VisuallyHidden>
) : (
<>
<NavLink href={item.slug} label={item.label} />
<span aria-hidden className={styles.sep}>
{sep}
</span>
</>
)}
</NavItem>
);
})}
</NavList>
</Nav>
);
};
export const Breadcrumbs = forwardRef(BreadcrumbsWithRef);
|