import * as Collapsible from "@radix-ui/react-collapsible" import clsx from "clsx" import { useMemo, useState } from "react" import { JSONTree } from "react-json-tree" import useClipboard from "../../../hooks/use-clipboard" import Button from "../../fundamentals/button" import ChevronDownIcon from "../../fundamentals/icons/chevron-down" import ClipboardCopyIcon from "../../fundamentals/icons/clipboard-copy-icon" type JSONViewProps = { data: object } const JSONView = ({ data }: JSONViewProps) => { const [expanded, setExpanded] = useState(false) const [isCopied, handleCopy] = useClipboard( JSON.stringify(data, undefined, 2), { successDuration: 5500, onCopied: () => {}, } ) const length = useMemo(() => { return Object.keys(data).length }, [data]) return (

{expanded ? "{" : length > 0 ? "{ ... }" : "{}"}

({length} {length === 1 ? "item" : "items"})
false} />
{expanded &&

{`}`}

}
{isCopied && ( Copied! )}
) } export default JSONView