Retrospring/app/javascript/retrospring/controllers/clipboard_controller.ts

23 lines
605 B
TypeScript

import { Controller } from "@hotwired/stimulus";
import I18n from 'retrospring/i18n';
import { showErrorNotification, showNotification } from "retrospring/utilities/notifications";
export default class extends Controller {
static values = {
copy: String
};
declare readonly copyValue: string;
async copy(){
try {
await navigator.clipboard.writeText(this.copyValue);
showNotification(I18n.translate("frontend.clipboard_copy.success"));
} catch (error) {
console.log(error);
showErrorNotification(I18n.translate("frontend.clipboard_copy.error"));
}
}
}