Skip to content

Commit 896134c

Browse files
committed
Add success hint when copying API keys to clipboard
1 parent 0902992 commit 896134c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Diff for: lib/keila_web/templates/api_key/index.html.heex

+17-5
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,28 @@
3939
<p class="font-bold text-emerald-500">
4040
<%= gettext("Important: The private API Key is displayed only once and cannot be recovered.") %>
4141
</p>
42-
<div class="flex flex-row mt-2">
43-
<input type="text" class="text-white bg-gray-900" readonly value={ @token.key } />
42+
<div class="flex flex-row mt-2 relative" x-data="{showFeedback: false}">
43+
<input
44+
type="text"
45+
class="text-white bg-gray-900"
46+
readonly value={ @token.key }
47+
x-ref="input"
48+
@click="$refs.input.focus(); $refs.input.select()"
49+
/>
4450
<button
4551
class="button"
46-
x-data="{}"
47-
@click="navigator.clipboard.writeText($el.previousElementSibling.value)"
52+
@click="navigator.clipboard.writeText($refs.input.value); showFeedback = true; setTimeout(() => {showFeedback = false}, 2000)"
4853
>
4954
<%= render_icon(:clipboard) %>
50-
<%= gettext("Copy") %>
55+
<%= gettext("Copy to clipboard") %>
5156
</button>
57+
<div
58+
style="display: none"
59+
class="absolute left-0 top-12 bg-green-700 p-2 font-sm rounded text-white"
60+
x-show.transition="showFeedback"
61+
>
62+
<%= gettext("API key copied to clipboard") %>
63+
</div>
5264
</div>
5365
</div>
5466
</div>

0 commit comments

Comments
 (0)