From f0feda0b9bd512340a2bb4e570847f70226ef516 Mon Sep 17 00:00:00 2001 From: KR Tirtho Date: Tue, 6 Apr 2021 09:39:16 -0700 Subject: [PATCH] Added Table, TableItem & ErrorPrompt (#347) * Dialog component created & RNView, RNBoxView was tweaked for Dialog * Added Components: - FileDialog - InputDialog - ProgressDialog Edited: - demo file for testing the dialogs * Added Compoents: - ColorDialog - FontDialog Edited: - Dialog (for adding some props) * updated ProgressBar Example * newly created components were exported * New Components: - Table - TableItem Modified: - demo.tsx !info: Table & TableItem works initially. But some of the functionality need imperative/useRef approach * finalized Table & TableItem * Added ErrorPrompt widget & warnings in Table widget * exported newly created ErrorPrompt & reverted demo to as it was * Fixed error prompt message not changing dynamically --- src/components/ErrorPrompt/RNErrorPrompt.ts | 38 +++++ src/components/ErrorPrompt/index.ts | 43 +++++ src/components/Table/RNTable.ts | 173 ++++++++++++++++++++ src/components/Table/index.ts | 48 ++++++ src/components/TableItem/RNTableItem.ts | 116 +++++++++++++ src/components/TableItem/index.ts | 27 +++ src/index.ts | 3 + 7 files changed, 448 insertions(+) create mode 100644 src/components/ErrorPrompt/RNErrorPrompt.ts create mode 100644 src/components/ErrorPrompt/index.ts create mode 100644 src/components/Table/RNTable.ts create mode 100644 src/components/Table/index.ts create mode 100644 src/components/TableItem/RNTableItem.ts create mode 100644 src/components/TableItem/index.ts 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 ( + * + * + *