fernotify 1.2.1 → 1.2.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.
@@ -146,7 +146,7 @@ async function loadData() {
146
146
  }
147
147
  ```
148
148
 
149
- ### Confirmación de Eliminación
149
+ ### Confirmación de Eliminación (dos botones)
150
150
 
151
151
  ```javascript
152
152
  function deleteItem(id) {
@@ -154,12 +154,52 @@ function deleteItem(id) {
154
154
  type: 'warning',
155
155
  title: '¿Estás seguro?',
156
156
  message: 'Esta acción no se puede deshacer. El registro será eliminado permanentemente.',
157
- buttonText: 'Sí, eliminar',
158
- onClose: async () => {
159
- // Usuario confirmó, proceder con eliminación
157
+ buttons: [
158
+ {
159
+ text: 'Cancelar',
160
+ color: 'linear-gradient(135deg, #9ca3af 0%, #6b7280 100%)',
161
+ onClick: () => {
162
+ // El usuario decidió no continuar; simplemente cerramos
163
+ console.log('Eliminación cancelada');
164
+ }
165
+ },
166
+ {
167
+ text: 'Sí, eliminar',
168
+ color: 'linear-gradient(135deg, #ef4444 0%, #dc2626 100%)',
169
+ onClick: async () => {
170
+ await performDelete(id);
171
+ notify.success('Registro eliminado correctamente');
172
+ }
173
+ }
174
+ ],
175
+ allowOutsideClick: false,
176
+ allowEscapeKey: false
177
+ });
178
+ }
179
+ ```
180
+
181
+ ### Confirmación simplificada con `onConfirm` / `onCancel`
182
+
183
+ Si prefieres no definir un array de botones, puedes usar los atajos `onConfirm` y `onCancel`.
184
+ `onConfirm` puede devolver una promesa (se espera antes de cerrar la notificación).
185
+
186
+ ```javascript
187
+ function deleteItem(id) {
188
+ notify.show({
189
+ type: 'warning',
190
+ title: '¿Eliminar registro?',
191
+ message: 'Esta acción no se puede deshacer.',
192
+ confirmText: 'Sí, eliminar',
193
+ cancelText: 'Cancelar',
194
+ onConfirm: async () => {
160
195
  await performDelete(id);
161
196
  notify.success('Registro eliminado correctamente');
162
- }
197
+ },
198
+ onCancel: () => {
199
+ console.log('Eliminación cancelada por el usuario');
200
+ },
201
+ allowOutsideClick: false,
202
+ allowEscapeKey: false
163
203
  });
164
204
  }
165
205
  ```
@@ -653,8 +693,17 @@ Cada tipo tiene su propio estilo:
653
693
  type: 'success' | 'error' | 'warning' | 'info', // Requerido
654
694
  title: 'Título', // Opcional
655
695
  message: 'Mensaje detallado', // Requerido
656
- buttonText: 'OK', // Opcional (default: 'OK')
657
- timer: 5000, // Opcional (ms, null = sin timer)
696
+ buttonText: 'OK', // Opcional (default: 'OK') // Array de botones. Cada elemento puede contener:
697
+ // { text, color?, shadowColor?, onClick? }
698
+ // Si se proporciona, `buttonText` se ignora y se renderiza
699
+ // una botonera con el contenido del array.
700
+ buttons: [], timer: 5000, // Opcional (ms, null = sin timer)
701
+ // Atajos para confirmaciones: si prefieres no definir un array de botones,
702
+ // puedes usar `onConfirm` y `onCancel` junto con `confirmText` / `cancelText`:
703
+ // onConfirm: () => { /* acción confirmada */ },
704
+ // onCancel: () => { /* acción cancelada */ },
705
+ // confirmText: 'Sí, eliminar',
706
+ // cancelText: 'Cancelar',
658
707
  onClose: () => { } // Opcional (callback)
659
708
  }
660
709
  ```
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## Características
10
10
 
11
- - **4 tipos de notificaciones**: Success, Error, Warning, Info
11
+ - **5 tipos de notificaciones**: Success, Error, Warning, Info, Question
12
12
  - **Dark Mode automático**: Detecta el tema de tu web
13
13
  - **Animaciones fluidas**: Powered by anime.js
14
14
  - **Ligero y rápido**: ~10KB sin dependencias (excepto anime.js)
@@ -74,11 +74,11 @@ window.notify = new NotificationSystem();
74
74
 
75
75
  ```html
76
76
  <!-- UMD -->
77
- <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@1.0.0/dist/notification-system.js"></script>
77
+ <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@1.2.1/dist/notification-system.js"></script>
78
78
 
79
79
  <!-- ES Module -->
80
80
  <script type="module">
81
- import NotificationSystem from 'https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@1.0.0/dist/notification-system.esm.js';
81
+ import NotificationSystem from 'https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@1.2.1/dist/notification-system.esm.js';
82
82
  </script>
83
83
  ```
84
84
 
@@ -98,6 +98,9 @@ notify.warning('Esta acción no se puede deshacer');
98
98
 
99
99
  // Info
100
100
  notify.info('Hay una nueva actualización disponible');
101
+
102
+ // Question (nuevo)
103
+ notify.question('¿Seguro que quieres continuar?', 'Confirmación');
101
104
  ```
102
105
 
103
106
  ### Con Título Personalizado
@@ -167,6 +170,11 @@ notify.show({
167
170
  title: 'Título', // Opcional
168
171
  message: 'Mensaje', // Requerido
169
172
  buttonText: 'OK', // Opcional (default: 'OK')
173
+ // Para confirmaciones rápidas hay atajos:
174
+ // `onConfirm` (función) se ejecuta al pulsar el botón de confirmar.
175
+ // `onCancel` (función) se ejecuta al pulsar el botón de cancelar.
176
+ // Puedes personalizar textos con `confirmText` / `cancelText` y colores con
177
+ // `confirmColor` / `cancelColor`.
170
178
  timer: 3000, // Opcional (ms, null = sin timer)
171
179
  allowOutsideClick: true, // Opcional (default: true)
172
180
  allowEscapeKey: true, // Opcional (default: true)
@@ -183,6 +191,7 @@ notify.success(message, title?, options?)
183
191
  notify.error(message, title?, options?)
184
192
  notify.warning(message, title?, options?)
185
193
  notify.info(message, title?, options?)
194
+ notify.question(message, title?, options?)
186
195
  notify.close() // Cerrar la notificación actual
187
196
  ```
188
197
 
@@ -269,25 +278,76 @@ async function fetchData() {
269
278
  fetchData();
270
279
  ```
271
280
 
272
- ### Confirmación de Operación
281
+ ### Confirmación de Operación (dos botones)
273
282
 
274
283
  ```javascript
275
284
  notify.show({
276
285
  type: 'warning',
277
286
  title: '¿Estás seguro?',
278
287
  message: 'Esta acción no se puede deshacer',
279
- buttonText: 'Sí, continuar',
288
+ buttons: [
289
+ {
290
+ text: 'Cancelar',
291
+ color: 'linear-gradient(135deg, #9ca3af 0%, #6b7280 100%)',
292
+ onClick: () => {
293
+ console.log('Operación cancelada');
294
+ }
295
+ },
296
+ {
297
+ text: 'Sí, continuar',
298
+ color: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)',
299
+ onClick: () => {
300
+ deleteUser();
301
+ }
302
+ }
303
+ ],
280
304
  allowOutsideClick: false,
281
- allowEscapeKey: false,
282
- onClose: () => {
283
- // Ejecutar acción después de confirmar
284
- deleteUser();
285
- }
305
+ allowEscapeKey: false
286
306
  });
287
307
  ```
288
308
 
289
309
  ### Notificación con Contenido HTML
290
310
 
311
+ ### Confirmación (atajo `onConfirm` / `onCancel`)
312
+
313
+ ```javascript
314
+ notify.show({
315
+ type: 'warning',
316
+ title: '¿Eliminar registro?',
317
+ message: 'Esta acción no se puede deshacer.',
318
+ confirmText: 'Sí, eliminar',
319
+ cancelText: 'Cancelar',
320
+ onConfirm: async () => {
321
+ await performDelete(id);
322
+ notify.success('Registro eliminado correctamente');
323
+ },
324
+ onCancel: () => {
325
+ console.log('El usuario canceló la operación');
326
+ },
327
+ allowOutsideClick: false,
328
+ allowEscapeKey: false
329
+ });
330
+ ```
331
+
332
+ ### Personalizar colores y sombras (ejemplo)
333
+
334
+ ```javascript
335
+ notify.show({
336
+ type: 'warning',
337
+ title: 'Eliminar elemento',
338
+ message: '¿Estás seguro?',
339
+ confirmText: 'Sí, borrar',
340
+ cancelText: 'No, cancelar',
341
+ onConfirm: () => fetch('/api/delete', { method: 'POST' }),
342
+ onCancel: () => console.log('Cancelado'),
343
+ // Colores y sombras pueden ser cualquier string CSS (gradiente o color simple)
344
+ confirmColor: 'linear-gradient(135deg, #10b981 0%, #059669 100%)',
345
+ confirmShadow: 'rgba(5,150,105,0.22)',
346
+ cancelColor: 'linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%)',
347
+ cancelShadow: 'rgba(0,0,0,0.08)'
348
+ });
349
+ ```
350
+
291
351
  ```javascript
292
352
  const form = document.createElement('form');
293
353
  form.innerHTML = `
@@ -347,10 +407,10 @@ Para usar una versión específica, usa tags en la URL del CDN:
347
407
 
348
408
  ```html
349
409
  <!-- Última versión (auto-actualiza) -->
350
- <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/notification-system@latest/dist/notification-system.js"></script>
410
+ <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@latest/dist/notification-system.js"></script>
351
411
 
352
412
  <!-- Versión fija (recomendado en producción) -->
353
- <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/notification-system@1.0.0/dist/notification-system.js"></script>
413
+ <script src="https://cdn.jsdelivr.net/gh/Fernandocabal/fernotify@1.2.1/dist/notification-system.js"></script>
354
414
  ```
355
415
 
356
416
  ### Crear una nueva versión