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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
678 B
TypeScript
Raw Normal View History

2023-11-12 03:03:59 -08:00
import { Controller } from "@hotwired/stimulus";
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(){
try {
await navigator.clipboard.writeText(this.copyValue);
showNotification(I18n.translate("frontend.clipboard_copy.success"));
this.element.dispatchEvent(new CustomEvent('retrospring:copied'));
} catch (error) {
console.log(error);
showErrorNotification(I18n.translate("frontend.clipboard_copy.error"));
}
2023-11-12 03:03:59 -08:00
}
}