@adamosuiteservices/ui 2.11.15 → 2.11.17
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/dist/colors.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/themes.css +1 -1
- package/docs/AI-GUIDE.md +321 -321
- package/docs/components/layout/sidebar.md +399 -399
- package/docs/components/layout/toaster.md +436 -436
- package/docs/components/ui/accordion-rounded.md +584 -584
- package/docs/components/ui/accordion.md +269 -269
- package/docs/components/ui/button-group.md +984 -984
- package/docs/components/ui/button.md +1137 -1137
- package/docs/components/ui/calendar.md +1159 -1159
- package/docs/components/ui/card.md +1455 -1455
- package/docs/components/ui/checkbox.md +292 -292
- package/docs/components/ui/collapsible.md +323 -323
- package/docs/components/ui/command.md +454 -454
- package/docs/components/ui/context-menu.md +540 -540
- package/docs/components/ui/dialog.md +628 -628
- package/docs/components/ui/dropdown-menu.md +709 -709
- package/docs/components/ui/field.md +706 -706
- package/docs/components/ui/hover-card.md +446 -446
- package/docs/components/ui/input.md +362 -362
- package/docs/components/ui/kbd.md +434 -434
- package/docs/components/ui/label.md +359 -359
- package/docs/components/ui/pagination.md +650 -650
- package/docs/components/ui/popover.md +536 -536
- package/docs/components/ui/progress.md +182 -182
- package/docs/components/ui/radio-group.md +311 -311
- package/docs/components/ui/select.md +352 -352
- package/docs/components/ui/separator.md +214 -214
- package/docs/components/ui/sheet.md +142 -142
- package/docs/components/ui/skeleton.md +140 -140
- package/docs/components/ui/slider.md +341 -341
- package/docs/components/ui/spinner.md +170 -170
- package/docs/components/ui/switch.md +408 -408
- package/docs/components/ui/tabs-underline.md +106 -106
- package/docs/components/ui/tabs.md +122 -122
- package/docs/components/ui/textarea.md +243 -243
- package/docs/components/ui/toggle.md +237 -237
- package/docs/components/ui/tooltip.md +317 -317
- package/docs/components/ui/typography.md +280 -280
- package/package.json +1 -1
|
@@ -1,436 +1,436 @@
|
|
|
1
|
-
# Toaster Component
|
|
2
|
-
|
|
3
|
-
## Descripción
|
|
4
|
-
|
|
5
|
-
Sistema de **notificaciones toast** no intrusivas que aparecen en la parte inferior de la pantalla. Incluye sistema de cola automático para múltiples toasts, 4 variantes de color, auto-cierre configurable, y animaciones suaves de entrada/salida.
|
|
6
|
-
|
|
7
|
-
## Características
|
|
8
|
-
|
|
9
|
-
- ✅ 4 variantes visuales (default, success, warning, destructive)
|
|
10
|
-
- ✅ Sistema de cola automático para múltiples toasts
|
|
11
|
-
- ✅ Auto-cierre configurable (por defecto 3000ms)
|
|
12
|
-
- ✅ Toasts persistentes (sin auto-cierre)
|
|
13
|
-
- ✅ Animaciones suaves de entrada y salida
|
|
14
|
-
- ✅ Portal rendering para posicionamiento fijo
|
|
15
|
-
- ✅ IDs únicos automáticos
|
|
16
|
-
- ✅ Cierre manual programático
|
|
17
|
-
|
|
18
|
-
## Importación
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { Toaster, ToastManager } from "@adamosuiteservices/ui/toaster";
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Setup Inicial
|
|
25
|
-
|
|
26
|
-
Agrega el componente `Toaster` en el nivel más alto de tu aplicación:
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
import { Toaster } from "@adamosuiteservices/ui/toaster";
|
|
30
|
-
|
|
31
|
-
function App() {
|
|
32
|
-
return (
|
|
33
|
-
<>
|
|
34
|
-
{/* Tu app aquí */}
|
|
35
|
-
<Toaster />
|
|
36
|
-
</>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
**Importante**: Solo necesitas una instancia de `Toaster` en toda tu aplicación.
|
|
42
|
-
|
|
43
|
-
## Uso Básico
|
|
44
|
-
|
|
45
|
-
```tsx
|
|
46
|
-
import { ToastManager } from "@adamosuiteservices/ui/toaster";
|
|
47
|
-
import { Button } from "@adamosuiteservices/ui/button";
|
|
48
|
-
|
|
49
|
-
function MyComponent() {
|
|
50
|
-
return (
|
|
51
|
-
<Button
|
|
52
|
-
onClick={() => {
|
|
53
|
-
ToastManager.show({
|
|
54
|
-
message: "Changes have been saved successfully!",
|
|
55
|
-
variant: "success",
|
|
56
|
-
});
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
Save Changes
|
|
60
|
-
</Button>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Variantes
|
|
66
|
-
|
|
67
|
-
### default
|
|
68
|
-
|
|
69
|
-
Toast informativo general con fondo azul claro.
|
|
70
|
-
|
|
71
|
-
```tsx
|
|
72
|
-
ToastManager.show({
|
|
73
|
-
message: "This is a general informational message",
|
|
74
|
-
variant: "default",
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**Estilos**:
|
|
79
|
-
|
|
80
|
-
- Fondo: `bg-primary-200`
|
|
81
|
-
- Texto: `text-foreground`
|
|
82
|
-
- Uso: Información general, confirmaciones neutrales
|
|
83
|
-
|
|
84
|
-
### success
|
|
85
|
-
|
|
86
|
-
Toast verde para acciones exitosas o confirmaciones positivas.
|
|
87
|
-
|
|
88
|
-
```tsx
|
|
89
|
-
ToastManager.show({
|
|
90
|
-
message: "Operation completed successfully!",
|
|
91
|
-
variant: "success",
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Estilos**:
|
|
96
|
-
|
|
97
|
-
- Fondo: `bg-success-50` (verde claro)
|
|
98
|
-
- Texto: `text-success`
|
|
99
|
-
- Uso: Guardado exitoso, operaciones completadas, confirmaciones
|
|
100
|
-
|
|
101
|
-
### warning
|
|
102
|
-
|
|
103
|
-
Toast amarillo para advertencias importantes.
|
|
104
|
-
|
|
105
|
-
```tsx
|
|
106
|
-
ToastManager.show({
|
|
107
|
-
message: "Your session will expire in 5 minutes",
|
|
108
|
-
variant: "warning",
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**Estilos**:
|
|
113
|
-
|
|
114
|
-
- Fondo: `bg-warning-50` (amarillo claro)
|
|
115
|
-
- Texto: `text-warning`
|
|
116
|
-
- Uso: Advertencias, validaciones, alertas preventivas
|
|
117
|
-
|
|
118
|
-
### destructive
|
|
119
|
-
|
|
120
|
-
Toast rojo para errores críticos o acciones destructivas.
|
|
121
|
-
|
|
122
|
-
```tsx
|
|
123
|
-
ToastManager.show({
|
|
124
|
-
message: "Error: Unable to complete the operation",
|
|
125
|
-
variant: "destructive",
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
**Estilos**:
|
|
130
|
-
|
|
131
|
-
- Fondo: `bg-destructive-50` (rojo claro)
|
|
132
|
-
- Texto: `text-destructive`
|
|
133
|
-
- Uso: Errores, fallos de operación, acciones destructivas
|
|
134
|
-
|
|
135
|
-
## Duración y Control
|
|
136
|
-
|
|
137
|
-
### Auto-cierre Personalizado
|
|
138
|
-
|
|
139
|
-
Por defecto, los toasts se cierran automáticamente después de 3 segundos (3000ms).
|
|
140
|
-
|
|
141
|
-
```tsx
|
|
142
|
-
// Toast rápido (1 segundo)
|
|
143
|
-
ToastManager.show({
|
|
144
|
-
message: "Quick notification",
|
|
145
|
-
variant: "default",
|
|
146
|
-
autoClose: 1000,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Toast normal (3 segundos - default)
|
|
150
|
-
ToastManager.show({
|
|
151
|
-
message: "Normal duration",
|
|
152
|
-
variant: "success",
|
|
153
|
-
autoClose: 3000,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// Toast largo (5 segundos)
|
|
157
|
-
ToastManager.show({
|
|
158
|
-
message: "Important message - read carefully",
|
|
159
|
-
variant: "warning",
|
|
160
|
-
autoClose: 5000,
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Toast Persistente
|
|
165
|
-
|
|
166
|
-
Para mensajes que requieren confirmación del usuario:
|
|
167
|
-
|
|
168
|
-
```tsx
|
|
169
|
-
// Mostrar toast sin auto-cierre
|
|
170
|
-
ToastManager.show({
|
|
171
|
-
message: "This message requires your attention",
|
|
172
|
-
variant: "destructive",
|
|
173
|
-
autoClose: undefined, // No se cierra automáticamente
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Los toasts persistentes se pueden cerrar manualmente por el usuario
|
|
177
|
-
// haciendo click en el toast o con acciones específicas de tu app
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## API
|
|
181
|
-
|
|
182
|
-
### ToastManager.show()
|
|
183
|
-
|
|
184
|
-
Método principal para mostrar toasts desde cualquier parte de tu aplicación.
|
|
185
|
-
|
|
186
|
-
```tsx
|
|
187
|
-
ToastManager.show({
|
|
188
|
-
message: "Your message here",
|
|
189
|
-
variant: "success",
|
|
190
|
-
autoClose: 3000,
|
|
191
|
-
});
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Toast Type
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
type Toast = {
|
|
198
|
-
id?: string;
|
|
199
|
-
message: string;
|
|
200
|
-
variant?: "default" | "success" | "warning" | "destructive";
|
|
201
|
-
autoClose?: number;
|
|
202
|
-
onClose?: () => void;
|
|
203
|
-
};
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
## Props
|
|
207
|
-
|
|
208
|
-
### Toast Options
|
|
209
|
-
|
|
210
|
-
| Prop | Tipo | Default | Descripción |
|
|
211
|
-
| --------- | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------ |
|
|
212
|
-
| id | `string` | Auto-generado | Identificador único del toast (opcional) |
|
|
213
|
-
| message | `string` | - | **Requerido**. Texto a mostrar |
|
|
214
|
-
| variant | `"default" \| "success" \| "warning" \| "destructive"` | `"default"` | Variante de color |
|
|
215
|
-
| autoClose | `number \| undefined` | `3000` | Duración en ms antes de cerrarse automáticamente. `undefined` para persistente |
|
|
216
|
-
| onClose | `() => void` | `undefined` | Callback ejecutado cuando el toast se cierra |
|
|
217
|
-
|
|
218
|
-
### Toaster Component
|
|
219
|
-
|
|
220
|
-
El componente `Toaster` no requiere props - simplemente inclúyelo en tu app.
|
|
221
|
-
|
|
222
|
-
| Prop | Tipo | Descripción |
|
|
223
|
-
| ---- | ---- | ----------- |
|
|
224
|
-
| - | - | Sin props |
|
|
225
|
-
|
|
226
|
-
## Ejemplos de Uso
|
|
227
|
-
|
|
228
|
-
### Formulario Enviado con Éxito
|
|
229
|
-
|
|
230
|
-
```tsx
|
|
231
|
-
const handleSubmit = async (data) => {
|
|
232
|
-
try {
|
|
233
|
-
await submitForm(data);
|
|
234
|
-
ToastManager.show({
|
|
235
|
-
message: "Form submitted successfully! We'll get back to you soon.",
|
|
236
|
-
variant: "success",
|
|
237
|
-
autoClose: 4000,
|
|
238
|
-
});
|
|
239
|
-
} catch (error) {
|
|
240
|
-
ToastManager.show({
|
|
241
|
-
message: "Error: Failed to submit form. Please try again.",
|
|
242
|
-
variant: "destructive",
|
|
243
|
-
autoClose: 5000,
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
### Operación de Eliminación
|
|
250
|
-
|
|
251
|
-
```tsx
|
|
252
|
-
const handleDelete = async (itemId) => {
|
|
253
|
-
try {
|
|
254
|
-
await deleteItem(itemId);
|
|
255
|
-
ToastManager.show({
|
|
256
|
-
message: "Item deleted permanently",
|
|
257
|
-
variant: "destructive",
|
|
258
|
-
autoClose: 3000,
|
|
259
|
-
});
|
|
260
|
-
} catch (error) {
|
|
261
|
-
ToastManager.show({
|
|
262
|
-
message: "Error: Unable to delete item",
|
|
263
|
-
variant: "destructive",
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
### Validación de Formulario
|
|
270
|
-
|
|
271
|
-
```tsx
|
|
272
|
-
const validateForm = (formData) => {
|
|
273
|
-
if (!formData.email) {
|
|
274
|
-
ToastManager.show({
|
|
275
|
-
message: "Please complete all required fields",
|
|
276
|
-
variant: "warning",
|
|
277
|
-
autoClose: 4000,
|
|
278
|
-
});
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (!isValidEmail(formData.email)) {
|
|
283
|
-
ToastManager.show({
|
|
284
|
-
message: "Please enter a valid email address",
|
|
285
|
-
variant: "warning",
|
|
286
|
-
autoClose: 4000,
|
|
287
|
-
});
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return true;
|
|
292
|
-
};
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Múltiples Toasts Automáticos
|
|
296
|
-
|
|
297
|
-
El sistema de cola maneja múltiples toasts automáticamente:
|
|
298
|
-
|
|
299
|
-
```tsx
|
|
300
|
-
const showMultipleNotifications = () => {
|
|
301
|
-
// Los toasts se mostrarán secuencialmente
|
|
302
|
-
ToastManager.show({
|
|
303
|
-
message: "Step 1: Processing data...",
|
|
304
|
-
variant: "default",
|
|
305
|
-
autoClose: 2000,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
ToastManager.show({
|
|
309
|
-
message: "Step 2: Validating information...",
|
|
310
|
-
variant: "default",
|
|
311
|
-
autoClose: 2000,
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
ToastManager.show({
|
|
315
|
-
message: "Step 3: Complete!",
|
|
316
|
-
variant: "success",
|
|
317
|
-
autoClose: 3000,
|
|
318
|
-
});
|
|
319
|
-
};
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
## Características Avanzadas
|
|
323
|
-
|
|
324
|
-
### Sistema de Cola Automático
|
|
325
|
-
|
|
326
|
-
El Toaster incluye un sistema de cola interno que previene solapamientos:
|
|
327
|
-
|
|
328
|
-
- Múltiples toasts se encolan automáticamente
|
|
329
|
-
- Solo se muestra un toast a la vez
|
|
330
|
-
- Cada toast espera a que el anterior se cierre
|
|
331
|
-
- Transiciones suaves entre toasts
|
|
332
|
-
|
|
333
|
-
### Animaciones CSS
|
|
334
|
-
|
|
335
|
-
- **Entrada**: `toast-slide-up` - deslizamiento desde abajo con fade in
|
|
336
|
-
- **Salida**: `toast-slide-down` - deslizamiento hacia abajo con fade out
|
|
337
|
-
- Duración: ~300ms para transiciones suaves
|
|
338
|
-
- Clases CSS personalizadas para máximo control
|
|
339
|
-
|
|
340
|
-
### ID Único Automático
|
|
341
|
-
|
|
342
|
-
Cada toast genera un ID único automáticamente:
|
|
343
|
-
|
|
344
|
-
```tsx
|
|
345
|
-
// ID generado automáticamente basado en timestamp
|
|
346
|
-
ToastManager.show({ message: "Hello" });
|
|
347
|
-
|
|
348
|
-
// O proporciona tu propio ID personalizado
|
|
349
|
-
ToastManager.show({
|
|
350
|
-
id: "custom-toast-id",
|
|
351
|
-
message: "Hello with custom ID",
|
|
352
|
-
});
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
### Callback onClose
|
|
356
|
-
|
|
357
|
-
Ejecuta lógica personalizada cuando el toast se cierra:
|
|
358
|
-
|
|
359
|
-
```tsx
|
|
360
|
-
ToastManager.show({
|
|
361
|
-
message: "Processing...",
|
|
362
|
-
variant: "default",
|
|
363
|
-
onClose: () => {
|
|
364
|
-
console.log("Toast closed");
|
|
365
|
-
// Lógica adicional después del cierre
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
## Implementación Técnica
|
|
371
|
-
|
|
372
|
-
### Estructura Interna
|
|
373
|
-
|
|
374
|
-
- **ToastObservable**: Sistema de eventos para comunicación global
|
|
375
|
-
- **ToastManager**: Singleton para mostrar toasts desde cualquier lugar
|
|
376
|
-
- **Toaster**: Componente React que renderiza y maneja los toasts
|
|
377
|
-
- **Portal**: Renderizado fuera del árbol de componentes para posicionamiento fijo
|
|
378
|
-
|
|
379
|
-
### Estilos y Posicionamiento
|
|
380
|
-
|
|
381
|
-
- Prefijo `adm:` para evitar conflictos de CSS
|
|
382
|
-
- Posición: `fixed bottom-0 left-0 right-0 z-50`
|
|
383
|
-
- Full-width responsive con padding horizontal
|
|
384
|
-
- Portal rendering para z-index correcto
|
|
385
|
-
|
|
386
|
-
### Animaciones Personalizadas
|
|
387
|
-
|
|
388
|
-
```css
|
|
389
|
-
/* Definidas en CSS del componente */
|
|
390
|
-
@keyframes toast-slide-up {
|
|
391
|
-
from {
|
|
392
|
-
transform: translateY(100%);
|
|
393
|
-
opacity: 0;
|
|
394
|
-
}
|
|
395
|
-
to {
|
|
396
|
-
transform: translateY(0);
|
|
397
|
-
opacity: 1;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
@keyframes toast-slide-down {
|
|
402
|
-
from {
|
|
403
|
-
transform: translateY(0);
|
|
404
|
-
opacity: 1;
|
|
405
|
-
}
|
|
406
|
-
to {
|
|
407
|
-
transform: translateY(100%);
|
|
408
|
-
opacity: 0;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
## Limitaciones
|
|
414
|
-
|
|
415
|
-
- ❌ Solo un toast visible a la vez (cola secuencial)
|
|
416
|
-
- ❌ Sin acciones/botones dentro del toast
|
|
417
|
-
- ❌ Sin títulos separados del mensaje
|
|
418
|
-
- ❌ Posición fija (no configurable)
|
|
419
|
-
- ❌ Sin toasts apilados múltiples
|
|
420
|
-
|
|
421
|
-
## Accesibilidad
|
|
422
|
-
|
|
423
|
-
- ✅ Contraste de colores adecuado en todas las variantes
|
|
424
|
-
- ✅ Posicionamiento no intrusivo
|
|
425
|
-
- ✅ Auto-cierre configurable
|
|
426
|
-
- ✅ Cierre manual por click
|
|
427
|
-
- ⚠️ Sin `role="alert"` o `aria-live` (mejora futura)
|
|
428
|
-
- ⚠️ Sin navegación por teclado
|
|
429
|
-
|
|
430
|
-
## Roadmap Futuro
|
|
431
|
-
|
|
432
|
-
- Soporte para `role="alert"` y `aria-live`
|
|
433
|
-
- Acciones/botones dentro del toast
|
|
434
|
-
- Múltiples posiciones (top, center, corners)
|
|
435
|
-
- Toasts apilados/múltiples simultáneos
|
|
436
|
-
- Navegación por teclado (Escape para cerrar)
|
|
1
|
+
# Toaster Component
|
|
2
|
+
|
|
3
|
+
## Descripción
|
|
4
|
+
|
|
5
|
+
Sistema de **notificaciones toast** no intrusivas que aparecen en la parte inferior de la pantalla. Incluye sistema de cola automático para múltiples toasts, 4 variantes de color, auto-cierre configurable, y animaciones suaves de entrada/salida.
|
|
6
|
+
|
|
7
|
+
## Características
|
|
8
|
+
|
|
9
|
+
- ✅ 4 variantes visuales (default, success, warning, destructive)
|
|
10
|
+
- ✅ Sistema de cola automático para múltiples toasts
|
|
11
|
+
- ✅ Auto-cierre configurable (por defecto 3000ms)
|
|
12
|
+
- ✅ Toasts persistentes (sin auto-cierre)
|
|
13
|
+
- ✅ Animaciones suaves de entrada y salida
|
|
14
|
+
- ✅ Portal rendering para posicionamiento fijo
|
|
15
|
+
- ✅ IDs únicos automáticos
|
|
16
|
+
- ✅ Cierre manual programático
|
|
17
|
+
|
|
18
|
+
## Importación
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Toaster, ToastManager } from "@adamosuiteservices/ui/toaster";
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Setup Inicial
|
|
25
|
+
|
|
26
|
+
Agrega el componente `Toaster` en el nivel más alto de tu aplicación:
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { Toaster } from "@adamosuiteservices/ui/toaster";
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{/* Tu app aquí */}
|
|
35
|
+
<Toaster />
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Importante**: Solo necesitas una instancia de `Toaster` en toda tu aplicación.
|
|
42
|
+
|
|
43
|
+
## Uso Básico
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { ToastManager } from "@adamosuiteservices/ui/toaster";
|
|
47
|
+
import { Button } from "@adamosuiteservices/ui/button";
|
|
48
|
+
|
|
49
|
+
function MyComponent() {
|
|
50
|
+
return (
|
|
51
|
+
<Button
|
|
52
|
+
onClick={() => {
|
|
53
|
+
ToastManager.show({
|
|
54
|
+
message: "Changes have been saved successfully!",
|
|
55
|
+
variant: "success",
|
|
56
|
+
});
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
Save Changes
|
|
60
|
+
</Button>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Variantes
|
|
66
|
+
|
|
67
|
+
### default
|
|
68
|
+
|
|
69
|
+
Toast informativo general con fondo azul claro.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
ToastManager.show({
|
|
73
|
+
message: "This is a general informational message",
|
|
74
|
+
variant: "default",
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Estilos**:
|
|
79
|
+
|
|
80
|
+
- Fondo: `bg-primary-200`
|
|
81
|
+
- Texto: `text-foreground`
|
|
82
|
+
- Uso: Información general, confirmaciones neutrales
|
|
83
|
+
|
|
84
|
+
### success
|
|
85
|
+
|
|
86
|
+
Toast verde para acciones exitosas o confirmaciones positivas.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
ToastManager.show({
|
|
90
|
+
message: "Operation completed successfully!",
|
|
91
|
+
variant: "success",
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Estilos**:
|
|
96
|
+
|
|
97
|
+
- Fondo: `bg-success-50` (verde claro)
|
|
98
|
+
- Texto: `text-success`
|
|
99
|
+
- Uso: Guardado exitoso, operaciones completadas, confirmaciones
|
|
100
|
+
|
|
101
|
+
### warning
|
|
102
|
+
|
|
103
|
+
Toast amarillo para advertencias importantes.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
ToastManager.show({
|
|
107
|
+
message: "Your session will expire in 5 minutes",
|
|
108
|
+
variant: "warning",
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Estilos**:
|
|
113
|
+
|
|
114
|
+
- Fondo: `bg-warning-50` (amarillo claro)
|
|
115
|
+
- Texto: `text-warning`
|
|
116
|
+
- Uso: Advertencias, validaciones, alertas preventivas
|
|
117
|
+
|
|
118
|
+
### destructive
|
|
119
|
+
|
|
120
|
+
Toast rojo para errores críticos o acciones destructivas.
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
ToastManager.show({
|
|
124
|
+
message: "Error: Unable to complete the operation",
|
|
125
|
+
variant: "destructive",
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Estilos**:
|
|
130
|
+
|
|
131
|
+
- Fondo: `bg-destructive-50` (rojo claro)
|
|
132
|
+
- Texto: `text-destructive`
|
|
133
|
+
- Uso: Errores, fallos de operación, acciones destructivas
|
|
134
|
+
|
|
135
|
+
## Duración y Control
|
|
136
|
+
|
|
137
|
+
### Auto-cierre Personalizado
|
|
138
|
+
|
|
139
|
+
Por defecto, los toasts se cierran automáticamente después de 3 segundos (3000ms).
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
// Toast rápido (1 segundo)
|
|
143
|
+
ToastManager.show({
|
|
144
|
+
message: "Quick notification",
|
|
145
|
+
variant: "default",
|
|
146
|
+
autoClose: 1000,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Toast normal (3 segundos - default)
|
|
150
|
+
ToastManager.show({
|
|
151
|
+
message: "Normal duration",
|
|
152
|
+
variant: "success",
|
|
153
|
+
autoClose: 3000,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Toast largo (5 segundos)
|
|
157
|
+
ToastManager.show({
|
|
158
|
+
message: "Important message - read carefully",
|
|
159
|
+
variant: "warning",
|
|
160
|
+
autoClose: 5000,
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Toast Persistente
|
|
165
|
+
|
|
166
|
+
Para mensajes que requieren confirmación del usuario:
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
// Mostrar toast sin auto-cierre
|
|
170
|
+
ToastManager.show({
|
|
171
|
+
message: "This message requires your attention",
|
|
172
|
+
variant: "destructive",
|
|
173
|
+
autoClose: undefined, // No se cierra automáticamente
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Los toasts persistentes se pueden cerrar manualmente por el usuario
|
|
177
|
+
// haciendo click en el toast o con acciones específicas de tu app
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## API
|
|
181
|
+
|
|
182
|
+
### ToastManager.show()
|
|
183
|
+
|
|
184
|
+
Método principal para mostrar toasts desde cualquier parte de tu aplicación.
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
ToastManager.show({
|
|
188
|
+
message: "Your message here",
|
|
189
|
+
variant: "success",
|
|
190
|
+
autoClose: 3000,
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Toast Type
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
type Toast = {
|
|
198
|
+
id?: string;
|
|
199
|
+
message: string;
|
|
200
|
+
variant?: "default" | "success" | "warning" | "destructive";
|
|
201
|
+
autoClose?: number;
|
|
202
|
+
onClose?: () => void;
|
|
203
|
+
};
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Props
|
|
207
|
+
|
|
208
|
+
### Toast Options
|
|
209
|
+
|
|
210
|
+
| Prop | Tipo | Default | Descripción |
|
|
211
|
+
| --------- | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------ |
|
|
212
|
+
| id | `string` | Auto-generado | Identificador único del toast (opcional) |
|
|
213
|
+
| message | `string` | - | **Requerido**. Texto a mostrar |
|
|
214
|
+
| variant | `"default" \| "success" \| "warning" \| "destructive"` | `"default"` | Variante de color |
|
|
215
|
+
| autoClose | `number \| undefined` | `3000` | Duración en ms antes de cerrarse automáticamente. `undefined` para persistente |
|
|
216
|
+
| onClose | `() => void` | `undefined` | Callback ejecutado cuando el toast se cierra |
|
|
217
|
+
|
|
218
|
+
### Toaster Component
|
|
219
|
+
|
|
220
|
+
El componente `Toaster` no requiere props - simplemente inclúyelo en tu app.
|
|
221
|
+
|
|
222
|
+
| Prop | Tipo | Descripción |
|
|
223
|
+
| ---- | ---- | ----------- |
|
|
224
|
+
| - | - | Sin props |
|
|
225
|
+
|
|
226
|
+
## Ejemplos de Uso
|
|
227
|
+
|
|
228
|
+
### Formulario Enviado con Éxito
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
const handleSubmit = async (data) => {
|
|
232
|
+
try {
|
|
233
|
+
await submitForm(data);
|
|
234
|
+
ToastManager.show({
|
|
235
|
+
message: "Form submitted successfully! We'll get back to you soon.",
|
|
236
|
+
variant: "success",
|
|
237
|
+
autoClose: 4000,
|
|
238
|
+
});
|
|
239
|
+
} catch (error) {
|
|
240
|
+
ToastManager.show({
|
|
241
|
+
message: "Error: Failed to submit form. Please try again.",
|
|
242
|
+
variant: "destructive",
|
|
243
|
+
autoClose: 5000,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Operación de Eliminación
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
const handleDelete = async (itemId) => {
|
|
253
|
+
try {
|
|
254
|
+
await deleteItem(itemId);
|
|
255
|
+
ToastManager.show({
|
|
256
|
+
message: "Item deleted permanently",
|
|
257
|
+
variant: "destructive",
|
|
258
|
+
autoClose: 3000,
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
ToastManager.show({
|
|
262
|
+
message: "Error: Unable to delete item",
|
|
263
|
+
variant: "destructive",
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Validación de Formulario
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
const validateForm = (formData) => {
|
|
273
|
+
if (!formData.email) {
|
|
274
|
+
ToastManager.show({
|
|
275
|
+
message: "Please complete all required fields",
|
|
276
|
+
variant: "warning",
|
|
277
|
+
autoClose: 4000,
|
|
278
|
+
});
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!isValidEmail(formData.email)) {
|
|
283
|
+
ToastManager.show({
|
|
284
|
+
message: "Please enter a valid email address",
|
|
285
|
+
variant: "warning",
|
|
286
|
+
autoClose: 4000,
|
|
287
|
+
});
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Múltiples Toasts Automáticos
|
|
296
|
+
|
|
297
|
+
El sistema de cola maneja múltiples toasts automáticamente:
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
const showMultipleNotifications = () => {
|
|
301
|
+
// Los toasts se mostrarán secuencialmente
|
|
302
|
+
ToastManager.show({
|
|
303
|
+
message: "Step 1: Processing data...",
|
|
304
|
+
variant: "default",
|
|
305
|
+
autoClose: 2000,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
ToastManager.show({
|
|
309
|
+
message: "Step 2: Validating information...",
|
|
310
|
+
variant: "default",
|
|
311
|
+
autoClose: 2000,
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
ToastManager.show({
|
|
315
|
+
message: "Step 3: Complete!",
|
|
316
|
+
variant: "success",
|
|
317
|
+
autoClose: 3000,
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Características Avanzadas
|
|
323
|
+
|
|
324
|
+
### Sistema de Cola Automático
|
|
325
|
+
|
|
326
|
+
El Toaster incluye un sistema de cola interno que previene solapamientos:
|
|
327
|
+
|
|
328
|
+
- Múltiples toasts se encolan automáticamente
|
|
329
|
+
- Solo se muestra un toast a la vez
|
|
330
|
+
- Cada toast espera a que el anterior se cierre
|
|
331
|
+
- Transiciones suaves entre toasts
|
|
332
|
+
|
|
333
|
+
### Animaciones CSS
|
|
334
|
+
|
|
335
|
+
- **Entrada**: `toast-slide-up` - deslizamiento desde abajo con fade in
|
|
336
|
+
- **Salida**: `toast-slide-down` - deslizamiento hacia abajo con fade out
|
|
337
|
+
- Duración: ~300ms para transiciones suaves
|
|
338
|
+
- Clases CSS personalizadas para máximo control
|
|
339
|
+
|
|
340
|
+
### ID Único Automático
|
|
341
|
+
|
|
342
|
+
Cada toast genera un ID único automáticamente:
|
|
343
|
+
|
|
344
|
+
```tsx
|
|
345
|
+
// ID generado automáticamente basado en timestamp
|
|
346
|
+
ToastManager.show({ message: "Hello" });
|
|
347
|
+
|
|
348
|
+
// O proporciona tu propio ID personalizado
|
|
349
|
+
ToastManager.show({
|
|
350
|
+
id: "custom-toast-id",
|
|
351
|
+
message: "Hello with custom ID",
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Callback onClose
|
|
356
|
+
|
|
357
|
+
Ejecuta lógica personalizada cuando el toast se cierra:
|
|
358
|
+
|
|
359
|
+
```tsx
|
|
360
|
+
ToastManager.show({
|
|
361
|
+
message: "Processing...",
|
|
362
|
+
variant: "default",
|
|
363
|
+
onClose: () => {
|
|
364
|
+
console.log("Toast closed");
|
|
365
|
+
// Lógica adicional después del cierre
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Implementación Técnica
|
|
371
|
+
|
|
372
|
+
### Estructura Interna
|
|
373
|
+
|
|
374
|
+
- **ToastObservable**: Sistema de eventos para comunicación global
|
|
375
|
+
- **ToastManager**: Singleton para mostrar toasts desde cualquier lugar
|
|
376
|
+
- **Toaster**: Componente React que renderiza y maneja los toasts
|
|
377
|
+
- **Portal**: Renderizado fuera del árbol de componentes para posicionamiento fijo
|
|
378
|
+
|
|
379
|
+
### Estilos y Posicionamiento
|
|
380
|
+
|
|
381
|
+
- Prefijo `adm:` para evitar conflictos de CSS
|
|
382
|
+
- Posición: `fixed bottom-0 left-0 right-0 z-50`
|
|
383
|
+
- Full-width responsive con padding horizontal
|
|
384
|
+
- Portal rendering para z-index correcto
|
|
385
|
+
|
|
386
|
+
### Animaciones Personalizadas
|
|
387
|
+
|
|
388
|
+
```css
|
|
389
|
+
/* Definidas en CSS del componente */
|
|
390
|
+
@keyframes toast-slide-up {
|
|
391
|
+
from {
|
|
392
|
+
transform: translateY(100%);
|
|
393
|
+
opacity: 0;
|
|
394
|
+
}
|
|
395
|
+
to {
|
|
396
|
+
transform: translateY(0);
|
|
397
|
+
opacity: 1;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
@keyframes toast-slide-down {
|
|
402
|
+
from {
|
|
403
|
+
transform: translateY(0);
|
|
404
|
+
opacity: 1;
|
|
405
|
+
}
|
|
406
|
+
to {
|
|
407
|
+
transform: translateY(100%);
|
|
408
|
+
opacity: 0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Limitaciones
|
|
414
|
+
|
|
415
|
+
- ❌ Solo un toast visible a la vez (cola secuencial)
|
|
416
|
+
- ❌ Sin acciones/botones dentro del toast
|
|
417
|
+
- ❌ Sin títulos separados del mensaje
|
|
418
|
+
- ❌ Posición fija (no configurable)
|
|
419
|
+
- ❌ Sin toasts apilados múltiples
|
|
420
|
+
|
|
421
|
+
## Accesibilidad
|
|
422
|
+
|
|
423
|
+
- ✅ Contraste de colores adecuado en todas las variantes
|
|
424
|
+
- ✅ Posicionamiento no intrusivo
|
|
425
|
+
- ✅ Auto-cierre configurable
|
|
426
|
+
- ✅ Cierre manual por click
|
|
427
|
+
- ⚠️ Sin `role="alert"` o `aria-live` (mejora futura)
|
|
428
|
+
- ⚠️ Sin navegación por teclado
|
|
429
|
+
|
|
430
|
+
## Roadmap Futuro
|
|
431
|
+
|
|
432
|
+
- Soporte para `role="alert"` y `aria-live`
|
|
433
|
+
- Acciones/botones dentro del toast
|
|
434
|
+
- Múltiples posiciones (top, center, corners)
|
|
435
|
+
- Toasts apilados/múltiples simultáneos
|
|
436
|
+
- Navegación por teclado (Escape para cerrar)
|