Compare commits
No commits in common. '8decbdf89957af5055a12114cb3338facfe8dab3' and '4177ccd6fe4c59c38e91a8db6358ddc7cbc84ca9' have entirely different histories.
8decbdf899
...
4177ccd6fe
6 changed files with 7 additions and 81 deletions
@ -1,30 +0,0 @@ |
|||||||
import { Controller } from '@hotwired/stimulus'; |
|
||||||
|
|
||||||
/** |
|
||||||
* Copies data-copy-text-text-value to the clipboard (e.g. full payment URI for wallets). |
|
||||||
*/ |
|
||||||
export default class extends Controller { |
|
||||||
static values = { text: String }; |
|
||||||
|
|
||||||
static targets = ['button']; |
|
||||||
|
|
||||||
async copy() { |
|
||||||
const t = this.textValue ?? ''; |
|
||||||
if (t === '') { |
|
||||||
return; |
|
||||||
} |
|
||||||
try { |
|
||||||
await navigator.clipboard.writeText(t); |
|
||||||
const btn = this.hasButtonTarget ? this.buttonTarget : this.element.querySelector('button'); |
|
||||||
if (btn) { |
|
||||||
const prev = btn.textContent; |
|
||||||
btn.textContent = 'Copied'; |
|
||||||
window.setTimeout(() => { |
|
||||||
btn.textContent = prev; |
|
||||||
}, 2000); |
|
||||||
} |
|
||||||
} catch (e) { |
|
||||||
console.warn('Copy failed', e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue