import PropTypes from 'prop-types'; import { Link as RouterLink } from 'react-router-dom'; import { Breadcrumbs, Link, ThemeProvider, Typography } from '@mui/material'; import { theme } from './theme'; interface Props { breadcrumbs: IBreadcrumb[]; } export interface IBreadcrumb { label: string; to?: string; href?: string; } export const Breadcrumb = (props: Props) => { const { breadcrumbs } = props; const isLast = (index: number) => { return index + 1 === breadcrumbs.length; }; const renderBreadcrumb = (item: IBreadcrumb, index: number) => { if (isLast(index)) { return {item.label}; } return renderLink(item); }; const renderLink = (breadcrumb: IBreadcrumb) => { return breadcrumb.to ? ( {breadcrumb.label} ) : ( {breadcrumb.label} ); }; return ( {breadcrumbs.map((item, i) => renderBreadcrumb(item, i))} ); }; Breadcrumb.propTypes = { breadcrumbs: PropTypes.array.isRequired, };