-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcopyInput.svelte
48 lines (43 loc) · 1.35 KB
/
copyInput.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { copy } from '$lib/helpers/copy';
import { addNotification } from '$lib/stores/notifications';
export let value: string;
export let label: string = null;
export let showLabel = false;
let content = 'Copy';
const handleCopy = async () => {
const success = await copy(value);
if (success) {
content = 'Copied';
} else {
addNotification({
message: 'Unable to copy to clipboard',
type: 'error'
});
}
};
</script>
<style>
span.icon-duplicate {
cursor: pointer;
}
</style>
<div>
<label class:u-hide={!showLabel} class="label" for={label}>{label}</label>
<div class="input-text-wrapper" style="--amount-of-buttons:1">
<input {value} id={label} type="text" class="input-text" readonly />
<div class="options-list">
<span
class="icon-duplicate" aria-label="Copy"
on:click={handleCopy}
on:mouseenter={() => setTimeout(() => (content = 'Copy'))}
use:tooltip={{
content,
hideOnClick: false,
appendTo: 'parent',
}}
/>
</div>
</div>
</div>