// Code: Breadcrumb component
import React from "react";
import UI from "#components/ui";
import { Truncate } from "#libs/content";
import Link from "#components/link/link";
// ============================================================================
// TYPES
// ============================================================================
/**
* Represents a route segment in the breadcrumb navigation.
*
* @remarks
* Each route can customize its display name and URL independently from its path.
* This allows for URL aliasing and custom route naming.
*
* @example
* ```tsx
* const route: CustomRoute = {
* path: "prod",
* name: "Products",
* url: "/products"
* };
* ```
*/
export type CustomRoute = {
/** The path segment as it appears in the URL */
path?: string;
/** The display name shown to users */
name: string;
/** The URL for navigation (defaults to path if not provided) */
url?: string;
};
/**
* Props for the Breadcrumb component.
*
* @remarks
* The component can operate in two modes:
* 1. Automatic mode: Derives path from `currentRoute` prop
* 2. Controlled mode: Uses provided `routes` array for complete control over route naming
*
* @example
* ```tsx
* // Simple automatic mode
*
*
* // Controlled mode with custom route names
*
* ```
*/
export type BreadcrumbProps = {
/** Array of custom route objects for controlled breadcrumb generation */
routes?: CustomRoute[];
/** Starting route node (typically "Home") */
startRoute?: React.ReactNode;
/** Starting route URL (typically "/") */
startRouteUrl?: string;
/** Separator element between breadcrumb items */
spacer?: React.ReactNode;
/** Current route path (required for breadcrumb generation) */
currentRoute?: string;
/** ARIA label for the breadcrumb navigation */
ariaLabel?: string;
/** Maximum character length before truncating breadcrumb text */
truncateLength?: number;
/** Props to spread onto breadcrumb Link components */
linkProps?: Omit, "href" | "children">;
} & Omit, "as" | "aria-label">;
// ============================================================================
// SUB-COMPONENTS
// ============================================================================
/**
* BreadcrumbItem - Individual list item wrapper for breadcrumb segments.
*
* @remarks
* This is a presentational component that wraps each breadcrumb segment.
* Memoized to prevent unnecessary re-renders when parent updates.
*/
const BreadcrumbItem = React.memo(
({
children,
id,
styles,
classes,
...props
}: React.ComponentProps) => {
// Filter out UI-specific props that aren't valid on
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
const { renderStyles, defaultStyles, as, ref, ...validLiProps } = props as any;
return (
{children}
);
}
);
BreadcrumbItem.displayName = "BreadcrumbItem";
/**
* BreadcrumbList - Ordered list container for breadcrumb items.
*
* @remarks
* Uses semantic `` element as recommended by WCAG for breadcrumb navigation.
* Memoized to prevent unnecessary re-renders.
*/
const BreadcrumbList = React.memo(
({ children, ...props }: React.ComponentProps) => {
return (
{children}
);
}
);
BreadcrumbList.displayName = "BreadcrumbList";
/**
* BreadcrumbNav - Navigation wrapper for breadcrumb structure.
*
* @remarks
* Provides semantic `