mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-08 02:19:43 +00:00
41 lines
992 B
TypeScript
41 lines
992 B
TypeScript
import { fireEvent } from "../../common/dom/fire_event";
|
|
|
|
export interface EnterCodeDialogParams {
|
|
codeFormat: "text" | "number";
|
|
codePattern?: string;
|
|
submitText?: string;
|
|
cancelText?: string;
|
|
title?: string;
|
|
submit?: (code?: string) => void;
|
|
cancel?: () => void;
|
|
}
|
|
|
|
export const showEnterCodeDialog = (
|
|
element: HTMLElement,
|
|
dialogParams: EnterCodeDialogParams
|
|
) =>
|
|
new Promise<string | null>((resolve) => {
|
|
const origCancel = dialogParams.cancel;
|
|
const origSubmit = dialogParams.submit;
|
|
|
|
fireEvent(element, "show-dialog", {
|
|
dialogTag: "dialog-enter-code",
|
|
dialogImport: () => import("./dialog-enter-code"),
|
|
dialogParams: {
|
|
...dialogParams,
|
|
cancel: () => {
|
|
resolve(null);
|
|
if (origCancel) {
|
|
origCancel();
|
|
}
|
|
},
|
|
submit: (code: string) => {
|
|
resolve(code);
|
|
if (origSubmit) {
|
|
origSubmit(code);
|
|
}
|
|
},
|
|
},
|
|
});
|
|
});
|