Skip to content

Commit 373996f

Browse files
committed
Add checbox
1 parent 59e2cfa commit 373996f

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Component } from '@angular/core';
66
<window title="Angular app in window!">
77
<view>
88
<text [style.font-size.px]="45">Hello, {{ name }}</text>
9-
9+
<checkbox [checked]="true"></checkbox>
10+
<checkbox [checked]="true" [enabled]="false"></checkbox>
1011
<button [style.background-color]="'green'" (clicked)="setName()">
1112
Green button
1213
</button>

src/lib/components/checkbox.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { QCheckBox } from '@nodegui/nodegui';
2+
import { NgComponent } from './component';
3+
import { RendererStyleFlags2 } from '@angular/core';
4+
import { TextField } from './nodes';
5+
6+
export class NgCheckbox extends QCheckBox implements NgComponent {
7+
public static nodeName = 'checkbox';
8+
public parent: any;
9+
10+
public appendChild(newChild: any): void {
11+
if (newChild instanceof TextField) {
12+
newChild.parent = this;
13+
this.setText(newChild.value);
14+
} else {
15+
console.warn('checkbox may be appendChild only TextField');
16+
}
17+
}
18+
19+
public insertBefore(newChild: any, refChild: any) {}
20+
21+
public setNgAttribute(
22+
name: string,
23+
value: string,
24+
namespace?: string | null
25+
): void {}
26+
27+
public setProperty(name: string, value: boolean): void {
28+
switch (name) {
29+
case 'checked':
30+
this.setChecked(value);
31+
break;
32+
case 'enabled':
33+
this.setEnabled(value);
34+
break;
35+
default:
36+
break;
37+
}
38+
}
39+
40+
public setStyle(
41+
style: string,
42+
value: any,
43+
flags?: RendererStyleFlags2
44+
): void {
45+
this.setInlineStyle(`${style}:${value}`);
46+
}
47+
48+
public setValue(value: string): void {
49+
this.setText(value);
50+
}
51+
52+
removeAttribute(name: string, namespace?: string): void {
53+
throw new Error('Method not implemented.');
54+
}
55+
removeChild(oldChild: any): void {
56+
throw new Error('Method not implemented.');
57+
}
58+
removeClass(name: string): void {
59+
throw new Error('Method not implemented.');
60+
}
61+
removeStyle(style: string, flags?: RendererStyleFlags2): void {
62+
throw new Error('Method not implemented.');
63+
}
64+
}

src/lib/components/components-map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NgComponent } from './component';
44
import { NgWindow } from './window';
55
import { NgText } from './text';
66
import { NgView } from './view';
7+
import { NgCheckbox } from './checkbox';
78

89
export type Constructable<T> = new () => T;
910
export type NgComponentClass = Constructable<NgComponent>;
@@ -20,5 +21,6 @@ export class ComponentsMap {
2021
this.map.set(NgWindow.nodeName, NgWindow);
2122
this.map.set(NgText.nodeName, NgText);
2223
this.map.set(NgView.nodeName, NgView);
24+
this.map.set(NgCheckbox.nodeName, NgCheckbox);
2325
}
2426
}

src/lib/components/nodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { QWidget, QLabel, QPushButton } from '@nodegui/nodegui';
1+
import { QWidget, QLabel, QPushButton, QCheckBox } from '@nodegui/nodegui';
22

33
export class TextField extends QWidget {
4-
public parent: QLabel | QPushButton;
4+
public parent: QLabel | QPushButton | QCheckBox;
55
constructor(public value: string) {
66
super();
77
}

0 commit comments

Comments
 (0)