|
1 | 1 | import React, { useState } from "react";
|
2 |
| -import { Renderer, Text, Window, View, Button, useEventHandler } from "./index"; |
3 |
| -import { GridView } from "./components/GridView"; |
4 |
| -import { GridRow } from "./components/GridView/GridRow"; |
5 |
| -import { GridColumn } from "./components/GridView/GridColumn"; |
6 |
| -import { QPushButtonSignals } from "@nodegui/nodegui"; |
| 2 | +import { Renderer, Window, Button } from "./index"; |
| 3 | +import { BoxView } from "./components/BoxView"; |
| 4 | +import { useEventHandler } from "./hooks"; |
| 5 | +import { QPushButtonSignals, Direction } from "@nodegui/nodegui"; |
7 | 6 |
|
8 | 7 | const App = () => {
|
9 |
| - const [additionalRows, setAdditionalRows] = useState<string[]>([]); |
10 |
| - const [rowStretch, setRowStretch] = useState(false); |
| 8 | + const [additionalButtons, setAdditionalButtons] = useState<string[]>([]); |
| 9 | + const [direction, setDirection] = useState<Direction>(Direction.LeftToRight); |
11 | 10 |
|
12 |
| - const [additionalColumns, setAdditionalColumns] = useState<string[]>([]); |
13 |
| - |
14 |
| - const insertRowHandler = useEventHandler<QPushButtonSignals>( |
15 |
| - { |
16 |
| - clicked: () => |
17 |
| - setAdditionalRows((rows) => [...rows, `Row ${rows.length}`]), |
18 |
| - }, |
19 |
| - [] |
20 |
| - ); |
21 |
| - |
22 |
| - const removeRowHandler = useEventHandler<QPushButtonSignals>( |
| 11 | + const addHandler = useEventHandler<QPushButtonSignals>( |
23 | 12 | {
|
24 | 13 | clicked: () =>
|
25 |
| - setAdditionalRows((rows) => [...rows.slice(0, rows.length - 1)]), |
26 |
| - }, |
27 |
| - [] |
28 |
| - ); |
29 |
| - |
30 |
| - const insertColumnHandler = useEventHandler<QPushButtonSignals>( |
31 |
| - { |
32 |
| - clicked: () => |
33 |
| - setAdditionalColumns((columns) => [ |
34 |
| - ...columns, |
35 |
| - `Column ${columns.length}`, |
| 14 | + setAdditionalButtons((buttons) => [ |
| 15 | + ...buttons, |
| 16 | + `Button ${buttons.length}`, |
36 | 17 | ]),
|
37 | 18 | },
|
38 | 19 | []
|
39 | 20 | );
|
40 | 21 |
|
41 |
| - const removeColumnsHandler = useEventHandler<QPushButtonSignals>( |
| 22 | + const removeHandler = useEventHandler<QPushButtonSignals>( |
42 | 23 | {
|
43 | 24 | clicked: () =>
|
44 |
| - setAdditionalColumns((columns) => [ |
45 |
| - ...columns.slice(0, columns.length - 1), |
46 |
| - ]), |
| 25 | + setAdditionalButtons((buttons) => buttons.slice(0, buttons.length - 1)), |
47 | 26 | },
|
48 | 27 | []
|
49 | 28 | );
|
50 | 29 |
|
51 |
| - const toggleRowStretch = useEventHandler<QPushButtonSignals>( |
| 30 | + const toggleDirection = useEventHandler<QPushButtonSignals>( |
52 | 31 | {
|
53 |
| - clicked: () => setRowStretch((value) => !value), |
| 32 | + clicked: () => |
| 33 | + setDirection((prevDirection) => ((prevDirection + 1) % 4) as Direction), |
54 | 34 | },
|
55 | 35 | []
|
56 | 36 | );
|
57 | 37 |
|
58 | 38 | return (
|
59 | 39 | <Window>
|
60 |
| - <GridView |
61 |
| - style="flex: 1" |
62 |
| - columnProps={{ |
63 |
| - 0: { |
64 |
| - minWidth: 200, |
65 |
| - }, |
66 |
| - 1: { |
67 |
| - minWidth: 300, |
68 |
| - }, |
69 |
| - }} |
70 |
| - rowProps={{ |
71 |
| - 0: { |
72 |
| - stretch: rowStretch ? 2 : undefined, |
73 |
| - minHeight: 400, |
74 |
| - }, |
75 |
| - 1: { |
76 |
| - stretch: !rowStretch ? 2 : undefined, |
77 |
| - }, |
78 |
| - }} |
79 |
| - > |
80 |
| - <GridRow> |
81 |
| - <GridColumn width={2}> |
82 |
| - <View style="background-color: red"> |
83 |
| - <Text>Hello</Text> |
84 |
| - <Button text="Insert row" on={insertRowHandler} /> |
85 |
| - <Button text="Remove row" on={removeRowHandler} /> |
86 |
| - <Button text="Toggle row stretch" on={toggleRowStretch} /> |
87 |
| - <Button text="Insert column" on={insertColumnHandler} /> |
88 |
| - <Button text="Remove column" on={removeColumnsHandler} /> |
89 |
| - </View> |
90 |
| - </GridColumn> |
91 |
| - <GridColumn width={2}> |
92 |
| - <View style="background-color: blue"> |
93 |
| - <Text>Second Column</Text> |
94 |
| - </View> |
95 |
| - </GridColumn> |
96 |
| - <> |
97 |
| - {additionalColumns.map((column) => ( |
98 |
| - <GridColumn key={column}> |
99 |
| - <Text>{column}</Text> |
100 |
| - </GridColumn> |
101 |
| - ))} |
102 |
| - </> |
103 |
| - </GridRow> |
104 |
| - <GridRow height={2}> |
105 |
| - <GridColumn> |
106 |
| - <View style="background-color: green"> |
107 |
| - <Text>Second row</Text> |
108 |
| - </View> |
109 |
| - </GridColumn> |
110 |
| - <GridColumn> |
111 |
| - <View style="background-color: purple"> |
112 |
| - <Text>Second Column</Text> |
113 |
| - </View> |
114 |
| - </GridColumn> |
115 |
| - <GridColumn> |
116 |
| - <View style="background-color: purple"> |
117 |
| - <Text>Third Column</Text> |
118 |
| - </View> |
119 |
| - </GridColumn> |
120 |
| - <GridColumn> |
121 |
| - <View style="background-color: purple"> |
122 |
| - <Text>Fourth Column</Text> |
123 |
| - </View> |
124 |
| - </GridColumn> |
125 |
| - <> |
126 |
| - {additionalColumns.map((column) => ( |
127 |
| - <GridColumn key={column}> |
128 |
| - <Text>Second {column}</Text> |
129 |
| - </GridColumn> |
130 |
| - ))} |
131 |
| - </> |
132 |
| - </GridRow> |
133 |
| - <GridRow> |
134 |
| - <GridColumn> |
135 |
| - <Text>Third row</Text> |
136 |
| - </GridColumn> |
137 |
| - </GridRow> |
138 |
| - <> |
139 |
| - {additionalRows.map((row) => ( |
140 |
| - <GridRow key={row}> |
141 |
| - <GridColumn width={2}> |
142 |
| - <Text>{row}</Text> |
143 |
| - </GridColumn> |
144 |
| - <GridColumn> |
145 |
| - <Text>Second {row}</Text> |
146 |
| - </GridColumn> |
147 |
| - </GridRow> |
148 |
| - ))} |
149 |
| - </> |
150 |
| - </GridView> |
| 40 | + <BoxView direction={direction}> |
| 41 | + <Button text="Add" on={addHandler} /> |
| 42 | + <Button text="Remove" on={removeHandler} /> |
| 43 | + <Button text="Toggle direction" on={toggleDirection} /> |
| 44 | + {additionalButtons.map((button) => ( |
| 45 | + <Button key={button} text={button} /> |
| 46 | + ))} |
| 47 | + </BoxView> |
151 | 48 | </Window>
|
152 | 49 | );
|
153 | 50 | };
|
|
0 commit comments