Navigation

Breadcrumb

Path trail with chevron or slash separators and collapsing middle levels.

react-aria-componentslucide-react

Preview

  1. Home
  2. Companies
  3. Ledgerly
  1. Workspace
  2. Lists
  3. Series B — VP Sales
  1. Home
  2. …
  3. Sequences
  4. Post-event: SaaStr

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components lucide-react
  2. Create a breadcrumb.tsx file and paste the following code into it.

    src/components/ui/breadcrumb.tsx
    "use client";
    
    import { ChevronRight, Slash } from "lucide-react";
    import type { ReactNode } from "react";
    import { Breadcrumb as AriaBreadcrumb, Breadcrumbs, Link } from "react-aria-components";
    import { cx } from "@/utils/cx";
    
    export interface BreadcrumbItem {
      id: string;
      label: string;
      href?: string;
      icon?: ReactNode;
    }
    
    export interface BreadcrumbProps {
      items: BreadcrumbItem[];
      separator?: "chevron" | "slash";
      /** Collapse middle items into "…" when there are more than this many. */
      maxItems?: number;
      className?: string;
    }
    
    /** Path trail. The last item is the current page. */
    export function Breadcrumb({ items, separator = "chevron", maxItems, className }: BreadcrumbProps) {
      const shown: (BreadcrumbItem | "…")[] =
        maxItems && items.length > maxItems ? [items[0]!, "…", ...items.slice(items.length - (maxItems - 1))] : items;
      const Sep = separator === "chevron" ? ChevronRight : Slash;
      return (
        <Breadcrumbs className={cx("flex flex-wrap items-center gap-1.5 text-base", className)}>
          {shown.map((it, i) => (
            <AriaBreadcrumb key={it === "…" ? "ellipsis" : it.id} id={it === "…" ? "ellipsis" : it.id} className="flex items-center gap-1.5">
              {it === "…" ? (
                <span className="px-1 text-fg-muted">…</span>
              ) : (
                <Link
                  href={it.href}
                  className={cx(
                    "inline-flex items-center gap-1.5 rounded-xs outline-none data-focus-visible:shadow-focus [&_svg]:size-4",
                    "text-fg-secondary data-hovered:text-fg data-current:font-medium data-current:text-fg",
                  )}
                >
                  {it.icon}
                  {it.label}
                </Link>
              )}
              {i < shown.length - 1 && <Sep aria-hidden className={cx("text-fg-disabled", separator === "chevron" ? "size-3.5" : "size-3 -rotate-12")} />}
            </AriaBreadcrumb>
          ))}
        </Breadcrumbs>
      );
    }
  3. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.