diff --git a/src/components/@shared/DebugOutput/index.module.css b/src/components/@shared/DebugOutput/index.module.css index 563a26c1a..333252beb 100644 --- a/src/components/@shared/DebugOutput/index.module.css +++ b/src/components/@shared/DebugOutput/index.module.css @@ -1,5 +1,6 @@ .debugOutput { margin-top: var(--spacer); + position: relative; } .debugOutput h5 { @@ -47,3 +48,52 @@ word-break: break-all; overflow-wrap: break-word; } + +.header { + display: flex; + align-items: center; + justify-content: space-between; +} + +.copyButton { + position: relative; + background: transparent; + border: none; + cursor: pointer; + padding: 4px; + border-radius: 6px; + font-size: 18px; + line-height: 1; + color: #04bd45; + margin-bottom: 0.5rem; + margin-right: 0.5rem; +} + +.copyButton:hover { + background-color: rgba(0, 0, 0, 0.05); +} + +.icon { + display: inline-block; +} + +.tooltip { + position: absolute; + top: -28px; + right: 0; + background-color: #303031; + color: #ffffff; + font-size: 11px; + padding: 4px 8px; + border-radius: 6px; + white-space: nowrap; + opacity: 0; + pointer-events: none; + transform: translateY(4px); + transition: opacity 0.15s ease, transform 0.15s ease; +} + +.copyButton:hover .tooltip { + opacity: 1; + transform: translateY(0); +} diff --git a/src/components/@shared/DebugOutput/index.tsx b/src/components/@shared/DebugOutput/index.tsx index 983c0e60b..638ff9d95 100644 --- a/src/components/@shared/DebugOutput/index.tsx +++ b/src/components/@shared/DebugOutput/index.tsx @@ -1,4 +1,4 @@ -import { ReactElement } from 'react' +import { ReactElement, useState } from 'react' import styles from './index.module.css' export default function DebugOutput({ @@ -10,11 +10,43 @@ export default function DebugOutput({ output: any large?: boolean }): ReactElement { + const jsonString = JSON.stringify(output, null, 2) + const [copied, setCopied] = useState(false) + + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(jsonString) + setCopied(true) + + setTimeout(() => { + setCopied(false) + }, 2000) + } catch (e) { + console.error('Failed to copy output', e) + } + } + return (
- {title &&
{title}
} + {title && ( +
+
{title}
+ + +
+ )} +
-        {JSON.stringify(output, null, 2)}
+        {jsonString}
       
)