Counter App
The code below is available in the minimal sample on our GitHub, that is based on our boilerplate.
1
import lampix from '@lampix/core';
2
import lampixDOM from '@lampix/dom';
3
4
import './styles.css';
5
6
let counter = 0;
7
8
const counterElement = document.getElementsByClassName('counter')[0];
9
counterElement.textContent = 'Loading...';
10
11
const increaseCount = () => {
12
counter++;
13
};
14
15
const updateCounterElement = () => {
16
counterElement.textContent = counter;
17
};
18
19
const initialize = async () => {
20
const counterButtonOptions = {
21
label: 'Increase count',
22
labelPosition: 'top',
23
scaleFactor: 1.2,
24
animationDuration: 250
25
};
26
27
const closeButtonOptions = {
28
label: 'Close App',
29
labelPosition: 'top',
30
scaleFactor: 1.2,
31
animationDuration: 500
32
};
33
34
const callback = () => {
35
increaseCount();
36
updateCounterElement();
37
};
38
39
const counterButtonPromise = lampixDOM.buttons.generate(
40
window.innerWidth / 2,
41
window.innerHeight - 120,
42
callback,
43
counterButtonOptions
44
);
45
46
const closeAppButtonPromise = lampixDOM.buttons.generate(
47
100,
48
100,
49
lampix.exit,
50
closeButtonOptions
51
);
52
53
await counterButtonPromise;
54
await closeAppButtonPromise;
55
56
updateCounterElement();
57
};
58
59
initialize();
Copied!
Copy link