"use client"; import * as React from "react"; import { cn } from "./lib/utils"; export interface BreadcrumbItemData { label: string; href?: string; active?: boolean; } export interface BreadcrumbDropdownProps extends React.HTMLAttributes { items: BreadcrumbItemData[]; maxVisible?: number; separator?: string; className?: string; } export function BreadcrumbDropdown({ items = [], maxVisible = 3, separator = "/", className, ...props }: BreadcrumbDropdownProps) { const [isDropdownOpen, setIsDropdownOpen] = React.useState(false); const dropdownRef = React.useRef(null); React.useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) { setIsDropdownOpen(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); if (items.length <= maxVisible) { return ( ); } // If items > maxVisible, collapse the middle items into a dropdown const firstItem = items[0]; const lastItem = items[items.length - 1]; const hiddenItems = items.slice(1, items.length - 1); return ( ); }