feat(front/CopyableText): add simple button mode

This commit is contained in:
Alice Gaudon 2022-03-02 11:36:23 +01:00
parent afef367e59
commit 81a62be38d

View File

@ -2,8 +2,9 @@
import Icon from "../utils/Icon.svelte"; import Icon from "../utils/Icon.svelte";
import { fade } from "svelte/transition"; import { fade } from "svelte/transition";
export let title: string; export let title: string | undefined = undefined;
export let content: string; export let content: string;
export let buttonMode: boolean = false;
let contentNode: HTMLElement; let contentNode: HTMLElement;
let copiedOverlay: HTMLElement; let copiedOverlay: HTMLElement;
@ -68,6 +69,11 @@
margin: 8px; margin: 8px;
} }
} }
}
.button-mode-button {
position: relative;
}
.copied-overlay { .copied-overlay {
position: absolute; position: absolute;
@ -80,11 +86,30 @@
text-align: center; text-align: center;
background-color: var(--success); background-color: var(--success);
} }
.content.hidden {
pointer-events: none;
overflow: hidden;
width: 0;
height: 0;
margin: 0;
padding: 0;
position: absolute;
} }
</style> </style>
<div class="copyable-text panel"> {#if buttonMode}
<div class="content hidden" bind:this={contentNode} on:click={selectAll}>{content}</div>
<button class="bold button-mode-button" on:click={copy} title="{content}">
<Icon name="copy"/>
{#if showCopiedOverlay}
<div class="copied-overlay" bind:this={copiedOverlay} out:fade on:mouseleave={releaseOverlay}><Icon name="check"/></div>
{/if}
</button>
{:else}
<div class="copyable-text panel">
<div class="title">{title}</div> <div class="title">{title}</div>
<div class="content" bind:this={contentNode} on:click={selectAll}>{content}</div> <div class="content" bind:this={contentNode} on:click={selectAll}>{content}</div>
<button class="bold copy-button" on:click={copy}><Icon name="copy"/></button> <button class="bold copy-button" on:click={copy}><Icon name="copy"/></button>
@ -92,4 +117,5 @@
{#if showCopiedOverlay} {#if showCopiedOverlay}
<div class="copied-overlay" bind:this={copiedOverlay} out:fade on:mouseleave={releaseOverlay}>Copied!</div> <div class="copied-overlay" bind:this={copiedOverlay} out:fade on:mouseleave={releaseOverlay}>Copied!</div>
{/if} {/if}
</div> </div>
{/if}