add copy to clipboard to display result

This commit is contained in:
Ruben Fiszel
2023-08-20 12:11:43 +02:00
parent 27e6a3fd66
commit 8bc7ee50bf
2 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -30,7 +30,7 @@
color="light"
size="xs"
>
<div class="flex gap-2 items-center">Copy to clipboard <ClipboardCopy /> </div>
<div class="flex gap-2 items-center">Copy <ClipboardCopy /> </div>
</Button>
</svelte:fragment>
{#if isString(jsonViewerContent)}
@@ -137,7 +137,8 @@
class="mb-2 w-full text-sm relative"
>The result keys are: <b>{truncate(Object.keys(result).join(', '), 50)}</b>
{#if !disableExpand}
<div class="text-tertiary text-xs absolute top-5.5 right-0">
<div class="text-tertiary text-xs absolute top-5.5 right-0 inline-flex gap-2">
<button on:click={() => copyToClipboard(jsonStr)}><ClipboardCopy size={16} /></button>
<button on:click={jsonViewer.openDrawer}><Expand size={16} /></button>
</div>
{/if}
@@ -280,6 +281,13 @@
<ObjectViewer json={result} />
{:else}
<Highlight language={json} code={jsonStr} />
{#if typeof result == 'string'}
<div class="flex">
<Button size="xs" on:click={() => copyToClipboard(result)} color="light">
<div class="flex gap-2 items-center">Copy <ClipboardCopy size={12} /> </div>
</Button>
</div>
{/if}
{/if}
{/if}
{:else}
@@ -313,7 +321,13 @@
JSON is too large to be displayed in full.
</div>
{:else}
FOO
<Highlight language={json} code={jsonStr.replace(/\\n/g, '\n')} />
{#if typeof result == 'string'}
<Button on:click={() => copyToClipboard(result)} color="light" size="xs">
<div class="flex gap-2 items-center">Copy <ClipboardCopy /> </div>
</Button>
{/if}
{/if}
</DrawerContent>
</Drawer>