diff --git a/src/components/ErrorPrompt/RNErrorPrompt.ts b/src/components/ErrorPrompt/RNErrorPrompt.ts new file mode 100644 index 0000000..c1b6ae1 --- /dev/null +++ b/src/components/ErrorPrompt/RNErrorPrompt.ts @@ -0,0 +1,38 @@ +import { NodeWidget, QErrorMessage, QErrorMessageSignals } from "@nodegui/nodegui"; +import { throwUnsupported } from "../../utils/helpers"; +import { RNWidget } from "../config"; +import { DialogProps, setDialogProps } from "../Dialog/RNDialog"; + +export interface ErrorPromptProps extends DialogProps { + message: string; +} + +function setErrorPromptProps(widget: RNErrorPrompt, newProps: ErrorPromptProps, oldProps: ErrorPromptProps) { + const setter: ErrorPromptProps = { + set message(message: string) { + widget.showMessage(message); + widget.close(); + }, + }; + Object.assign(setter, newProps); + setDialogProps(widget, newProps, oldProps); +} + +export class RNErrorPrompt extends QErrorMessage implements RNWidget { + setProps(newProps: ErrorPromptProps, oldProps: ErrorPromptProps): void { + setErrorPromptProps(this, newProps, oldProps); + } + appendInitialChild(child: NodeWidget): void { + throwUnsupported(this); + } + appendChild(child: NodeWidget): void { + throwUnsupported(this); + } + insertBefore(child: NodeWidget, beforeChild: NodeWidget): void { + throwUnsupported(this); + } + removeChild(child: NodeWidget): void { + throwUnsupported(this); + } + static tagName = "error-prompt"; +} diff --git a/src/components/ErrorPrompt/index.ts b/src/components/ErrorPrompt/index.ts new file mode 100644 index 0000000..14d987a --- /dev/null +++ b/src/components/ErrorPrompt/index.ts @@ -0,0 +1,43 @@ +import { Fiber } from "react-reconciler"; +import { AppContainer } from "../../reconciler"; +import { ComponentConfig, registerComponent } from "../config"; +import { RNErrorPrompt, ErrorPromptProps } from "./RNErrorPrompt"; + +class ErrorPromptConfig extends ComponentConfig { + tagName: string = RNErrorPrompt.tagName; + shouldSetTextContent(nextProps: ErrorPromptProps): boolean { + return false; + } + createInstance(newProps: ErrorPromptProps, rootInstance: AppContainer, context: any, workInProgress: Fiber): RNErrorPrompt { + const widget = new RNErrorPrompt(); + widget.setProps(newProps, { message: "" }); + return widget; + } + commitMount(instance: RNErrorPrompt, newProps: ErrorPromptProps, internalInstanceHandle: any): void { + if (newProps.visible !== false && newProps.open !== false) { + instance.show(); + } + return; + } + commitUpdate(instance: RNErrorPrompt, updatePayload: any, oldProps: ErrorPromptProps, newProps: ErrorPromptProps, finishedWork: Fiber): void { + instance.setProps(newProps, oldProps); + } +} +/** + * ErrorPrompt inherits the functionality of nodegui's `QErrorMessage` + * @property `message` the message that needs to be displayed + * @example + * ```javascriptreact + * function ErrorApplet(){ + * const [open, setOpen] = useState(false); + * return ( + * + * + *