Skip to content

Commit 7f1d64d

Browse files
committed
Add basic support for PlainTextEdit
1 parent 235a8bc commit 7f1d64d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/components/PlainTextEdit/index.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import { registerComponent } from "../config";
3+
import { QPlainTextEdit, QPlainTextEditEvents } from "@nodegui/nodegui";
4+
import { ViewProps, setProps as setViewProps } from "../View";
5+
6+
interface PlainTextEditProps extends ViewProps {
7+
children?: string;
8+
text?: string;
9+
}
10+
11+
const setProps = (
12+
widget: QPlainTextEdit,
13+
newProps: PlainTextEditProps,
14+
oldProps: PlainTextEditProps
15+
) => {
16+
const setter: PlainTextEditProps = {
17+
set text(text: string) {
18+
text ? widget.setPlainText(text) : widget.clear();
19+
},
20+
};
21+
Object.assign(setter, newProps);
22+
setViewProps(widget, newProps, oldProps);
23+
};
24+
25+
export const PlainTextEdit = registerComponent<PlainTextEditProps>({
26+
id: "plaintextedit",
27+
getContext() {
28+
return {};
29+
},
30+
shouldSetTextContent: () => {
31+
return true;
32+
},
33+
createInstance: newProps => {
34+
const widget = new QPlainTextEdit();
35+
setProps(widget, newProps, {});
36+
return widget;
37+
},
38+
finalizeInitialChildren: () => {
39+
return false;
40+
},
41+
commitMount: (instance, newProps, internalInstanceHandle) => {
42+
return;
43+
},
44+
prepareUpdate: (
45+
instance,
46+
oldProps,
47+
newProps,
48+
rootContainerInstance,
49+
hostContext
50+
) => {
51+
return true;
52+
},
53+
commitUpdate: (instance, updatePayload, oldProps, newProps, finishedWork) => {
54+
setProps(instance as QPlainTextEdit, newProps, oldProps);
55+
}
56+
});

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { Text } from "./components/Text";
44
export { Button } from "./components/Button";
55
export { CheckBox } from "./components/CheckBox";
66
export { LineEdit } from "./components/LineEdit";
7+
export { PlainTextEdit } from "./components/PlainTextEdit";
78
export { ProgressBar } from "./components/ProgressBar";
89
export { RadioButton } from "./components/RadioButton";
910
export { Image } from "./components/Image";

0 commit comments

Comments
 (0)