forked from nodegui/react-nodegui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRNCheckBox.ts
More file actions
71 lines (68 loc) · 1.97 KB
/
RNCheckBox.ts
File metadata and controls
71 lines (68 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { QCheckBox, NodeWidget, QCheckBoxSignals } from "@nodegui/nodegui";
import { RNWidget } from "../config";
import { throwUnsupported } from "../../utils/helpers";
import {
AbstractButtonProps,
setAbstractButtonProps
} from "../AbstractComponents/RNAbstractButton";
/**
* The CheckBox component provides ability to add and manipulate native button widgets. It is based on
* [NodeGui's QCheckBox](https://docs.nodegui.org/docs/api/QCheckBox).
* ## Example
* ```javascript
* import React from "react";
* import { Renderer, CheckBox, Window } from "@nodegui/react-nodegui";
* const App = () => {
* return (
* <Window>
* <CheckBox style={checkboxStyle} text={"Hello World"} checked={true} />
* </Window>
* );
* };
* const checkboxStyle = `
* color: white;
* `;
* Renderer.render(<App />);
*
* ```
*/
export interface CheckBoxProps extends AbstractButtonProps<QCheckBoxSignals> {
/**
* This property holds whether the button is checked. [QCheckBox: setChecked](https://docs.nodegui.org/docs/api/QCheckBox/#checkboxsetcheckedcheck)
*/
checked?: boolean;
}
const setCheckBoxProps = (
widget: RNCheckBox,
newProps: CheckBoxProps,
oldProps: CheckBoxProps
) => {
const setter: CheckBoxProps = {
set checked(isChecked: boolean) {
widget.setChecked(isChecked);
}
};
Object.assign(setter, newProps);
setAbstractButtonProps(widget, newProps, oldProps);
};
/**
* @ignore
*/
export class RNCheckBox extends QCheckBox implements RNWidget {
setProps(newProps: CheckBoxProps, oldProps: CheckBoxProps): void {
setCheckBoxProps(this, newProps, oldProps);
}
appendInitialChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
appendChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
throwUnsupported(this);
}
removeChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
static tagName = "checkbox";
}