kimu-core 0.4.1 → 0.5.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/.editorconfig +116 -30
- package/.gitattributes +81 -11
- package/.github/FUNDING.yml +8 -8
- package/.github/kimu-copilot-instructions.md +3779 -3779
- package/.github/workflows/deploy-demo.yml +39 -39
- package/.nvmrc +1 -0
- package/.prettierignore +44 -0
- package/.prettierrc +16 -0
- package/FUNDING.md +31 -31
- package/icon.svg +10 -10
- package/kimu-core-0.5.0.tgz +0 -0
- package/package.json +10 -3
- package/scripts/minify-css-assets.js +82 -82
- package/src/core/index.ts +47 -47
- package/src/core/kimu-global-styles.ts +136 -136
- package/src/core/kimu-reactive.ts +196 -196
- package/src/extensions/{kimu-home → app-root}/component.ts +5 -5
- package/src/extensions/extensions-manifest.json +4 -4
- package/src/main.ts +3 -3
- package/src/modules-repository/api-axios/CHANGELOG.md +48 -48
- package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -178
- package/src/modules-repository/api-axios/README.md +304 -304
- package/src/modules-repository/api-axios/api-axios-service.ts +355 -355
- package/src/modules-repository/api-axios/examples.ts +293 -293
- package/src/modules-repository/api-axios/index.ts +19 -19
- package/src/modules-repository/api-axios/interfaces.ts +71 -71
- package/src/modules-repository/api-axios/module.ts +41 -41
- package/src/modules-repository/api-core/CHANGELOG.md +42 -42
- package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -192
- package/src/modules-repository/api-core/README.md +435 -435
- package/src/modules-repository/api-core/api-core-service.ts +289 -289
- package/src/modules-repository/api-core/examples.ts +432 -432
- package/src/modules-repository/api-core/index.ts +8 -8
- package/src/modules-repository/api-core/interfaces.ts +83 -83
- package/src/modules-repository/api-core/module.ts +30 -30
- package/src/modules-repository/event-bus/README.md +273 -273
- package/src/modules-repository/event-bus/event-bus-service.ts +176 -176
- package/src/modules-repository/event-bus/module.ts +30 -30
- package/src/modules-repository/notification/README.md +423 -423
- package/src/modules-repository/notification/module.ts +30 -30
- package/src/modules-repository/notification/notification-service.ts +436 -436
- package/src/modules-repository/router/README.it.md +61 -10
- package/src/modules-repository/router/README.md +61 -10
- package/src/modules-repository/router/router-config.ts.example +61 -0
- package/src/modules-repository/router/router.ts +18 -0
- package/src/modules-repository/state/README.md +409 -409
- package/src/modules-repository/state/module.ts +30 -30
- package/src/modules-repository/state/state-service.ts +296 -296
- package/src/modules-repository/theme/README.md +311 -267
- package/src/modules-repository/theme/module.ts +30 -30
- package/src/modules-repository/theme/pre-build.js +40 -40
- package/src/modules-repository/theme/theme-service.ts +411 -389
- package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -78
- package/src/modules-repository/theme/themes/theme-cozy.css +111 -111
- package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -150
- package/src/modules-repository/theme/themes/theme-dark.css +79 -79
- package/src/modules-repository/theme/themes/theme-forest.css +171 -171
- package/src/modules-repository/theme/themes/theme-gold.css +100 -100
- package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -126
- package/src/modules-repository/theme/themes/theme-lava.css +101 -101
- package/src/modules-repository/theme/themes/theme-lavender.css +90 -90
- package/src/modules-repository/theme/themes/theme-light.css +79 -79
- package/src/modules-repository/theme/themes/theme-matrix.css +103 -103
- package/src/modules-repository/theme/themes/theme-midnight.css +81 -81
- package/src/modules-repository/theme/themes/theme-nord.css +94 -94
- package/src/modules-repository/theme/themes/theme-ocean.css +84 -84
- package/src/modules-repository/theme/themes/theme-retro80s.css +343 -343
- package/src/modules-repository/theme/themes/theme-sunset.css +62 -62
- package/src/modules-repository/theme/themes-config-default.json +19 -0
- package/src/modules-repository/theme/themes-config.d.ts +27 -27
- package/src/modules-repository/theme/{themes-config.json → themes-config.json.example} +223 -213
- /package/src/extensions/{kimu-home → app-root}/lang/en.json +0 -0
- /package/src/extensions/{kimu-home → app-root}/lang/it.json +0 -0
- /package/src/extensions/{kimu-home → app-root}/style.css +0 -0
- /package/src/extensions/{kimu-home → app-root}/view.html +0 -0
|
@@ -1,423 +1,423 @@
|
|
|
1
|
-
# Notification Module
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
The Notification module provides a toast notification system for KIMU-Core applications. It supports different notification types (success, error, warning, info), customizable durations, positions, and styling.
|
|
5
|
-
|
|
6
|
-
## Features
|
|
7
|
-
- ✅ **Multiple types** - Success, error, warning, info notifications
|
|
8
|
-
- ✅ **Customizable position** - 6 position options (top/bottom + left/center/right)
|
|
9
|
-
- ✅ **Auto-dismiss** - Configurable duration or persistent
|
|
10
|
-
- ✅ **Dismissible** - Optional close button
|
|
11
|
-
- ✅ **Click handlers** - Custom actions on click
|
|
12
|
-
- ✅ **Styled** - Beautiful, responsive design out-of-the-box
|
|
13
|
-
- ✅ **Max limit** - Prevents notification overflow
|
|
14
|
-
- ✅ **Animations** - Smooth enter/exit transitions
|
|
15
|
-
- ✅ **Debug mode** - Optional logging for development
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
The Notification module is included in KIMU-Core. No additional installation required.
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
### Basic Examples
|
|
23
|
-
```typescript
|
|
24
|
-
import { notificationService } from './modules/notification/notification-service';
|
|
25
|
-
|
|
26
|
-
// Success notification
|
|
27
|
-
notificationService.success('Profile updated successfully!');
|
|
28
|
-
|
|
29
|
-
// Error notification
|
|
30
|
-
notificationService.error('Failed to save changes');
|
|
31
|
-
|
|
32
|
-
// Warning notification
|
|
33
|
-
notificationService.warning('Your session will expire in 5 minutes');
|
|
34
|
-
|
|
35
|
-
// Info notification
|
|
36
|
-
notificationService.info('New message received');
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Custom Duration
|
|
40
|
-
```typescript
|
|
41
|
-
// Show for 5 seconds
|
|
42
|
-
notificationService.success('Operation completed!', { duration: 5000 });
|
|
43
|
-
|
|
44
|
-
// Persistent (no auto-dismiss)
|
|
45
|
-
notificationService.info('Important message', { duration: 0 });
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Custom Position
|
|
49
|
-
```typescript
|
|
50
|
-
// Bottom right
|
|
51
|
-
notificationService.info('Download complete', {
|
|
52
|
-
position: 'bottom-right'
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Top center
|
|
56
|
-
notificationService.warning('Network connection lost', {
|
|
57
|
-
position: 'top-center'
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Available positions:
|
|
61
|
-
// 'top-right', 'top-left', 'top-center'
|
|
62
|
-
// 'bottom-right', 'bottom-left', 'bottom-center'
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Click Handlers
|
|
66
|
-
```typescript
|
|
67
|
-
// Execute action on click
|
|
68
|
-
notificationService.info('New message from John', {
|
|
69
|
-
onClick: () => {
|
|
70
|
-
console.log('Opening chat...');
|
|
71
|
-
openChat('john');
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Callback on close
|
|
76
|
-
notificationService.success('Changes saved', {
|
|
77
|
-
onClose: () => {
|
|
78
|
-
console.log('Notification closed');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### In a Component
|
|
84
|
-
```typescript
|
|
85
|
-
import { KimuComponent } from '../core/kimu-component';
|
|
86
|
-
import { KimuComponentElement } from '../core/kimu-component-element';
|
|
87
|
-
import { notificationService } from '../modules/notification/notification-service';
|
|
88
|
-
|
|
89
|
-
@KimuComponent({
|
|
90
|
-
tag: 'user-form',
|
|
91
|
-
name: 'User Form',
|
|
92
|
-
// ...
|
|
93
|
-
})
|
|
94
|
-
export class UserFormComponent extends KimuComponentElement {
|
|
95
|
-
|
|
96
|
-
async saveUser(userData: any) {
|
|
97
|
-
try {
|
|
98
|
-
await this.apiService.post('/users', userData);
|
|
99
|
-
|
|
100
|
-
// Show success notification
|
|
101
|
-
notificationService.success('User created successfully!', {
|
|
102
|
-
duration: 3000,
|
|
103
|
-
position: 'top-right'
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
this.resetForm();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
// Show error notification
|
|
109
|
-
notificationService.error('Failed to create user. Please try again.', {
|
|
110
|
-
duration: 5000,
|
|
111
|
-
dismissible: true
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
validateForm() {
|
|
117
|
-
if (!this.isValid) {
|
|
118
|
-
notificationService.warning('Please fill all required fields', {
|
|
119
|
-
duration: 4000
|
|
120
|
-
});
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
showInfo() {
|
|
127
|
-
notificationService.info('This form requires authentication', {
|
|
128
|
-
duration: 0, // Persistent
|
|
129
|
-
dismissible: true,
|
|
130
|
-
onClick: () => {
|
|
131
|
-
this.showLoginDialog();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Dismiss Notifications
|
|
139
|
-
```typescript
|
|
140
|
-
// Dismiss specific notification (returns ID)
|
|
141
|
-
const id = notificationService.success('Task completed');
|
|
142
|
-
notificationService.dismiss(id);
|
|
143
|
-
|
|
144
|
-
// Dismiss all notifications
|
|
145
|
-
notificationService.dismissAll();
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### Configuration
|
|
149
|
-
```typescript
|
|
150
|
-
// Set default duration (default: 3000ms)
|
|
151
|
-
notificationService.setDefaultDuration(5000);
|
|
152
|
-
|
|
153
|
-
// Set default position (default: 'top-right')
|
|
154
|
-
notificationService.setDefaultPosition('bottom-right');
|
|
155
|
-
|
|
156
|
-
// Set max visible notifications (default: 5)
|
|
157
|
-
notificationService.setMaxNotifications(3);
|
|
158
|
-
|
|
159
|
-
// Enable debug mode
|
|
160
|
-
notificationService.setDebugMode(true);
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### Custom Icons
|
|
164
|
-
```typescript
|
|
165
|
-
// Use custom emoji or icon
|
|
166
|
-
notificationService.success('Payment received', {
|
|
167
|
-
icon: '💰'
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
notificationService.info('New follower', {
|
|
171
|
-
icon: '👤'
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
notificationService.warning('Battery low', {
|
|
175
|
-
icon: '🔋'
|
|
176
|
-
});
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## API Reference
|
|
180
|
-
|
|
181
|
-
### `notificationService.success(message, options?)`
|
|
182
|
-
Show a success notification.
|
|
183
|
-
- **message**: `string` - Notification message
|
|
184
|
-
- **options**: `NotificationOptions` (optional)
|
|
185
|
-
- **Returns**: `string` - Notification ID
|
|
186
|
-
|
|
187
|
-
### `notificationService.error(message, options?)`
|
|
188
|
-
Show an error notification.
|
|
189
|
-
- **message**: `string` - Notification message
|
|
190
|
-
- **options**: `NotificationOptions` (optional)
|
|
191
|
-
- **Returns**: `string` - Notification ID
|
|
192
|
-
|
|
193
|
-
### `notificationService.warning(message, options?)`
|
|
194
|
-
Show a warning notification.
|
|
195
|
-
- **message**: `string` - Notification message
|
|
196
|
-
- **options**: `NotificationOptions` (optional)
|
|
197
|
-
- **Returns**: `string` - Notification ID
|
|
198
|
-
|
|
199
|
-
### `notificationService.info(message, options?)`
|
|
200
|
-
Show an info notification.
|
|
201
|
-
- **message**: `string` - Notification message
|
|
202
|
-
- **options**: `NotificationOptions` (optional)
|
|
203
|
-
- **Returns**: `string` - Notification ID
|
|
204
|
-
|
|
205
|
-
### `notificationService.show(message, options?)`
|
|
206
|
-
Show a notification with custom options.
|
|
207
|
-
- **message**: `string` - Notification message
|
|
208
|
-
- **options**: `NotificationOptions` (optional)
|
|
209
|
-
- **Returns**: `string` - Notification ID
|
|
210
|
-
|
|
211
|
-
### `notificationService.dismiss(id)`
|
|
212
|
-
Dismiss a specific notification.
|
|
213
|
-
- **id**: `string` - Notification ID
|
|
214
|
-
|
|
215
|
-
### `notificationService.dismissAll()`
|
|
216
|
-
Dismiss all active notifications.
|
|
217
|
-
|
|
218
|
-
### `notificationService.getAll()`
|
|
219
|
-
Get all active notifications.
|
|
220
|
-
- **Returns**: `Notification[]`
|
|
221
|
-
|
|
222
|
-
### `notificationService.getCount()`
|
|
223
|
-
Get count of active notifications.
|
|
224
|
-
- **Returns**: `number`
|
|
225
|
-
|
|
226
|
-
### Configuration Methods
|
|
227
|
-
|
|
228
|
-
### `notificationService.setDefaultDuration(duration)`
|
|
229
|
-
Set default notification duration.
|
|
230
|
-
- **duration**: `number` - Duration in milliseconds
|
|
231
|
-
|
|
232
|
-
### `notificationService.setDefaultPosition(position)`
|
|
233
|
-
Set default notification position.
|
|
234
|
-
- **position**: `NotificationPosition`
|
|
235
|
-
|
|
236
|
-
### `notificationService.setMaxNotifications(max)`
|
|
237
|
-
Set maximum visible notifications.
|
|
238
|
-
- **max**: `number`
|
|
239
|
-
|
|
240
|
-
### `notificationService.setDebugMode(enabled)`
|
|
241
|
-
Enable or disable debug logging.
|
|
242
|
-
- **enabled**: `boolean`
|
|
243
|
-
|
|
244
|
-
## NotificationOptions Interface
|
|
245
|
-
```typescript
|
|
246
|
-
interface NotificationOptions {
|
|
247
|
-
type?: 'success' | 'error' | 'warning' | 'info';
|
|
248
|
-
duration?: number; // milliseconds, 0 = no auto-dismiss
|
|
249
|
-
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
250
|
-
dismissible?: boolean; // show close button
|
|
251
|
-
icon?: string; // custom icon (emoji or HTML)
|
|
252
|
-
onClick?: () => void; // click handler
|
|
253
|
-
onClose?: () => void; // close callback
|
|
254
|
-
}
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## Styling
|
|
258
|
-
|
|
259
|
-
### Default Styles
|
|
260
|
-
The module includes built-in styles with smooth animations and responsive design. Notifications are styled based on their type:
|
|
261
|
-
- **Success**: Green accent with ✅ icon
|
|
262
|
-
- **Error**: Red accent with ❌ icon
|
|
263
|
-
- **Warning**: Orange accent with ⚠️ icon
|
|
264
|
-
- **Info**: Blue accent with ℹ️ icon
|
|
265
|
-
|
|
266
|
-
### Custom Styles
|
|
267
|
-
You can override default styles using CSS:
|
|
268
|
-
```css
|
|
269
|
-
/* Custom notification styling */
|
|
270
|
-
.kimu-notification {
|
|
271
|
-
border-radius: 12px;
|
|
272
|
-
font-family: 'Your Font', sans-serif;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
.kimu-notification-success {
|
|
276
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
277
|
-
color: white;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
.kimu-notification-message {
|
|
281
|
-
font-weight: bold;
|
|
282
|
-
}
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
## Best Practices
|
|
286
|
-
|
|
287
|
-
### 1. Use Appropriate Types
|
|
288
|
-
```typescript
|
|
289
|
-
// Success for completed actions
|
|
290
|
-
notificationService.success('Profile updated');
|
|
291
|
-
|
|
292
|
-
// Error for failures
|
|
293
|
-
notificationService.error('Network error');
|
|
294
|
-
|
|
295
|
-
// Warning for attention needed
|
|
296
|
-
notificationService.warning('Unsaved changes');
|
|
297
|
-
|
|
298
|
-
// Info for general messages
|
|
299
|
-
notificationService.info('New feature available');
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### 2. Keep Messages Concise
|
|
303
|
-
```typescript
|
|
304
|
-
// Good
|
|
305
|
-
notificationService.success('Changes saved');
|
|
306
|
-
|
|
307
|
-
// Too verbose
|
|
308
|
-
notificationService.success('Your changes have been successfully saved to the database and will be reflected immediately');
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### 3. Use Appropriate Durations
|
|
312
|
-
```typescript
|
|
313
|
-
// Quick confirmations (2-3 seconds)
|
|
314
|
-
notificationService.success('Copied to clipboard', { duration: 2000 });
|
|
315
|
-
|
|
316
|
-
// Errors (4-5 seconds)
|
|
317
|
-
notificationService.error('Invalid email format', { duration: 4000 });
|
|
318
|
-
|
|
319
|
-
// Important messages (persistent)
|
|
320
|
-
notificationService.warning('Session expiring soon', {
|
|
321
|
-
duration: 0,
|
|
322
|
-
dismissible: true
|
|
323
|
-
});
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
### 4. Provide Actions When Needed
|
|
327
|
-
```typescript
|
|
328
|
-
// Actionable notifications
|
|
329
|
-
notificationService.info('New message received', {
|
|
330
|
-
onClick: () => {
|
|
331
|
-
openMessages();
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
notificationService.error('Network error', {
|
|
336
|
-
onClick: () => {
|
|
337
|
-
retryConnection();
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
## Common Use Cases
|
|
343
|
-
|
|
344
|
-
### 1. Form Validation
|
|
345
|
-
```typescript
|
|
346
|
-
function validateAndSave() {
|
|
347
|
-
if (!form.isValid()) {
|
|
348
|
-
notificationService.error('Please fill all required fields');
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
saveForm();
|
|
353
|
-
notificationService.success('Form submitted successfully');
|
|
354
|
-
}
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
### 2. API Responses
|
|
358
|
-
```typescript
|
|
359
|
-
async function loadData() {
|
|
360
|
-
try {
|
|
361
|
-
const data = await api.get('/data');
|
|
362
|
-
notificationService.success('Data loaded successfully');
|
|
363
|
-
return data;
|
|
364
|
-
} catch (error) {
|
|
365
|
-
notificationService.error('Failed to load data. Please try again.');
|
|
366
|
-
throw error;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### 3. Background Tasks
|
|
372
|
-
```typescript
|
|
373
|
-
function startExport() {
|
|
374
|
-
notificationService.info('Export started...', { duration: 2000 });
|
|
375
|
-
|
|
376
|
-
exportData().then(() => {
|
|
377
|
-
notificationService.success('Export completed!', {
|
|
378
|
-
onClick: () => downloadFile()
|
|
379
|
-
});
|
|
380
|
-
}).catch(() => {
|
|
381
|
-
notificationService.error('Export failed');
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
### 4. User Actions
|
|
387
|
-
```typescript
|
|
388
|
-
function deleteItem() {
|
|
389
|
-
const id = notificationService.warning('This action cannot be undone', {
|
|
390
|
-
duration: 0,
|
|
391
|
-
dismissible: true
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
// Show confirmation UI
|
|
395
|
-
showConfirmDialog(() => {
|
|
396
|
-
notificationService.dismiss(id);
|
|
397
|
-
performDelete();
|
|
398
|
-
notificationService.success('Item deleted');
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
## Accessibility
|
|
404
|
-
- Notifications have proper ARIA labels
|
|
405
|
-
- Close buttons include aria-label="Close"
|
|
406
|
-
- Animations respect user preferences (prefers-reduced-motion)
|
|
407
|
-
- Keyboard accessible (Tab to close button, Enter to dismiss)
|
|
408
|
-
|
|
409
|
-
## Performance Considerations
|
|
410
|
-
- Maximum 5 notifications by default (configurable)
|
|
411
|
-
- Automatic cleanup of old notifications
|
|
412
|
-
- CSS-based animations for smooth performance
|
|
413
|
-
- Minimal DOM manipulation
|
|
414
|
-
|
|
415
|
-
## Browser Support
|
|
416
|
-
- Modern browsers with ES6+ support
|
|
417
|
-
- Chrome 60+, Firefox 60+, Safari 12+, Edge 79+
|
|
418
|
-
|
|
419
|
-
## License
|
|
420
|
-
This module is part of KIMU-Core and follows the same license (MPL-2.0).
|
|
421
|
-
|
|
422
|
-
## Version History
|
|
423
|
-
- **1.0.0** - Initial release with toast notifications
|
|
1
|
+
# Notification Module
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The Notification module provides a toast notification system for KIMU-Core applications. It supports different notification types (success, error, warning, info), customizable durations, positions, and styling.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
- ✅ **Multiple types** - Success, error, warning, info notifications
|
|
8
|
+
- ✅ **Customizable position** - 6 position options (top/bottom + left/center/right)
|
|
9
|
+
- ✅ **Auto-dismiss** - Configurable duration or persistent
|
|
10
|
+
- ✅ **Dismissible** - Optional close button
|
|
11
|
+
- ✅ **Click handlers** - Custom actions on click
|
|
12
|
+
- ✅ **Styled** - Beautiful, responsive design out-of-the-box
|
|
13
|
+
- ✅ **Max limit** - Prevents notification overflow
|
|
14
|
+
- ✅ **Animations** - Smooth enter/exit transitions
|
|
15
|
+
- ✅ **Debug mode** - Optional logging for development
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
The Notification module is included in KIMU-Core. No additional installation required.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Examples
|
|
23
|
+
```typescript
|
|
24
|
+
import { notificationService } from './modules/notification/notification-service';
|
|
25
|
+
|
|
26
|
+
// Success notification
|
|
27
|
+
notificationService.success('Profile updated successfully!');
|
|
28
|
+
|
|
29
|
+
// Error notification
|
|
30
|
+
notificationService.error('Failed to save changes');
|
|
31
|
+
|
|
32
|
+
// Warning notification
|
|
33
|
+
notificationService.warning('Your session will expire in 5 minutes');
|
|
34
|
+
|
|
35
|
+
// Info notification
|
|
36
|
+
notificationService.info('New message received');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Custom Duration
|
|
40
|
+
```typescript
|
|
41
|
+
// Show for 5 seconds
|
|
42
|
+
notificationService.success('Operation completed!', { duration: 5000 });
|
|
43
|
+
|
|
44
|
+
// Persistent (no auto-dismiss)
|
|
45
|
+
notificationService.info('Important message', { duration: 0 });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Custom Position
|
|
49
|
+
```typescript
|
|
50
|
+
// Bottom right
|
|
51
|
+
notificationService.info('Download complete', {
|
|
52
|
+
position: 'bottom-right'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Top center
|
|
56
|
+
notificationService.warning('Network connection lost', {
|
|
57
|
+
position: 'top-center'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Available positions:
|
|
61
|
+
// 'top-right', 'top-left', 'top-center'
|
|
62
|
+
// 'bottom-right', 'bottom-left', 'bottom-center'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Click Handlers
|
|
66
|
+
```typescript
|
|
67
|
+
// Execute action on click
|
|
68
|
+
notificationService.info('New message from John', {
|
|
69
|
+
onClick: () => {
|
|
70
|
+
console.log('Opening chat...');
|
|
71
|
+
openChat('john');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Callback on close
|
|
76
|
+
notificationService.success('Changes saved', {
|
|
77
|
+
onClose: () => {
|
|
78
|
+
console.log('Notification closed');
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### In a Component
|
|
84
|
+
```typescript
|
|
85
|
+
import { KimuComponent } from '../core/kimu-component';
|
|
86
|
+
import { KimuComponentElement } from '../core/kimu-component-element';
|
|
87
|
+
import { notificationService } from '../modules/notification/notification-service';
|
|
88
|
+
|
|
89
|
+
@KimuComponent({
|
|
90
|
+
tag: 'user-form',
|
|
91
|
+
name: 'User Form',
|
|
92
|
+
// ...
|
|
93
|
+
})
|
|
94
|
+
export class UserFormComponent extends KimuComponentElement {
|
|
95
|
+
|
|
96
|
+
async saveUser(userData: any) {
|
|
97
|
+
try {
|
|
98
|
+
await this.apiService.post('/users', userData);
|
|
99
|
+
|
|
100
|
+
// Show success notification
|
|
101
|
+
notificationService.success('User created successfully!', {
|
|
102
|
+
duration: 3000,
|
|
103
|
+
position: 'top-right'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this.resetForm();
|
|
107
|
+
} catch (error) {
|
|
108
|
+
// Show error notification
|
|
109
|
+
notificationService.error('Failed to create user. Please try again.', {
|
|
110
|
+
duration: 5000,
|
|
111
|
+
dismissible: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
validateForm() {
|
|
117
|
+
if (!this.isValid) {
|
|
118
|
+
notificationService.warning('Please fill all required fields', {
|
|
119
|
+
duration: 4000
|
|
120
|
+
});
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
showInfo() {
|
|
127
|
+
notificationService.info('This form requires authentication', {
|
|
128
|
+
duration: 0, // Persistent
|
|
129
|
+
dismissible: true,
|
|
130
|
+
onClick: () => {
|
|
131
|
+
this.showLoginDialog();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Dismiss Notifications
|
|
139
|
+
```typescript
|
|
140
|
+
// Dismiss specific notification (returns ID)
|
|
141
|
+
const id = notificationService.success('Task completed');
|
|
142
|
+
notificationService.dismiss(id);
|
|
143
|
+
|
|
144
|
+
// Dismiss all notifications
|
|
145
|
+
notificationService.dismissAll();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Configuration
|
|
149
|
+
```typescript
|
|
150
|
+
// Set default duration (default: 3000ms)
|
|
151
|
+
notificationService.setDefaultDuration(5000);
|
|
152
|
+
|
|
153
|
+
// Set default position (default: 'top-right')
|
|
154
|
+
notificationService.setDefaultPosition('bottom-right');
|
|
155
|
+
|
|
156
|
+
// Set max visible notifications (default: 5)
|
|
157
|
+
notificationService.setMaxNotifications(3);
|
|
158
|
+
|
|
159
|
+
// Enable debug mode
|
|
160
|
+
notificationService.setDebugMode(true);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Custom Icons
|
|
164
|
+
```typescript
|
|
165
|
+
// Use custom emoji or icon
|
|
166
|
+
notificationService.success('Payment received', {
|
|
167
|
+
icon: '💰'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
notificationService.info('New follower', {
|
|
171
|
+
icon: '👤'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
notificationService.warning('Battery low', {
|
|
175
|
+
icon: '🔋'
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## API Reference
|
|
180
|
+
|
|
181
|
+
### `notificationService.success(message, options?)`
|
|
182
|
+
Show a success notification.
|
|
183
|
+
- **message**: `string` - Notification message
|
|
184
|
+
- **options**: `NotificationOptions` (optional)
|
|
185
|
+
- **Returns**: `string` - Notification ID
|
|
186
|
+
|
|
187
|
+
### `notificationService.error(message, options?)`
|
|
188
|
+
Show an error notification.
|
|
189
|
+
- **message**: `string` - Notification message
|
|
190
|
+
- **options**: `NotificationOptions` (optional)
|
|
191
|
+
- **Returns**: `string` - Notification ID
|
|
192
|
+
|
|
193
|
+
### `notificationService.warning(message, options?)`
|
|
194
|
+
Show a warning notification.
|
|
195
|
+
- **message**: `string` - Notification message
|
|
196
|
+
- **options**: `NotificationOptions` (optional)
|
|
197
|
+
- **Returns**: `string` - Notification ID
|
|
198
|
+
|
|
199
|
+
### `notificationService.info(message, options?)`
|
|
200
|
+
Show an info notification.
|
|
201
|
+
- **message**: `string` - Notification message
|
|
202
|
+
- **options**: `NotificationOptions` (optional)
|
|
203
|
+
- **Returns**: `string` - Notification ID
|
|
204
|
+
|
|
205
|
+
### `notificationService.show(message, options?)`
|
|
206
|
+
Show a notification with custom options.
|
|
207
|
+
- **message**: `string` - Notification message
|
|
208
|
+
- **options**: `NotificationOptions` (optional)
|
|
209
|
+
- **Returns**: `string` - Notification ID
|
|
210
|
+
|
|
211
|
+
### `notificationService.dismiss(id)`
|
|
212
|
+
Dismiss a specific notification.
|
|
213
|
+
- **id**: `string` - Notification ID
|
|
214
|
+
|
|
215
|
+
### `notificationService.dismissAll()`
|
|
216
|
+
Dismiss all active notifications.
|
|
217
|
+
|
|
218
|
+
### `notificationService.getAll()`
|
|
219
|
+
Get all active notifications.
|
|
220
|
+
- **Returns**: `Notification[]`
|
|
221
|
+
|
|
222
|
+
### `notificationService.getCount()`
|
|
223
|
+
Get count of active notifications.
|
|
224
|
+
- **Returns**: `number`
|
|
225
|
+
|
|
226
|
+
### Configuration Methods
|
|
227
|
+
|
|
228
|
+
### `notificationService.setDefaultDuration(duration)`
|
|
229
|
+
Set default notification duration.
|
|
230
|
+
- **duration**: `number` - Duration in milliseconds
|
|
231
|
+
|
|
232
|
+
### `notificationService.setDefaultPosition(position)`
|
|
233
|
+
Set default notification position.
|
|
234
|
+
- **position**: `NotificationPosition`
|
|
235
|
+
|
|
236
|
+
### `notificationService.setMaxNotifications(max)`
|
|
237
|
+
Set maximum visible notifications.
|
|
238
|
+
- **max**: `number`
|
|
239
|
+
|
|
240
|
+
### `notificationService.setDebugMode(enabled)`
|
|
241
|
+
Enable or disable debug logging.
|
|
242
|
+
- **enabled**: `boolean`
|
|
243
|
+
|
|
244
|
+
## NotificationOptions Interface
|
|
245
|
+
```typescript
|
|
246
|
+
interface NotificationOptions {
|
|
247
|
+
type?: 'success' | 'error' | 'warning' | 'info';
|
|
248
|
+
duration?: number; // milliseconds, 0 = no auto-dismiss
|
|
249
|
+
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
250
|
+
dismissible?: boolean; // show close button
|
|
251
|
+
icon?: string; // custom icon (emoji or HTML)
|
|
252
|
+
onClick?: () => void; // click handler
|
|
253
|
+
onClose?: () => void; // close callback
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Styling
|
|
258
|
+
|
|
259
|
+
### Default Styles
|
|
260
|
+
The module includes built-in styles with smooth animations and responsive design. Notifications are styled based on their type:
|
|
261
|
+
- **Success**: Green accent with ✅ icon
|
|
262
|
+
- **Error**: Red accent with ❌ icon
|
|
263
|
+
- **Warning**: Orange accent with ⚠️ icon
|
|
264
|
+
- **Info**: Blue accent with ℹ️ icon
|
|
265
|
+
|
|
266
|
+
### Custom Styles
|
|
267
|
+
You can override default styles using CSS:
|
|
268
|
+
```css
|
|
269
|
+
/* Custom notification styling */
|
|
270
|
+
.kimu-notification {
|
|
271
|
+
border-radius: 12px;
|
|
272
|
+
font-family: 'Your Font', sans-serif;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.kimu-notification-success {
|
|
276
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
277
|
+
color: white;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.kimu-notification-message {
|
|
281
|
+
font-weight: bold;
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Best Practices
|
|
286
|
+
|
|
287
|
+
### 1. Use Appropriate Types
|
|
288
|
+
```typescript
|
|
289
|
+
// Success for completed actions
|
|
290
|
+
notificationService.success('Profile updated');
|
|
291
|
+
|
|
292
|
+
// Error for failures
|
|
293
|
+
notificationService.error('Network error');
|
|
294
|
+
|
|
295
|
+
// Warning for attention needed
|
|
296
|
+
notificationService.warning('Unsaved changes');
|
|
297
|
+
|
|
298
|
+
// Info for general messages
|
|
299
|
+
notificationService.info('New feature available');
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 2. Keep Messages Concise
|
|
303
|
+
```typescript
|
|
304
|
+
// Good
|
|
305
|
+
notificationService.success('Changes saved');
|
|
306
|
+
|
|
307
|
+
// Too verbose
|
|
308
|
+
notificationService.success('Your changes have been successfully saved to the database and will be reflected immediately');
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 3. Use Appropriate Durations
|
|
312
|
+
```typescript
|
|
313
|
+
// Quick confirmations (2-3 seconds)
|
|
314
|
+
notificationService.success('Copied to clipboard', { duration: 2000 });
|
|
315
|
+
|
|
316
|
+
// Errors (4-5 seconds)
|
|
317
|
+
notificationService.error('Invalid email format', { duration: 4000 });
|
|
318
|
+
|
|
319
|
+
// Important messages (persistent)
|
|
320
|
+
notificationService.warning('Session expiring soon', {
|
|
321
|
+
duration: 0,
|
|
322
|
+
dismissible: true
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### 4. Provide Actions When Needed
|
|
327
|
+
```typescript
|
|
328
|
+
// Actionable notifications
|
|
329
|
+
notificationService.info('New message received', {
|
|
330
|
+
onClick: () => {
|
|
331
|
+
openMessages();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
notificationService.error('Network error', {
|
|
336
|
+
onClick: () => {
|
|
337
|
+
retryConnection();
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Common Use Cases
|
|
343
|
+
|
|
344
|
+
### 1. Form Validation
|
|
345
|
+
```typescript
|
|
346
|
+
function validateAndSave() {
|
|
347
|
+
if (!form.isValid()) {
|
|
348
|
+
notificationService.error('Please fill all required fields');
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
saveForm();
|
|
353
|
+
notificationService.success('Form submitted successfully');
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### 2. API Responses
|
|
358
|
+
```typescript
|
|
359
|
+
async function loadData() {
|
|
360
|
+
try {
|
|
361
|
+
const data = await api.get('/data');
|
|
362
|
+
notificationService.success('Data loaded successfully');
|
|
363
|
+
return data;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
notificationService.error('Failed to load data. Please try again.');
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### 3. Background Tasks
|
|
372
|
+
```typescript
|
|
373
|
+
function startExport() {
|
|
374
|
+
notificationService.info('Export started...', { duration: 2000 });
|
|
375
|
+
|
|
376
|
+
exportData().then(() => {
|
|
377
|
+
notificationService.success('Export completed!', {
|
|
378
|
+
onClick: () => downloadFile()
|
|
379
|
+
});
|
|
380
|
+
}).catch(() => {
|
|
381
|
+
notificationService.error('Export failed');
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### 4. User Actions
|
|
387
|
+
```typescript
|
|
388
|
+
function deleteItem() {
|
|
389
|
+
const id = notificationService.warning('This action cannot be undone', {
|
|
390
|
+
duration: 0,
|
|
391
|
+
dismissible: true
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// Show confirmation UI
|
|
395
|
+
showConfirmDialog(() => {
|
|
396
|
+
notificationService.dismiss(id);
|
|
397
|
+
performDelete();
|
|
398
|
+
notificationService.success('Item deleted');
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Accessibility
|
|
404
|
+
- Notifications have proper ARIA labels
|
|
405
|
+
- Close buttons include aria-label="Close"
|
|
406
|
+
- Animations respect user preferences (prefers-reduced-motion)
|
|
407
|
+
- Keyboard accessible (Tab to close button, Enter to dismiss)
|
|
408
|
+
|
|
409
|
+
## Performance Considerations
|
|
410
|
+
- Maximum 5 notifications by default (configurable)
|
|
411
|
+
- Automatic cleanup of old notifications
|
|
412
|
+
- CSS-based animations for smooth performance
|
|
413
|
+
- Minimal DOM manipulation
|
|
414
|
+
|
|
415
|
+
## Browser Support
|
|
416
|
+
- Modern browsers with ES6+ support
|
|
417
|
+
- Chrome 60+, Firefox 60+, Safari 12+, Edge 79+
|
|
418
|
+
|
|
419
|
+
## License
|
|
420
|
+
This module is part of KIMU-Core and follows the same license (MPL-2.0).
|
|
421
|
+
|
|
422
|
+
## Version History
|
|
423
|
+
- **1.0.0** - Initial release with toast notifications
|