feat(modal): port Clipboard

This commit is contained in:
Paul Makles
2022-06-18 12:33:22 +01:00
parent d10bd96900
commit 241b9cd27b
9 changed files with 49 additions and 27 deletions

View File

@@ -9,14 +9,15 @@ import type { Client, API } from "revolt.js";
import { ulid } from "ulid";
import Changelog from "./components/Changelog";
import { Error } from "./components/Error";
import Clipboard from "./components/Clipboard";
import Error from "./components/Error";
import MFAEnableTOTP from "./components/MFAEnableTOTP";
import MFAFlow from "./components/MFAFlow";
import MFARecovery from "./components/MFARecovery";
import OutOfDate from "./components/OutOfDate";
import { ShowToken } from "./components/ShowToken";
import { SignOutSessions } from "./components/SignOutSessions";
import { SignedOut } from "./components/SignedOut";
import ShowToken from "./components/ShowToken";
import SignOutSessions from "./components/SignOutSessions";
import SignedOut from "./components/SignedOut";
import { Modal } from "./types";
type Components = Record<string, React.FC<any>>;
@@ -140,10 +141,26 @@ class ModalControllerExtended extends ModalController<Modal> {
),
);
}
/**
* Write text to the clipboard
* @param text Text to write
*/
writeText(text: string) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
} else {
this.push({
type: "clipboard",
text,
});
}
}
}
export const modalController = new ModalControllerExtended({
changelog: Changelog,
clipboard: Clipboard,
error: Error,
mfa_flow: MFAFlow,
mfa_recovery: MFARecovery,