import { useState } from 'react' import { FaChevronDown, FaRegClipboard, FaTimes } from 'react-icons/fa' import { copy } from 'utils/clipboard' import { Tooltip } from './Tooltip' export interface JsonPreviewProps { title?: string content: unknown initialState?: boolean onClose?: () => void isCopyable?: boolean isToggleable?: boolean /** @deprecated use {@link isCopyable} prop */ copyable?: boolean /** @deprecated use {@link initialState} prop */ isVisible?: boolean } export const JsonPreview = ({ copyable = false, isVisible = true, title = 'JSON Preview', content, initialState = isVisible, onClose, isCopyable = copyable, isToggleable = true, }: JsonPreviewProps) => { const [show, setShow] = useState(() => initialState) const toggle = () => { if (isToggleable) setShow((prev) => !prev) } return (
{title}
{isToggleable && ( )} {isCopyable && ( )} {onClose && ( )}
{show && (
{JSON.stringify(content, null, 2).trim()}
)}
) }