Compare commits
2 Commits
4177ccd6fe
...
8decbdf899
| Author | SHA1 | Date |
|---|---|---|
|
|
8decbdf899 | 1 week ago |
|
|
de3455becf | 1 week ago |
6 changed files with 81 additions and 7 deletions
@ -0,0 +1,30 @@ |
|||||||
|
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