"use client"; import { ReactNode, useEffect, useState } from "react"; import { ModuleWithPermissions } from "../../permissions"; import { cn } from "../../utils"; type TitleProps = { type?: string | string[]; element?: string; functions?: ReactNode; className?: string; module?: ModuleWithPermissions; prioritizeFunctions?: boolean; }; export function ContentTitle({ module, type, element, functions, className, prioritizeFunctions }: TitleProps) { const [clientFunctions, setClientFunctions] = useState(null); const [isClient, setIsClient] = useState(false); // Defer function rendering to client-side only to prevent hydration mismatches // caused by Radix UI's dynamic ID generation in Dialog/AlertDialog components useEffect(() => { setIsClient(true); setClientFunctions(functions); }, [functions]); if (!element) return null; return (
{/* Title section - shrinks when prioritizeFunctions is true */}
{/* Type label - never shrinks (stays visible as minimum) */} {type && (
{module && module.icon && } {type}
)} {/* Element (name) - truncates with ellipsis when space is limited */}
{element}
{/* Functions section - doesn't shrink when prioritizeFunctions is true */} {isClient && clientFunctions && (
{clientFunctions}
)}
); }