-
-
Notifications
You must be signed in to change notification settings - Fork 196
/
FontsExample.re
87 lines (78 loc) · 2.15 KB
/
FontsExample.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
open Revery;
open Revery.UI;
open Revery.UI.Components;
module FontComponent = {
type state = {
family: string,
bold: bool,
italic: bool,
};
let initialState: state = {family: "Arial", bold: false, italic: false};
type actions =
| SetBold(bool)
| SetItalic(bool)
| SetFamily(string);
let reducer = (action: actions, state: state) => {
let state =
switch (action) {
| SetBold(v) => {...state, bold: v}
| SetItalic(v) => {...state, italic: v}
| SetFamily(v) => {...state, family: v}
};
state;
};
let%component make = () => {
let%hook (state, dispatch) = Hooks.reducer(~initialState, reducer);
let fontExample =
<Text
text="Lorem ipsum dolor sit amet"
fontFamily={Font.Family.system(state.family)}
fontWeight={state.bold ? Font.Weight.Bold : Font.Weight.Normal}
italic={state.italic}
fontSize=24.
/>;
<Container width=500 height=500>
<Center>
<Padding padding=10>
<Row>
<Input
placeholder="Type font name"
onChange={(value, _) => dispatch(SetFamily(value))}
value={state.family}
/>
</Row>
</Padding>
<Padding padding=10>
<Row>
<Padding padding=16>
<Checkbox
checked={state.bold}
onChange={() => dispatch(SetBold(!state.bold))}
/>
</Padding>
<Center>
<Text text="Bold" fontSize=20. style=Style.[width(150)] />
</Center>
</Row>
</Padding>
<Padding padding=10>
<Row>
<Padding padding=16>
<Checkbox
checked={state.italic}
onChange={() => dispatch(SetItalic(!state.italic))}
/>
</Padding>
<Center>
<Text text="Italic" fontSize=20. style=Style.[width(150)] />
</Center>
</Row>
</Padding>
<Padding padding=16> <Row> fontExample </Row> </Padding>
</Center>
</Container>;
};
};
let render = () => {
<FontComponent />;
};