-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
CanQuitExample.re
44 lines (40 loc) · 1.01 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
open Revery;
open Revery.UI;
open Revery.UI.Components;
module CanQuit = {
type checkboxState = {canQuit: bool};
let%component make = () => {
let initialCheckboxState = {canQuit: true};
let%hook ({canQuit}, setCheckboxState) =
Hooks.state(initialCheckboxState);
<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: !canQuit});
}}
style=Style.[border(~width=2, ~color=Colors.green)]
checked=canQuit
/>
<Text
text={"Can quit: " ++ (canQuit ? "Yes" : "No")}
fontSize=20.
style=Style.[marginTop(10)]
/>
</View>;
};
};
let render = () => {
<CanQuit />;
};