flicker-alerts 1.0.6 → 1.0.7

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