import { Maximize2 } from "lucide-react"; import { useCallback, useRef, useState, type ReactNode } from "react"; import { Button } from "~/components/primitives/Buttons"; import { ShortcutKey } from "~/components/primitives/ShortcutKey"; import { SimpleTooltip } from "~/components/primitives/Tooltip"; import { useShortcutKeys } from "~/hooks/useShortcutKeys"; import { cn } from "~/utils/cn"; import { Dialog, DialogContent, DialogHeader } from "../Dialog"; import { Card } from "./Card"; type ChartCardProps = { /** Title shown in the card header (and the fullscreen dialog header). */ title: ReactNode; /** Chart content. Also used in the fullscreen dialog unless `fullscreenChildren` is set. */ children: ReactNode; /** Optional distinct content for the fullscreen dialog (defaults to `children`). */ fullscreenChildren?: ReactNode; /** Show the maximize button + enable the fullscreen dialog. Defaults to true. */ maximizable?: boolean; /** Extra classes for the inner Card. */ className?: string; }; /** * Chart card with a title and an optional "Maximize" button that opens the chart * fullscreen. Mirrors the dashboard QueryWidget (hover-revealed button + "v" shortcut). */ export function ChartCard({ title, children, fullscreenChildren, maximizable = true, className, }: ChartCardProps) { const [isFullscreen, setIsFullscreen] = useState(false); const containerRef = useRef(null); // "v" toggles fullscreen for the hovered card. useShortcutKeys({ shortcut: { key: "v" }, action: useCallback(() => { const isHovered = containerRef.current?.matches(":hover"); if (!isFullscreen && !isHovered) return; setIsFullscreen((prev) => !prev); }, [isFullscreen]), disabled: !maximizable, }); return (
{title}
{maximizable && (
); }