2025-04-01 16:15:20 +02:00
|
|
|
import React from 'react'
|
|
|
|
|
2025-05-09 18:00:43 +02:00
|
|
|
/**
|
|
|
|
* A component to render breadcrumbs
|
|
|
|
*
|
|
|
|
* This is a pure render component, you need to pass in the data.
|
2025-04-01 16:15:20 +02:00
|
|
|
*
|
2025-05-09 18:00:43 +02:00
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {React.Component} props.Link - A framework specific Link component for client-side routing
|
|
|
|
* @param {array} [props.crumbs = []] - The crumbs, an array with objects with href & label properties
|
|
|
|
* @param {text} title - The title of the current (final) page the breadcrumbs lead to
|
|
|
|
* @returns {JSX.Element}
|
2025-04-01 16:15:20 +02:00
|
|
|
*/
|
|
|
|
export const Breadcrumbs = ({ crumbs = [], title, Link = false }) => {
|
|
|
|
if (Link === false) Link = RegularLink
|
|
|
|
|
|
|
|
return (
|
2025-04-18 08:07:13 +00:00
|
|
|
<div className="tw:tailwind-container tw:p-0">
|
2025-04-01 16:15:20 +02:00
|
|
|
<ul
|
2025-04-18 08:07:13 +00:00
|
|
|
className="tw:flex tw:flex-row tw:items-center tw:gap-2 tw:m-0 tw:py-4"
|
2025-04-01 16:15:20 +02:00
|
|
|
style={{ paddingLeft: 0 }}
|
|
|
|
>
|
2025-04-18 08:07:13 +00:00
|
|
|
<li className="tw:inline">
|
2025-06-01 17:04:47 +02:00
|
|
|
<Link href="/">
|
|
|
|
<b>Home</b>
|
|
|
|
</Link>
|
2025-04-01 16:15:20 +02:00
|
|
|
</li>
|
|
|
|
<Spacer />
|
|
|
|
{crumbs.map((crumb, i) => (
|
2025-05-09 18:00:43 +02:00
|
|
|
<React.Fragment key={i}>
|
|
|
|
<li key={i} className="tw:inline">
|
|
|
|
<Link href={crumb.href}>{crumb.label}</Link>
|
|
|
|
</li>
|
2025-06-01 17:04:47 +02:00
|
|
|
<li key={i} className="tw:inline">
|
|
|
|
<Spacer />
|
|
|
|
</li>
|
2025-05-09 18:00:43 +02:00
|
|
|
</React.Fragment>
|
2025-04-01 16:15:20 +02:00
|
|
|
))}
|
2025-04-18 08:07:13 +00:00
|
|
|
<li className="tw:inline">{title}</li>
|
2025-04-01 16:15:20 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* People can pass in a custom Link component,
|
|
|
|
* which is useful when using one from your framework.
|
|
|
|
* If not, we use a regular a tag
|
|
|
|
*/
|
|
|
|
const RegularLink = ({ href, children }) => <a href={href}>{children}</a>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This goes between breadcrumbs
|
|
|
|
*/
|
2025-04-18 08:07:13 +00:00
|
|
|
const Spacer = () => <li className="tw:inline">»</li>
|