-
Notifications
You must be signed in to change notification settings - Fork 28
/
breadcrumb-item.tsx
39 lines (35 loc) · 1002 Bytes
/
breadcrumb-item.tsx
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
import React, { ComponentProps, FC, MouseEventHandler, ReactNode } from 'react'
import { EbayIcon } from '../ebay-icon'
type ItemAttributes = ComponentProps<'a'> & ComponentProps<'button'>;
type BreadcrumbItemProps = ItemAttributes & {
children: ReactNode;
tag?: 'a' | 'button';
href?: string;
isLastItem?: boolean;
onClick?: MouseEventHandler;
_sp?: string;
navsrc?: string;
}
const BreadcrumbItem: FC<BreadcrumbItemProps> = ({
tag: Item = 'button',
isLastItem = false,
href,
children,
onClick,
...rest
}) => {
const isLink = Item === 'a'
const itemAttr: ItemAttributes = {
...rest,
...isLastItem ? { 'aria-current': 'location' } : {},
href: isLink ? href : undefined,
onClick: isLink ? undefined : onClick
}
return (
<li>
<Item {...itemAttr}>{children}</Item>
{!isLastItem && <EbayIcon name="chevronRight12" />}
</li>
)
}
export default BreadcrumbItem