Make IDs copyable by clicking anywhere in the body

This commit is contained in:
Rūdolfs Ošiņš
2023-11-09 10:55:10 +01:00
parent ca28fc28b2
commit 179f22cf66
8 changed files with 62 additions and 68 deletions
+3 -14
View File
@@ -6,11 +6,9 @@
import { toClipboard } from "@app/lib/utils";
import Icon from "@app/components/Icon.svelte";
import IconSmall from "@app/components/IconSmall.svelte";
export let text: string;
export let small = false;
export let tooltip: string | undefined = undefined;
const dispatch = createEventDispatcher<{ copied: null }>();
@@ -31,18 +29,14 @@
<style>
.clipboard {
width: 2rem;
height: 2rem;
width: 1.5rem;
height: 1.5rem;
cursor: pointer;
display: inline-flex;
justify-content: center;
align-items: center;
user-select: none;
}
.small {
width: 1.5rem;
height: 1.5rem;
}
</style>
<!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -51,11 +45,6 @@
tabindex="0"
title={tooltip}
class="clipboard"
class:small
on:click|stopPropagation={copy}>
{#if small}
<IconSmall name={icon} />
{:else}
<Icon name={icon} />
{/if}
<IconSmall name={icon} />
</span>
+1 -1
View File
@@ -66,7 +66,7 @@
{#if showPrompt}${/if}
{command}
<div class="clipboard">
<Clipboard bind:this={clipboard} small text={command} />
<Clipboard bind:this={clipboard} text={command} />
</div>
</div>
</div>
+33
View File
@@ -0,0 +1,33 @@
<script lang="ts">
import type { SvelteComponent } from "svelte";
import Clipboard from "@app/components/Clipboard.svelte";
export let id: string;
let clipboard: SvelteComponent;
</script>
<style>
.id {
cursor: pointer;
color: var(--color-fill-secondary);
overflow-wrap: anywhere;
display: flex;
align-items: center;
gap: 0.125rem;
width: fit-content;
}
</style>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
role="button"
tabindex="0"
on:click={() => {
clipboard.copy();
}}
class="id">
<span class="txt-overflow global-hash">
<slot>{id}</slot>
</span>
<Clipboard bind:this={clipboard} text={id} />
</div>
+5 -13
View File
@@ -3,7 +3,7 @@
import Avatar from "./Avatar.svelte";
import HoverPopover from "./HoverPopover.svelte";
import Clipboard from "./Clipboard.svelte";
import CopyableId from "./CopyableId.svelte";
export let nodeId: string;
export let alias: string | undefined = undefined;
@@ -29,13 +29,6 @@
height: 1.25rem;
gap: 0.5rem;
}
.node-id {
height: 2.5rem;
padding: 0 0.5rem 0 0.75rem;
display: flex;
align-items: center;
white-space: nowrap;
}
</style>
<HoverPopover
@@ -51,10 +44,9 @@
{/if}
</div>
<div slot="popover" class="node-id">
<span class="global-hash">{formatNodeId(nodeId)}</span>
<span style:color="var(--color-fill-secondary)">
<Clipboard small text={nodeId} />
</span>
<div style:padding="0.5rem 0.5rem 0.5rem 0.75rem" slot="popover">
<CopyableId id={nodeId}>
{formatNodeId(nodeId)}
</CopyableId>
</div>
</HoverPopover>