- format long import statements with consistent line wrapping - apply consistent indentation across client and server modules - remove generated tsconfig.tsbuildinfo file
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import React from 'react';
|
|
import styles from './Breadcrumbs.module.css';
|
|
|
|
export interface BreadcrumbItem {
|
|
label: string;
|
|
icon?: React.ReactNode;
|
|
href?: string;
|
|
onClick?: (e: React.MouseEvent) => void;
|
|
}
|
|
|
|
export interface BreadcrumbsProps {
|
|
items: BreadcrumbItem[];
|
|
separator?: React.ReactNode;
|
|
className?: string;
|
|
}
|
|
|
|
export function Breadcrumbs({ items, separator, className }: BreadcrumbsProps) {
|
|
const sep = separator ?? (
|
|
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
<path
|
|
d="M4 2L8 6L4 10"
|
|
stroke="currentColor"
|
|
strokeWidth="1.5"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
/>
|
|
</svg>
|
|
);
|
|
|
|
return (
|
|
<nav aria-label="Breadcrumb" className={[styles.nav, className].filter(Boolean).join(' ')}>
|
|
<ol className={styles.list}>
|
|
{items.map((item, i) => {
|
|
const isLast = i === items.length - 1;
|
|
return (
|
|
<li key={i} className={styles.item}>
|
|
{isLast ? (
|
|
<span className={styles.current} aria-current="page">
|
|
{item.icon}
|
|
{item.label}
|
|
</span>
|
|
) : item.href ? (
|
|
<a href={item.href} className={styles.link} onClick={item.onClick}>
|
|
{item.icon}
|
|
{item.label}
|
|
</a>
|
|
) : (
|
|
<button type="button" className={styles.link} onClick={item.onClick}>
|
|
{item.icon}
|
|
{item.label}
|
|
</button>
|
|
)}
|
|
{!isLast && <span className={styles.separator}>{sep}</span>}
|
|
</li>
|
|
);
|
|
})}
|
|
</ol>
|
|
</nav>
|
|
);
|
|
}
|