@rkosafo/cai.components 0.0.38 → 0.0.39

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/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export * from './ui/icons/index.js';
26
26
  export * from './ui/box/index.js';
27
27
  export * from './ui/breadcrumb/index.js';
28
28
  export * from './layout/ComponentCanvas/index.js';
29
+ export * from './ui/toast/index.js';
29
30
  export * from './forms/input/index.js';
30
31
  export * from './forms/label/index.js';
31
32
  export * from './forms/datepicker/index.js';
@@ -44,6 +45,7 @@ export * from './forms/FormClEditor/index.js';
44
45
  export * from './builders/filters/index.js';
45
46
  export * from './types/index.js';
46
47
  export * from './utils/index.js';
48
+ export * from './utils/svelte-legos.js';
47
49
  import 'iconify-icon';
48
50
  export * from './keycloak/index.js';
49
51
  export { YouTube, BaseEditor };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ export * from './ui/icons/index.js';
27
27
  export * from './ui/box/index.js';
28
28
  export * from './ui/breadcrumb/index.js';
29
29
  export * from './layout/ComponentCanvas/index.js';
30
+ export * from './ui/toast/index.js';
30
31
  export * from './forms/input/index.js';
31
32
  export * from './forms/label/index.js';
32
33
  export * from './forms/datepicker/index.js';
@@ -45,6 +46,7 @@ export * from './forms/FormClEditor/index.js';
45
46
  export * from './builders/filters/index.js';
46
47
  export * from './types/index.js';
47
48
  export * from './utils/index.js';
49
+ export * from './utils/svelte-legos.js';
48
50
  import 'iconify-icon';
49
51
  export * from './keycloak/index.js';
50
52
  export { YouTube, BaseEditor };
@@ -0,0 +1,337 @@
1
+ <script lang="ts" module>
2
+ export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
3
+ export type ToastPosition =
4
+ | 'top-left'
5
+ | 'top-center'
6
+ | 'top-right'
7
+ | 'bottom-left'
8
+ | 'bottom-center'
9
+ | 'bottom-right';
10
+
11
+ export interface CustomToastOptions extends ToastOptions {
12
+ icon?: string;
13
+ showProgress?: boolean;
14
+ progressColor?: string;
15
+ borderColor?: string;
16
+ backgroundColor?: string;
17
+ textColor?: string;
18
+ iconColor?: string;
19
+ style?: any;
20
+ action?: {
21
+ label: string;
22
+ onClick: () => void;
23
+ buttonStyle?: string;
24
+ };
25
+ }
26
+
27
+ export interface ToastTheme {
28
+ success?: Partial<CustomToastOptions>;
29
+ error?: Partial<CustomToastOptions>;
30
+ warning?: Partial<CustomToastOptions>;
31
+ info?: Partial<CustomToastOptions>;
32
+ loading?: Partial<CustomToastOptions>;
33
+ custom?: Partial<CustomToastOptions>;
34
+ }
35
+
36
+ export interface ToasterProps {
37
+ position?: ToastPosition;
38
+ duration?: number;
39
+ theme?: ToastTheme;
40
+ className?: string;
41
+ toastOptions?: ToastOptions;
42
+ richColors?: boolean;
43
+ customIcons?: boolean;
44
+ closeButton?: boolean;
45
+ pauseOnHover?: boolean;
46
+ reverseOrder?: boolean;
47
+ visibleToasts?: number;
48
+ expand?: boolean;
49
+ gap?: number;
50
+ offset?: number | string;
51
+ }
52
+ // Default theme configuration
53
+ const defaultTheme: ToastTheme = {
54
+ success: {
55
+ icon: '✅',
56
+ borderColor: '#22c55e',
57
+ backgroundColor: '#f0fdf4',
58
+ textColor: '#166534',
59
+ iconColor: '#16a34a',
60
+ progressColor: '#22c55e'
61
+ },
62
+ error: {
63
+ icon: '❌',
64
+ borderColor: '#ef4444',
65
+ backgroundColor: '#fef2f2',
66
+ textColor: '#991b1b',
67
+ iconColor: '#dc2626',
68
+ progressColor: '#ef4444'
69
+ },
70
+ warning: {
71
+ icon: '⚠️',
72
+ borderColor: '#f59e0b',
73
+ backgroundColor: '#fffbeb',
74
+ textColor: '#92400e',
75
+ iconColor: '#d97706',
76
+ progressColor: '#f59e0b'
77
+ },
78
+ info: {
79
+ icon: 'ℹ️',
80
+ borderColor: '#3b82f6',
81
+ backgroundColor: '#eff6ff',
82
+ textColor: '#1e40af',
83
+ iconColor: '#2563eb',
84
+ progressColor: '#3b82f6'
85
+ },
86
+ loading: {
87
+ icon: '⏳',
88
+ borderColor: '#6b7280',
89
+ backgroundColor: '#f9fafb',
90
+ textColor: '#374151',
91
+ iconColor: '#6b7280',
92
+ progressColor: '#6b7280'
93
+ }
94
+ };
95
+
96
+ let currentDuration = 4000;
97
+ let currentTheme: ToastTheme = {};
98
+ let currentRichColors = false;
99
+
100
+ function buildToastStyle(
101
+ theme: Partial<CustomToastOptions>,
102
+ options?: CustomToastOptions,
103
+ type?: ToastType,
104
+ richColors?: boolean
105
+ ): string {
106
+ if (options?.style) return options.style;
107
+
108
+ const baseStyle = `
109
+ border: 1px solid ${options?.borderColor || theme.borderColor || '#e5e7eb'};
110
+ background: ${options?.backgroundColor || theme.backgroundColor || '#ffffff'};
111
+ color: ${options?.textColor || theme.textColor || '#1f2937'};
112
+ padding: 12px 16px;
113
+ border-radius: 8px;
114
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
115
+ font-size: 14px;
116
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
117
+ display: flex;
118
+ align-items: center;
119
+ gap: 8px;
120
+ `;
121
+
122
+ if (richColors && type && defaultTheme[type]) {
123
+ const richTheme = defaultTheme[type]!;
124
+ return `
125
+ ${baseStyle}
126
+ border-color: ${options?.borderColor || richTheme.borderColor}!important;
127
+ background: ${options?.backgroundColor || richTheme.backgroundColor}!important;
128
+ color: ${options?.textColor || richTheme.textColor}!important;
129
+ `;
130
+ }
131
+
132
+ return baseStyle;
133
+ }
134
+
135
+ export const toast = {
136
+ success: (message: string, options?: CustomToastOptions) => {
137
+ const themeOptions = currentTheme?.success || defaultTheme.success || {};
138
+ const style = buildToastStyle(themeOptions, options, 'success');
139
+
140
+ return originalToast.success(message, {
141
+ duration: currentDuration,
142
+ ...themeOptions,
143
+ ...options,
144
+ style,
145
+ icon: options?.icon || themeOptions.icon
146
+ });
147
+ },
148
+
149
+ error: (message: string, options?: CustomToastOptions) => {
150
+ const themeOptions = currentTheme?.error || defaultTheme.error || {};
151
+ const style = buildToastStyle(themeOptions, options, 'error');
152
+
153
+ return originalToast.error(message, {
154
+ duration: currentDuration,
155
+ ...themeOptions,
156
+ ...options,
157
+ style,
158
+ icon: options?.icon || themeOptions.icon
159
+ });
160
+ },
161
+
162
+ warning: (message: string, options?: CustomToastOptions) => {
163
+ const themeOptions = currentTheme?.warning || defaultTheme.warning || {};
164
+ const style = buildToastStyle(themeOptions, options, 'warning');
165
+
166
+ return originalToast(message, {
167
+ duration: currentDuration,
168
+ ...themeOptions,
169
+ ...options,
170
+ style,
171
+ icon: options?.icon || themeOptions.icon
172
+ });
173
+ },
174
+
175
+ info: (message: string, options?: CustomToastOptions) => {
176
+ const themeOptions = currentTheme?.info || defaultTheme.info || {};
177
+ const style = buildToastStyle(themeOptions, options, 'info');
178
+
179
+ return originalToast(message, {
180
+ duration: currentDuration,
181
+ ...themeOptions,
182
+ ...options,
183
+ style,
184
+ icon: options?.icon || themeOptions.icon
185
+ });
186
+ },
187
+
188
+ loading: (message: string, options?: CustomToastOptions) => {
189
+ const themeOptions = currentTheme?.loading || defaultTheme.loading || {};
190
+ const style = buildToastStyle(themeOptions, options, 'loading');
191
+
192
+ return originalToast.loading(message, {
193
+ duration: currentDuration,
194
+ ...themeOptions,
195
+ ...options,
196
+ style,
197
+ icon: options?.icon || themeOptions.icon
198
+ });
199
+ },
200
+
201
+ promise: <T,>(
202
+ promise: Promise<T>,
203
+ messages: { loading: string; success: string; error: string },
204
+ options?: {
205
+ loading?: CustomToastOptions;
206
+ success?: CustomToastOptions;
207
+ error?: CustomToastOptions;
208
+ }
209
+ ) => {
210
+ const loadingTheme = currentTheme?.loading || defaultTheme.loading || {};
211
+ const successTheme = currentTheme?.success || defaultTheme.success || {};
212
+ const errorTheme = currentTheme?.error || defaultTheme.error || {};
213
+
214
+ return originalToast.promise(promise, messages, {
215
+ loading: {
216
+ ...loadingTheme,
217
+ ...options?.loading,
218
+ style: buildToastStyle(loadingTheme, options?.loading, 'loading'),
219
+ icon: options?.loading?.icon || loadingTheme.icon
220
+ },
221
+ success: {
222
+ ...successTheme,
223
+ ...options?.success,
224
+ style: buildToastStyle(successTheme, options?.success, 'success'),
225
+ icon: options?.success?.icon || successTheme.icon
226
+ },
227
+ error: {
228
+ ...errorTheme,
229
+ ...options?.error,
230
+ style: buildToastStyle(errorTheme, options?.error, 'error'),
231
+ icon: options?.error?.icon || errorTheme.icon
232
+ }
233
+ });
234
+ },
235
+
236
+ // Custom toast with complete control
237
+ custom: (message: string, type: ToastType = 'info', options?: CustomToastOptions) => {
238
+ const themeOptions = currentTheme?.[type] || defaultTheme[type] || defaultTheme.info || {};
239
+ const style = buildToastStyle(themeOptions, options, type);
240
+
241
+ return originalToast(message, {
242
+ duration: currentDuration,
243
+ ...themeOptions,
244
+ ...options,
245
+ style,
246
+ icon: options?.icon || themeOptions.icon
247
+ });
248
+ },
249
+
250
+ // Action toast with button
251
+ action: (
252
+ message: string,
253
+ action: { label: string; onClick: () => void },
254
+ options?: CustomToastOptions
255
+ ) => {
256
+ const themeOptions = currentTheme?.info || defaultTheme.info || {};
257
+ const style = buildToastStyle(themeOptions, options, 'info');
258
+
259
+ return originalToast(message, {
260
+ duration: currentDuration,
261
+ ...themeOptions,
262
+ ...options,
263
+ style,
264
+ icon: options?.icon || themeOptions.icon,
265
+ action: {
266
+ label: action.label,
267
+ onClick: action.onClick,
268
+ buttonStyle:
269
+ options?.action?.buttonStyle ||
270
+ 'background: #3b82f6; color: white; border: none; padding: 4px 12px; border-radius: 4px; cursor: pointer;'
271
+ }
272
+ });
273
+ },
274
+
275
+ // Dismiss specific toast or all toasts
276
+ dismiss: (toastId?: string) => {
277
+ return originalToast.dismiss(toastId);
278
+ },
279
+
280
+ // Remove specific toast
281
+ remove: (toastId?: string) => {
282
+ return originalToast.remove(toastId);
283
+ }
284
+ };
285
+
286
+ export function updateToastConfig(config: {
287
+ duration?: number;
288
+ theme?: ToastTheme;
289
+ richColors?: boolean;
290
+ }) {
291
+ if (config.duration !== undefined) currentDuration = config.duration;
292
+ if (config.theme !== undefined) currentTheme = config.theme;
293
+ if (config.richColors !== undefined) currentRichColors = config.richColors;
294
+ }
295
+
296
+ export { originalToast };
297
+ export type { ToastOptions };
298
+ </script>
299
+
300
+ <script lang="ts">
301
+ import { Toaster, toast as originalToast, type ToastOptions } from 'svelte-french-toast';
302
+
303
+ let {
304
+ position = 'top-center',
305
+ duration = 4000,
306
+ theme = {},
307
+ className = '',
308
+ toastOptions = {},
309
+ richColors = false,
310
+ customIcons = true,
311
+ closeButton = true,
312
+ pauseOnHover = true,
313
+ reverseOrder = false,
314
+ visibleToasts = 3,
315
+ expand = false,
316
+ gap = 8,
317
+ offset = '32px'
318
+ }: ToasterProps = $props();
319
+
320
+ $effect(() => {
321
+ updateToastConfig({ duration, theme, richColors });
322
+ });
323
+ </script>
324
+
325
+ <Toaster
326
+ {position}
327
+ {duration}
328
+ {className}
329
+ {toastOptions}
330
+ {closeButton}
331
+ {pauseOnHover}
332
+ {reverseOrder}
333
+ {visibleToasts}
334
+ {expand}
335
+ {gap}
336
+ {offset}
337
+ />
@@ -0,0 +1,75 @@
1
+ export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
2
+ export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
3
+ export interface CustomToastOptions extends ToastOptions {
4
+ icon?: string;
5
+ showProgress?: boolean;
6
+ progressColor?: string;
7
+ borderColor?: string;
8
+ backgroundColor?: string;
9
+ textColor?: string;
10
+ iconColor?: string;
11
+ style?: any;
12
+ action?: {
13
+ label: string;
14
+ onClick: () => void;
15
+ buttonStyle?: string;
16
+ };
17
+ }
18
+ export interface ToastTheme {
19
+ success?: Partial<CustomToastOptions>;
20
+ error?: Partial<CustomToastOptions>;
21
+ warning?: Partial<CustomToastOptions>;
22
+ info?: Partial<CustomToastOptions>;
23
+ loading?: Partial<CustomToastOptions>;
24
+ custom?: Partial<CustomToastOptions>;
25
+ }
26
+ export interface ToasterProps {
27
+ position?: ToastPosition;
28
+ duration?: number;
29
+ theme?: ToastTheme;
30
+ className?: string;
31
+ toastOptions?: ToastOptions;
32
+ richColors?: boolean;
33
+ customIcons?: boolean;
34
+ closeButton?: boolean;
35
+ pauseOnHover?: boolean;
36
+ reverseOrder?: boolean;
37
+ visibleToasts?: number;
38
+ expand?: boolean;
39
+ gap?: number;
40
+ offset?: number | string;
41
+ }
42
+ export declare const toast: {
43
+ success: (message: string, options?: CustomToastOptions) => string;
44
+ error: (message: string, options?: CustomToastOptions) => string;
45
+ warning: (message: string, options?: CustomToastOptions) => string;
46
+ info: (message: string, options?: CustomToastOptions) => string;
47
+ loading: (message: string, options?: CustomToastOptions) => string;
48
+ promise: <T>(promise: Promise<T>, messages: {
49
+ loading: string;
50
+ success: string;
51
+ error: string;
52
+ }, options?: {
53
+ loading?: CustomToastOptions;
54
+ success?: CustomToastOptions;
55
+ error?: CustomToastOptions;
56
+ }) => Promise<T>;
57
+ custom: (message: string, type?: ToastType, options?: CustomToastOptions) => string;
58
+ action: (message: string, action: {
59
+ label: string;
60
+ onClick: () => void;
61
+ }, options?: CustomToastOptions) => string;
62
+ dismiss: (toastId?: string) => void;
63
+ remove: (toastId?: string) => void;
64
+ };
65
+ export declare function updateToastConfig(config: {
66
+ duration?: number;
67
+ theme?: ToastTheme;
68
+ richColors?: boolean;
69
+ }): void;
70
+ export { originalToast };
71
+ export type { ToastOptions };
72
+ import { toast as originalToast, type ToastOptions } from 'svelte-french-toast';
73
+ declare const Toast: import("svelte").Component<ToasterProps, {}, "">;
74
+ type Toast = ReturnType<typeof Toast>;
75
+ export default Toast;
@@ -0,0 +1,2 @@
1
+ export { default as Toaster, toast } from './Toast.svelte';
2
+ export type { ToasterProps, ToastType, CustomToastOptions, ToastTheme } from './Toast.svelte';
@@ -0,0 +1 @@
1
+ export { default as Toaster, toast } from './Toast.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rkosafo/cai.components",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -64,6 +64,7 @@
64
64
  "mdsvex": "^0.12.6",
65
65
  "nanoid": "^5.1.5",
66
66
  "svelecte": "^5.3.0",
67
+ "svelte-french-toast": "^1.2.0",
67
68
  "svelte-headless-table": "^0.18.3",
68
69
  "svelte-meta-tags": "^4.4.0",
69
70
  "tailwind-merge": "^3.3.1",