|
| 1 | +import { QIcon, QSize } from "@nodegui/nodegui"; |
| 2 | +import { ViewProps, setViewProps } from "../View/RNView"; |
| 3 | +import { QAbstractButton } from "@nodegui/nodegui"; |
| 4 | + |
| 5 | +/** |
| 6 | + * The Button component provides ability to add and manipulate native button widgets. It is based on |
| 7 | + * [NodeGui's QPushButton](https://docs.nodegui.org/docs/api/QPushButton). |
| 8 | + * ## Example |
| 9 | + * ```javascript |
| 10 | + * import React from "react"; |
| 11 | + * import { Renderer, Button, Window } from "@nodegui/react-nodegui"; |
| 12 | + * const App = () => { |
| 13 | + * return ( |
| 14 | + * <Window> |
| 15 | + * <Button style={buttonStyle} text={"Hello World"} /> |
| 16 | + * </Window> |
| 17 | + * ); |
| 18 | + * }; |
| 19 | + * const buttonStyle = ` |
| 20 | + * color: white; |
| 21 | + * `; |
| 22 | + * Renderer.render(<App />); |
| 23 | + * |
| 24 | + * ``` |
| 25 | + */ |
| 26 | +export interface AbstractButtonProps extends ViewProps { |
| 27 | + /** |
| 28 | + * Sets the given text to the button. [QPushButton: setText](https://docs.nodegui.org/docs/api/QPushButton#buttonsettexttext) |
| 29 | + */ |
| 30 | + text?: string; |
| 31 | + /** |
| 32 | + * Sets an icon in the button. [QPushButton: setIcon](https://docs.nodegui.org/docs/api/QPushButton#buttonseticonicon) |
| 33 | + */ |
| 34 | + icon?: QIcon; |
| 35 | + /** |
| 36 | + * Sets an icon size in the button. [QPushButton: setIconSize](https://docs.nodegui.org/docs/api/QPushButton#buttonseticonsize) |
| 37 | + */ |
| 38 | + iconSize?: QSize; |
| 39 | +} |
| 40 | + |
| 41 | +export const setAbstractButtonProps = ( |
| 42 | + widget: QAbstractButton, |
| 43 | + newProps: AbstractButtonProps, |
| 44 | + oldProps: AbstractButtonProps |
| 45 | +) => { |
| 46 | + const setter: AbstractButtonProps = { |
| 47 | + set text(buttonText: string) { |
| 48 | + widget.setText(buttonText); |
| 49 | + }, |
| 50 | + set icon(icon: QIcon) { |
| 51 | + widget.setIcon(icon); |
| 52 | + }, |
| 53 | + set iconSize(iconSize: QSize) { |
| 54 | + widget.setIconSize(iconSize); |
| 55 | + } |
| 56 | + }; |
| 57 | + Object.assign(setter, newProps); |
| 58 | + setViewProps(widget, newProps, oldProps); |
| 59 | +}; |
0 commit comments