flicker-alerts 1.0.6 → 1.0.8

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.
Files changed (2) hide show
  1. package/index.js +38 -32
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -1,8 +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
3
+ // Verifique se está no ambiente do navegador (client-side) antes de tentar manipular o DOM
4
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
5
+ // Garantir que o container de alertas exista, se não, criá-lo
6
+ let container = document.getElementById('alerts-container');
7
+ if (!container) {
8
+ // Cria o container se ele não existir
9
+ container = document.createElement('div');
10
+ container.id = 'alerts-container';
11
+ document.body.appendChild(container); // Adiciona o container ao body ou a outro elemento desejado
6
12
  }
7
13
 
8
14
  // Criação do alerta
@@ -13,10 +19,10 @@ const FlickerAlerts = {
13
19
  const icon = document.createElement('div');
14
20
  icon.className = 'icon';
15
21
  const iconClass = {
16
- success: 'fa-check',
17
- info: 'fa-info',
18
- warning: 'fa-exclamation',
19
- danger: 'fa-times'
22
+ success: 'fa-check',
23
+ info: 'fa-info',
24
+ warning: 'fa-exclamation',
25
+ danger: 'fa-times'
20
26
  }[type];
21
27
  icon.innerHTML = `<i class="fas ${iconClass}"></i>`;
22
28
  alertBox.appendChild(icon);
@@ -39,33 +45,33 @@ const FlickerAlerts = {
39
45
  alertBox.appendChild(progressBar);
40
46
 
41
47
  // Adicionar ao container
42
- const container = document.getElementById('alerts-container');
43
- if (container) {
44
- container.appendChild(alertBox);
45
- }
48
+ container.appendChild(alertBox);
46
49
 
47
- // Remoção automática
50
+ // Remoção automática após o tempo especificado
48
51
  setTimeout(() => alertBox.remove(), timer);
52
+ }
49
53
  }
50
- };
54
+ };
55
+
56
+ // Botões de teste - Eles podem ser removidos se não forem necessários
57
+ if (typeof document !== 'undefined') {
58
+ document.getElementById('success-btn')?.addEventListener('click', () => {
59
+ FlickerAlerts.showAlert({ type: 'success', title: 'Sucesso', message: 'A operação foi concluída com êxito!' });
60
+ });
61
+
62
+ document.getElementById('info-btn')?.addEventListener('click', () => {
63
+ FlickerAlerts.showAlert({ type: 'info', title: 'Informação', message: 'Aqui está uma informação importante.' });
64
+ });
65
+
66
+ document.getElementById('warning-btn')?.addEventListener('click', () => {
67
+ FlickerAlerts.showAlert({ type: 'warning', title: 'Alerta', message: 'Por favor, preste atenção nisso!' });
68
+ });
51
69
 
52
-
70
+ document.getElementById('error-btn')?.addEventListener('click', () => {
71
+ FlickerAlerts.showAlert({ type: 'danger', title: 'Erro', message: 'Ocorreu um erro inesperado!' });
72
+ });
73
+ }
53
74
 
54
- // Botões de teste
55
- document.getElementById('success-btn').addEventListener('click', () => {
56
- FlickerAlerts.showAlert({ type: 'success', title: 'Sucesso', message: 'A operação foi concluída com êxito!' });
57
- });
58
-
59
- document.getElementById('info-btn').addEventListener('click', () => {
60
- FlickerAlerts.showAlert({ type: 'info', title: 'Informação', message: 'Aqui está uma informação importante.' });
61
- });
62
-
63
- document.getElementById('warning-btn').addEventListener('click', () => {
64
- FlickerAlerts.showAlert({ type: 'warning', title: 'Alerta', message: 'Por favor, preste atenção nisso!' });
65
- });
66
-
67
- document.getElementById('error-btn').addEventListener('click', () => {
68
- FlickerAlerts.showAlert({ type: 'danger', title: 'Erro', message: 'Ocorreu um erro inesperado!' });
69
- });
70
- // Exportação
71
- export default FlickerAlerts;
75
+ // Exportação
76
+ export default FlickerAlerts;
77
+
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "flicker-alerts",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Biblioteca para alertas animados",
5
5
  "main": "index.js",
6
- "types": "index.d.ts",
6
+ "types": "index.d.ts",
7
+ "style": "style.css",
7
8
  "scripts": {
8
9
  "test": "echo \"Error: no test specified\" && exit 1"
9
10
  },