-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (70 loc) · 1.84 KB
/
index.js
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
const _$ = query => document.querySelector(query);
const Modal = {
modalOverlay: _$('.modal-overlay'),
toogle(event){
event.preventDefault();
this.modalOverlay.classList.toggle('active');
}
}
const Transaction = {
incomes () {
},
expenses () {
},
total () {
}
}
const transactions = [
{
id: 1,
amount: 500_00,
date: '27/02/2021',
description: 'LaLALAn'
},
{
id: 2,
amount: -4500_59,
date: '27/02/2021',
description: 'Sei lá!'
},
{
id: 2,
amount: 750_00,
date: '27/02/2021',
description: 'LaLALAn'
},
];
const AppDOM = {
transactionsContainer: _$('#data-table tbody'),
addTransaction(transaction, index){
const tr = document.createElement('tr');
tr.innerHTML = AppDOM.transactionInnerHTML(transaction);
AppDOM.transactionsContainer.appendChild(tr);
},
transactionInnerHTML(transaction){
const positive = transaction.amount > 0;
const cssClass = positive ? 'income' : 'expanse';
const amount = Utils.formatCurrency(transaction.amount);
return `
<td class="description">${transaction.description}</td>
<td class="${cssClass}">${amount}</td>
<td class="date">${transaction.date}</td>
<td>
<img src="./assets/minus.svg" alt="Remover transação">
</td>
`;
}
}
const Utils = {
formatCurrency(value){
const signal = Number(value) < 0 ? '-' : '';
value = String(value).replace(/\D/g, '');
value = Number(value) / 100;
value = value.toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL'
});
return signal + value;
}
}
transactions.forEach(transaction => AppDOM.addTransaction(transaction));