Skip to content

Commit 8f8ee9c

Browse files
committed
add copy_to_clipboard_button
1 parent 14f6f35 commit 8f8ee9c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/algora_web/components/core_components.ex

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,43 @@ defmodule AlgoraWeb.CoreComponents do
13371337
"""
13381338
end
13391339

1340+
attr :id, :string, required: true
1341+
attr :value, :string, required: true
1342+
1343+
def copy_to_clipboard_button(assigns) do
1344+
~H"""
1345+
<button
1346+
id={@id}
1347+
phx-hook="CopyToClipboard"
1348+
data-value={@value}
1349+
title={@value}
1350+
phx-click={
1351+
%JS{}
1352+
|> JS.hide(
1353+
to: "##{@id}-copy-icon",
1354+
transition: {"transition-opacity", "opacity-100", "opacity-0"}
1355+
)
1356+
|> JS.show(
1357+
to: "##{@id}-check-icon",
1358+
transition: {"transition-opacity", "opacity-0", "opacity-100"}
1359+
)
1360+
}
1361+
class="relative inline-flex p-0 rounded-lg border-secondary-foreground/20 bg-muted text-foreground/90 cursor-pointer transition-colors whitespace-nowrap items-center justify-center font-medium shadow text-sm focus-visible:outline-secondary-foreground focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none hover:border-secondary-foreground/40 hover:bg-secondary/80 hover:text-foreground border phx-submit-loading:opacity-75 h-6 w-6"
1362+
>
1363+
<.icon
1364+
id={@id <> "-copy-icon"}
1365+
name="tabler-copy"
1366+
class="absolute inset-0 m-auto h-3 w-3 flex items-center justify-center"
1367+
/>
1368+
<.icon
1369+
id={@id <> "-check-icon"}
1370+
name="tabler-check"
1371+
class="absolute inset-0 m-auto hidden h-3 w-3 items-center justify-center"
1372+
/>
1373+
</button>
1374+
"""
1375+
end
1376+
13401377
defdelegate tech_badge(assigns), to: AlgoraWeb.Components.TechBadge
13411378

13421379
defdelegate accordion_item(assigns), to: Accordion

0 commit comments

Comments
 (0)