Skip to content

Commit 4edde8c

Browse files
authored
Support providing button titles through children (#220)
1 parent 0ab482e commit 4edde8c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/components/AbstractComponents/RNAbstractButton.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import { QAbstractButton } from "@nodegui/nodegui";
2525
*/
2626
export interface AbstractButtonProps<Signals extends QAbstractButtonSignals>
2727
extends ViewProps<Signals> {
28+
/**
29+
* Alternative method of providing the button text
30+
*/
31+
children?: string;
2832
/**
2933
* Sets the given text to the button. [QPushButton: setText](https://docs.nodegui.org/docs/api/QPushButton#buttonsettexttext)
3034
*/
@@ -45,6 +49,9 @@ export function setAbstractButtonProps<Signals extends QAbstractButtonSignals>(
4549
oldProps: AbstractButtonProps<Signals>
4650
) {
4751
const setter: AbstractButtonProps<Signals> = {
52+
set children(childrenText: string) {
53+
widget.setText(childrenText);
54+
},
4855
set text(buttonText: string) {
4956
widget.setText(buttonText);
5057
},
@@ -53,7 +60,7 @@ export function setAbstractButtonProps<Signals extends QAbstractButtonSignals>(
5360
},
5461
set iconSize(iconSize: QSize) {
5562
widget.setIconSize(iconSize);
56-
}
63+
},
5764
};
5865
Object.assign(setter, newProps);
5966
setViewProps(widget, newProps, oldProps);

src/demo.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from "react";
2-
import { Renderer, Text, ScrollArea, Window } from "./index";
2+
import { Renderer, Text, ScrollArea, Window, View, Button } from "./index";
33

44
const App = () => {
55
return (
66
<Window>
7-
<ScrollArea>
8-
<Text>
9-
{`
7+
<View style="flex-direction: column">
8+
<Button>Test</Button>
9+
<ScrollArea>
10+
<Text>
11+
{`
1012
Contrary to popular belief,
1113
Lorem Ipsum is not simply random text.
1214
It has roots in a piece of classical Latin literature from 45 BC,
@@ -42,8 +44,9 @@ const App = () => {
4244
sometimes on purpose (injected humour and the like).
4345
4446
`}
45-
</Text>
46-
</ScrollArea>
47+
</Text>
48+
</ScrollArea>
49+
</View>
4750
</Window>
4851
);
4952
};

0 commit comments

Comments
 (0)