mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 06:09:38 +02:00
29 lines
776 B
JavaScript
29 lines
776 B
JavaScript
|
import { Controller } from "@hotwired/stimulus"
|
||
|
|
||
|
|
||
|
export default class extends Controller {
|
||
|
static targets = ["source", "iconDefault", "iconSuccess"]
|
||
|
|
||
|
copy(event) {
|
||
|
event.preventDefault();
|
||
|
if (this.sourceTarget && this.sourceTarget.textContent) {
|
||
|
navigator.clipboard.writeText(this.sourceTarget.textContent)
|
||
|
.then(() => {
|
||
|
this.showSuccess();
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
console.error('Failed to copy text: ', error);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
showSuccess() {
|
||
|
this.iconDefaultTarget.classList.add('hidden');
|
||
|
this.iconSuccessTarget.classList.remove('hidden');
|
||
|
setTimeout(() => {
|
||
|
this.iconDefaultTarget.classList.remove('hidden');
|
||
|
this.iconSuccessTarget.classList.add('hidden');
|
||
|
}, 3000);
|
||
|
}
|
||
|
}
|