flicker-alerts 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -2
- package/index.js +18 -7
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
const FlickerAlerts = {
|
2
2
|
showAlert: function ({ type, title, message, timer = 3000 }) {
|
3
|
+
// Verifique se está no ambiente do navegador (client-side)
|
4
|
+
if (typeof document === 'undefined') {
|
5
|
+
return; // Evita erros no servidor ou no ambiente sem DOM
|
6
|
+
}
|
7
|
+
|
3
8
|
// Criação do alerta
|
4
9
|
const alertBox = document.createElement('div');
|
5
10
|
alertBox.className = `alert-custom alert-${type}`;
|
6
|
-
|
11
|
+
|
7
12
|
// Ícone
|
8
13
|
const icon = document.createElement('div');
|
9
14
|
icon.className = 'icon';
|
@@ -15,33 +20,37 @@ const FlickerAlerts = {
|
|
15
20
|
}[type];
|
16
21
|
icon.innerHTML = `<i class="fas ${iconClass}"></i>`;
|
17
22
|
alertBox.appendChild(icon);
|
18
|
-
|
23
|
+
|
19
24
|
// Conteúdo
|
20
25
|
const content = document.createElement('div');
|
21
26
|
content.innerHTML = `<strong>${title}</strong><div>${message}</div>`;
|
22
27
|
alertBox.appendChild(content);
|
23
|
-
|
28
|
+
|
24
29
|
// Botão de fechamento
|
25
30
|
const closeButton = document.createElement('div');
|
26
31
|
closeButton.className = 'close';
|
27
32
|
closeButton.innerHTML = '<i class="fas fa-times"></i>';
|
28
33
|
closeButton.onclick = () => alertBox.remove();
|
29
34
|
alertBox.appendChild(closeButton);
|
30
|
-
|
35
|
+
|
31
36
|
// Barra de progresso
|
32
37
|
const progressBar = document.createElement('div');
|
33
38
|
progressBar.className = `progress-bar progress-bar-${type}`;
|
34
39
|
alertBox.appendChild(progressBar);
|
35
|
-
|
40
|
+
|
36
41
|
// Adicionar ao container
|
37
42
|
const container = document.getElementById('alerts-container');
|
38
|
-
container
|
39
|
-
|
43
|
+
if (container) {
|
44
|
+
container.appendChild(alertBox);
|
45
|
+
}
|
46
|
+
|
40
47
|
// Remoção automática
|
41
48
|
setTimeout(() => alertBox.remove(), timer);
|
42
49
|
}
|
43
50
|
};
|
51
|
+
|
44
52
|
|
53
|
+
|
45
54
|
// Botões de teste
|
46
55
|
document.getElementById('success-btn').addEventListener('click', () => {
|
47
56
|
FlickerAlerts.showAlert({ type: 'success', title: 'Sucesso', message: 'A operação foi concluída com êxito!' });
|
@@ -58,3 +67,5 @@ document.getElementById('warning-btn').addEventListener('click', () => {
|
|
58
67
|
document.getElementById('error-btn').addEventListener('click', () => {
|
59
68
|
FlickerAlerts.showAlert({ type: 'danger', title: 'Erro', message: 'Ocorreu um erro inesperado!' });
|
60
69
|
});
|
70
|
+
// Exportação
|
71
|
+
export default FlickerAlerts;
|