Icon alternative to How to click hyperlink / button to copy text to clipboard?
import param
import panel as pn
from panel.reactive import ReactiveHTML
pn.extension()
class CopyIcon(ReactiveHTML):
value = param.String(default=None, doc="The text to copy to the clipboard.")
_template = """
<div
type="button"
id="copy-button"
onclick="${script('copy_to_clipboard')}"
style="cursor: pointer; width: ${model.width}px; height: ${model.height}px;"
title="Copy to Clipboard"
>
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard-text" width="40" height="40" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"></path>
<path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path>
<path d="M9 12h6"></path>
<path d="M9 16h6"></path>
</svg>
</div>
"""
_scripts = {"copy_to_clipboard": "navigator.clipboard.writeText(`${data.value}`)"}
CopyIcon(value="You got it!")