mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-20 05:39:39 +02:00
* chore: add formatting and linting for javascript code relates to #1295 * use spaces instaed * add to recommended extensions * only enforce lint * auto save
28 lines
766 B
JavaScript
28 lines
766 B
JavaScript
import { Controller } from "@hotwired/stimulus";
|
|
|
|
export default class extends Controller {
|
|
static targets = ["source", "iconDefault", "iconSuccess"];
|
|
|
|
copy(event) {
|
|
event.preventDefault();
|
|
if (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);
|
|
}
|
|
}
|