2023-11-12 03:03:59 -08:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
2023-11-19 03:10:22 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
|
|
|
import { showErrorNotification, showNotification } from "retrospring/utilities/notifications";
|
2023-11-12 03:03:59 -08:00
|
|
|
|
|
|
|
export default class extends Controller {
|
|
|
|
|
|
|
|
static values = {
|
|
|
|
copy: String
|
2023-11-12 03:17:33 -08:00
|
|
|
};
|
2023-11-12 03:03:59 -08:00
|
|
|
|
|
|
|
declare readonly copyValue: string;
|
|
|
|
|
|
|
|
async copy(){
|
2023-11-19 03:10:22 -08:00
|
|
|
try {
|
|
|
|
await navigator.clipboard.writeText(this.copyValue);
|
|
|
|
showNotification(I18n.translate("frontend.clipboard_copy.success"));
|
2023-11-22 08:54:04 -08:00
|
|
|
this.element.dispatchEvent(new CustomEvent('retrospring:copied'));
|
2023-11-19 03:10:22 -08:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
showErrorNotification(I18n.translate("frontend.clipboard_copy.error"));
|
|
|
|
}
|
2023-11-12 03:03:59 -08:00
|
|
|
}
|
|
|
|
}
|