rojeru-toast 1.0.0

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Rogelio Urieta Camacho (RojeruSan)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ # rojeru-toast
2
+
3
+ [![npm version](https://img.shields.io/npm/v/rojeru-toast.svg)](https://www.npmjs.com/package/rojeru-toast)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Bundle Size](https://img.shields.io/bundlephobia/min/rojeru-toast)](https://bundlephobia.com/package/rojeru-toast)
6
+
7
+ Una librería moderna de mensajes toast para aplicaciones web, compatible con todos los frameworks y HTML puro.
8
+
9
+ ## Características
10
+
11
+ - 🎨 **Diseño moderno** con 3 temas (light, dark, colored)
12
+ - 📱 **Totalmente responsive**
13
+ - 🎭 **6 tipos de mensajes**: info, success, warning, error, loading
14
+ - ⚡ **Animaciones suaves** (slide, fade, scale)
15
+ - 🔧 **Altamente personalizable**
16
+ - 🌐 **Compatible con todos los frameworks**: React, Vue, Angular, Svelte, etc.
17
+ - 📦 **Sin dependencias**
18
+ - 🏗️ **API intuitiva y fluida**
19
+
20
+ ## Instalación
21
+
22
+ ### NPM
23
+ ```bash
24
+ npm install rojeru-toast
25
+ ```
26
+
27
+ ### Yarn
28
+ ```bash
29
+ yarn add rojeru-toast
30
+ ```
31
+
32
+ ### CDN
33
+ ```html
34
+ <!-- CSS -->
35
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/rojeru-toast@latest/dist/rojeru-toast.min.css">
36
+
37
+ <!-- JavaScript -->
38
+ <script src="https://cdn.jsdelivr.net/npm/rojeru-toast@latest/dist/rojeru-toast.min.js"></script>
39
+ ```
40
+
41
+ ## Uso Rápido
42
+
43
+ ### HTML Puro
44
+ ```html
45
+ <!DOCTYPE html>
46
+ <html>
47
+ <head>
48
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/rojeru-toast@latest/dist/rojeru-toast.min.css">
49
+ </head>
50
+ <body>
51
+ <script src="https://cdn.jsdelivr.net/npm/rojeru-toast@latest/dist/rojeru-toast.min.js"></script>
52
+ <script>
53
+ // Usar globalmente
54
+ rojeruToast.success('¡Operación exitosa!');
55
+
56
+ // O crear instancia
57
+ const toast = new RojeruToast();
58
+ toast.info('Mensaje informativo');
59
+ </script>
60
+ </body>
61
+ </html>
62
+ ```
63
+
64
+ ### Módulos ES6
65
+ ```javascript
66
+ import RojeruToast from 'rojeru-toast';
67
+
68
+ // Crear instancia
69
+ const toast = new RojeruToast();
70
+
71
+ // Métodos principales
72
+ toast.info('Mensaje informativo');
73
+ toast.success('¡Éxito!');
74
+ toast.warning('Advertencia');
75
+ toast.error('Error encontrado');
76
+
77
+ // Toast con título
78
+ toast.withTitle('Título', 'Mensaje de contenido');
79
+
80
+ // Toast de carga
81
+ const loadingToast = toast.loading('Procesando...');
82
+ // Luego completarlo
83
+ setTimeout(() => {
84
+ loadingToast.complete('¡Completado!');
85
+ }, 2000);
86
+ ```
87
+
88
+ ### React
89
+ ```jsx
90
+ import React from 'react';
91
+ import RojeruToast from 'rojeru-toast';
92
+
93
+ function App() {
94
+ const toast = React.useMemo(() => new RojeruToast(), []);
95
+
96
+ const showToast = () => {
97
+ toast.success('¡Mensaje desde React!');
98
+ };
99
+
100
+ return (
101
+ <button onClick={showToast}>
102
+ Mostrar Toast
103
+ </button>
104
+ );
105
+ }
106
+ ```
107
+
108
+ ### Vue
109
+ ```vue
110
+ <template>
111
+ <button @click="showToast">Mostrar Toast</button>
112
+ </template>
113
+
114
+ <script>
115
+ import RojeruToast from 'rojeru-toast';
116
+
117
+ export default {
118
+ data() {
119
+ return {
120
+ toast: null
121
+ };
122
+ },
123
+ mounted() {
124
+ this.toast = new RojeruToast();
125
+ },
126
+ methods: {
127
+ showToast() {
128
+ this.toast.success('¡Mensaje desde Vue!');
129
+ }
130
+ }
131
+ };
132
+ </script>
133
+ ```
134
+
135
+ ## API
136
+
137
+ ### Métodos Principales
138
+
139
+ #### `show(title, message, options)`
140
+ Muestra un toast con título y mensaje.
141
+
142
+ ```javascript
143
+ // Sin título
144
+ toast.show('Mensaje simple');
145
+
146
+ // Con título
147
+ toast.show('Título', 'Mensaje del contenido');
148
+
149
+ // Con opciones
150
+ toast.show('Título', 'Mensaje', {
151
+ type: 'success',
152
+ duration: 5000,
153
+ position: 'top-center',
154
+ theme: 'dark'
155
+ });
156
+ ```
157
+
158
+ #### Métodos de conveniencia
159
+ ```javascript
160
+ toast.info(message, options);
161
+ toast.success(message, options);
162
+ toast.warning(message, options);
163
+ toast.error(message, options);
164
+ toast.loading(message, options);
165
+ toast.withTitle(title, message, options);
166
+ ```
167
+
168
+ ### Opciones
169
+
170
+ | Opción | Tipo | Default | Descripción |
171
+ |--------|------|---------|-------------|
172
+ | `type` | `string` | `'info'` | Tipo de toast: `'info'`, `'success'`, `'warning'`, `'error'`, `'loading'` |
173
+ | `duration` | `number` | `3000` | Duración en milisegundos (0 = permanente) |
174
+ | `position` | `string` | `'top-right'` | Posición: `'top-right'`, `'top-left'`, `'top-center'`, `'bottom-right'`, `'bottom-left'`, `'bottom-center'` |
175
+ | `theme` | `string` | `'light'` | Tema: `'light'`, `'dark'`, `'colored'` |
176
+ | `dismissible` | `boolean` | `true` | Si muestra botón de cerrar |
177
+ | `pauseOnHover` | `boolean` | `true` | Pausa la desaparición al hacer hover |
178
+ | `animation` | `string` | `'slide'` | Animación: `'slide'`, `'fade'`, `'scale'` |
179
+ | `closeOnClick` | `boolean` | `false` | Cierra al hacer click en el toast |
180
+
181
+ ### Métodos de Instancia
182
+
183
+ Cada toast retornado tiene estos métodos:
184
+
185
+ ```javascript
186
+ const toastInstance = toast.info('Mensaje');
187
+
188
+ // Obtener ID
189
+ const id = toastInstance.getId();
190
+
191
+ // Actualizar contenido
192
+ toastInstance.update('Nuevo mensaje');
193
+ toastInstance.update('Nuevo título', 'Nuevo mensaje');
194
+
195
+ // Cambiar tipo
196
+ toastInstance.changeType('success', '¡Completado!');
197
+
198
+ // Completar toast de carga
199
+ toastInstance.complete('¡Proceso completado!');
200
+
201
+ // Ocultar manualmente
202
+ toastInstance.hide();
203
+ ```
204
+
205
+ ### Métodos Globales
206
+
207
+ ```javascript
208
+ // Ocultar toast por ID
209
+ toast.hideById('toast-id');
210
+
211
+ // Ocultar el último toast
212
+ toast.hideLast();
213
+
214
+ // Ocultar todos los toasts de un tipo
215
+ toast.hideByType('success');
216
+
217
+ // Limpiar todos los toasts
218
+ toast.clear();
219
+ ```
220
+
221
+ ## Personalización
222
+
223
+ ### Configuración Global
224
+ ```javascript
225
+ const toast = new RojeruToast();
226
+
227
+ // Cambiar opciones por defecto
228
+ toast.defaultOptions = {
229
+ duration: 5000,
230
+ position: 'top-center',
231
+ theme: 'colored',
232
+ animation: 'fade'
233
+ };
234
+ ```
235
+
236
+ ### CSS Custom Properties
237
+ ```css
238
+ :root {
239
+ --rojeru-toast-font-family: 'Arial, sans-serif';
240
+ --rojeru-toast-border-radius: 8px;
241
+ --rojeru-toast-spacing: 10px;
242
+ }
243
+ ```
244
+
245
+ ## Ejemplos Avanzados
246
+
247
+ ### Toast Persistente
248
+ ```javascript
249
+ const persistentToast = toast.info('Actualizando datos...', {
250
+ duration: 0,
251
+ dismissible: false
252
+ });
253
+
254
+ // Actualizar cuando termine la operación
255
+ setTimeout(() => {
256
+ persistentToast.changeType('success', '¡Datos actualizados!', {
257
+ duration: 3000,
258
+ dismissible: true
259
+ });
260
+ }, 2000);
261
+ ```
262
+
263
+ ### Toast con Acciones
264
+ ```javascript
265
+ const actionToast = toast.info('¿Deseas guardar los cambios?', {
266
+ duration: 0,
267
+ closeOnClick: false
268
+ });
269
+
270
+ // Agregar botones personalizados
271
+ setTimeout(() => {
272
+ const btnContainer = document.createElement('div');
273
+ btnContainer.style.marginTop = '10px';
274
+ btnContainer.innerHTML = `
275
+ <button onclick="guardar()">Guardar</button>
276
+ <button onclick="cancelar()">Cancelar</button>
277
+ `;
278
+
279
+ actionToast.element.querySelector('.rojeru-toast-content')
280
+ .appendChild(btnContainer);
281
+ }, 100);
282
+ ```
283
+
284
+ ## Soporte para Frameworks
285
+
286
+ ### React Hook
287
+ ```jsx
288
+ // useToast.js
289
+ import { useRef } from 'react';
290
+ import RojeruToast from 'rojeru-toast';
291
+
292
+ export function useToast() {
293
+ const toastRef = useRef(null);
294
+
295
+ if (!toastRef.current) {
296
+ toastRef.current = new RojeruToast();
297
+ }
298
+
299
+ return toastRef.current;
300
+ }
301
+
302
+ // Uso
303
+ function Component() {
304
+ const toast = useToast();
305
+
306
+ const handleClick = () => {
307
+ toast.success('¡Hecho!');
308
+ };
309
+
310
+ return <button onClick={handleClick}>Click</button>;
311
+ }
312
+ ```
313
+
314
+ ## Licencia
315
+
316
+ MIT © Rogelio Urieta Camacho (RojeruSan)
317
+ ## ❤️ Donaciones
318
+ [![Donar](https://img.shields.io/badge/Donar-PayPal-00457C?logo=paypal&style=for-the-badge)](https://www.paypal.com/donate/?cmd=_s-xclick&hosted_button_id=JLWEAETTE3H28&ssrt=1764941769118)