11import { QIcon , QPushButton , NodeWidget } from "@nodegui/nodegui" ;
2- import { ViewProps , setProps as setViewProps } from "../View/RNView" ;
2+ import { ViewProps , setViewProps } from "../View/RNView" ;
33import { RNWidget } from "../config" ;
44import { throwUnsupported } from "../../utils/helpers" ;
55
6- export class RNButton extends QPushButton implements RNWidget {
7- appendInitialChild ( child : NodeWidget ) : void {
8- throwUnsupported ( this ) ;
9- }
10- appendChild ( child : NodeWidget ) : void {
11- throwUnsupported ( this ) ;
12- }
13- insertBefore ( child : NodeWidget , beforeChild : NodeWidget ) : void {
14- throwUnsupported ( this ) ;
15- }
16- removeChild ( child : NodeWidget ) : void {
17- throwUnsupported ( this ) ;
18- }
19- static tagName = "button" ;
20- }
6+ /**
7+ * The Button component provides ability to add and manipulate native button widgets. It is based on
8+ * [NodeGui's QPushButton](https://docs.nodegui.org/docs/api/QPushButton).
9+ * ## Example
10+ * ```javascript
11+ * import React from "react";
12+ * import { Renderer, Button, Window } from "@nodegui/react-nodegui";
13+ * const App = () => {
14+ * return (
15+ * <Window>
16+ * <Button style={buttonStyle} text={"Hello World"} />
17+ * </Window>
18+ * );
19+ * };
20+ * const buttonStyle = `
21+ * color: white;
22+ * `;
23+ * Renderer.render(<App />);
24+ *
25+ * ```
26+ */
2127export interface ButtonProps extends ViewProps {
28+ /**
29+ * Sets the given text to the button. [QPushButton: setText](https://docs.nodegui.org/docs/api/QPushButton#buttonsettexttext)
30+ */
2231 text ?: string ;
32+ /**
33+ * Sets whether the button border is raised. [QPushButton: setFlat](https://docs.nodegui.org/docs/api/QPushButton#buttonsetflatisflat)
34+ */
2335 flat ?: boolean ;
36+ /**
37+ * Sets an icon in the button. [QPushButton: setIcon](https://docs.nodegui.org/docs/api/QPushButton#buttonseticonicon)
38+ */
2439 icon ?: QIcon ;
2540}
2641
27- export const setProps = (
42+ const setButtonProps = (
2843 widget : RNButton ,
2944 newProps : ButtonProps ,
3045 oldProps : ButtonProps
@@ -43,3 +58,25 @@ export const setProps = (
4358 Object . assign ( setter , newProps ) ;
4459 setViewProps ( widget , newProps , oldProps ) ;
4560} ;
61+
62+ /**
63+ * @ignore
64+ */
65+ export class RNButton extends QPushButton implements RNWidget {
66+ appendInitialChild ( child : NodeWidget ) : void {
67+ throwUnsupported ( this ) ;
68+ }
69+ appendChild ( child : NodeWidget ) : void {
70+ throwUnsupported ( this ) ;
71+ }
72+ insertBefore ( child : NodeWidget , beforeChild : NodeWidget ) : void {
73+ throwUnsupported ( this ) ;
74+ }
75+ removeChild ( child : NodeWidget ) : void {
76+ throwUnsupported ( this ) ;
77+ }
78+ setProps ( newProps : ButtonProps , oldProps : ButtonProps ) {
79+ setButtonProps ( this , newProps , oldProps ) ;
80+ }
81+ static tagName = "button" ;
82+ }
0 commit comments