"use client"; import { RiExpandDiagonalLine } from "@remixicon/react"; import { useEffect, useRef, useState } from "react"; import type { WidgetCardProps } from "@/components/shared/widget-card"; import WidgetCard from "@/components/shared/widget-card"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; const OVERFLOW_THRESHOLD_PX = 16; const EXPANDABLE_CONTENT_CLASSNAME = "max-h-[calc(var(--spacing-custom-height-card)-5rem)] overflow-hidden md:max-h-[calc(100%-5rem)]"; export function ExpandableWidgetCard({ title, subtitle, icon, children, action, }: WidgetCardProps) { const contentRef = useRef(null); const [hasOverflow, setHasOverflow] = useState(false); const [isOpen, setIsOpen] = useState(false); useEffect(() => { const element = contentRef.current; if (!element) return; let frameId = 0; const checkOverflow = () => { cancelAnimationFrame(frameId); frameId = window.requestAnimationFrame(() => { const hasOverflowNow = element.scrollHeight - element.clientHeight > OVERFLOW_THRESHOLD_PX; setHasOverflow((currentValue) => currentValue === hasOverflowNow ? currentValue : hasOverflowNow, ); }); }; checkOverflow(); const resizeObserver = new ResizeObserver(checkOverflow); resizeObserver.observe(element); return () => { cancelAnimationFrame(frameId); resizeObserver.disconnect(); }; }, []); return ( <> ) : null } > {children} {icon} {title} {subtitle ? (

{subtitle}

) : null}
{children}
); }