import type { FunctionComponent, ReactNode } from "react"; import React from "react"; import { useBoolean } from "usehooks-ts"; import { LinkIcon, CodeBracketIcon, DocumentArrowDownIcon, ClipboardDocumentIcon, } from "@heroicons/react/24/outline"; type AbstractCardProps = { children?: ReactNode; header?: ReactNode; footer?: ReactNode; data?: object; url?: string; }; const AbstractCard: FunctionComponent = ({ url, children, header, footer, data, }) => { const { value: showRaw, toggle: toggleRaw } = useBoolean(false); return (
{header != undefined || data != undefined ? (
{header}
{url != undefined ? (
) : null} {data != undefined ? ( <>
{ // stringify the JSON object, then begin the async clipboard write navigator.clipboard .writeText(JSON.stringify(data, null, 4)) .then( () => { console.log("Copied to clipboard."); }, (err) => { if (err instanceof Error) console.error( `Failed to copy to clipboard (${err.toString()}).` ); else console.error( "Failed to copy to clipboard." ); } ); }} className="h-6 w-6 cursor-pointer" />
{ const file = new Blob([JSON.stringify(data, null, 4)], { type: "application/json", }); const anchor = document.createElement("a"); anchor.href = URL.createObjectURL(file); anchor.download = "response.json"; anchor.click(); }} className="h-6 w-6 cursor-pointer" />
) : null}
) : null}
{showRaw ? (
						{JSON.stringify(data, null, 4)}
					
) : ( children )}
{footer != null ? (
{footer}
) : null}
); }; export default AbstractCard;