forked from revery-ui/revery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanQuitExample.re
53 lines (48 loc) · 1.31 KB
/
CanQuitExample.re
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
open Revery;
open Revery.UI;
open Revery.UI.Components;
module CanQuit = {
type checkboxState = {canQuit: bool};
let component = React.component("CanQuit");
let createElement = (~children as _, ()) =>
component(hooks => {
let initialCheckboxState = {canQuit: true};
let ({canQuit}, setCheckboxState, hooks) =
Hooks.state(initialCheckboxState, hooks);
(
hooks,
<View
style=Style.[
width(500),
height(500),
justifyContent(`Center),
alignItems(`Center),
]>
<Checkbox
checkedColor=Colors.green
onChange={() => {
let win = getActiveWindow();
switch (win) {
| Some(win) => Window.setCanQuitCallback(win, () => !canQuit)
| None => ()
};
setCheckboxState({canQuit: !canQuit});
}}
style=Style.[border(~width=2, ~color=Colors.green)]
checked=canQuit
/>
<Text
text={"Can quit: " ++ (canQuit ? "Yes" : "No")}
style=Style.[
marginTop(10),
fontFamily("Roboto-Regular.ttf"),
fontSize(20),
]
/>
</View>,
);
});
};
let render = () => {
<CanQuit />;
};