ngx-dynamic-toast 0.0.5 → 0.0.11

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/README.md CHANGED
@@ -1,55 +1,262 @@
1
1
  # ngx-dynamic-toast
2
2
 
3
- An elegant, liquid-smooth toast notification library for Angular, heavily inspired by the beautiful [Sileo](https://github.com/hiaaryan/sileo) project. This is an attempt to port its fluid animations and API to the Angular ecosystem.
3
+ An elegant, liquid-smooth notification library for Angular featuring spring-physics transitions and interactive Dynamic Island anchoring. Heavily inspired by the premium aesthetics of the [Sileo](https://github.com/hiaaryan/sileo) project, bringing fluid motion and state-swapping interfaces to the Angular ecosystem.
4
4
 
5
- ## Credits & Inspiration
5
+ ## Key Features
6
+
7
+ - **Liquid-Smooth Physics**: Powered by spring animations (`motion`), producing natural, elastic card expansions and fluid transformations.
8
+ - **Dynamic Island Anchoring**: Bind notifications to specific DOM elements (buttons, inputs, status indicators) using a declarative directive. The notification expands directly from and around the element.
9
+ - **Stateful Upgrades**: Instantly morph a loading toast into a success or error notification with gorgeous crossfade layer swaps.
10
+ - **System-Aware Theme Engine**: Seamlessly switch between Light, Dark, and System-preferred styles.
11
+ - **Developer-Centric DX**: Injectable service with complete type-safety.
6
12
 
7
- The original concept, design, CSS animations (including the gooey SVG filter), and API structure are credited to **Aryan Hia** and the amazing work on the [Sileo](https://github.com/hiaaryan/sileo) repository. This package aims to bring that precise aesthetic and DX (Developer Experience) to Angular developers.
13
+ ---
8
14
 
9
15
  ## Installation
10
16
 
17
+ Install the package via npm along with its motion animation peer dependency:
18
+
11
19
  ```bash
12
- npm install ngx-dynamic-toast
20
+ npm install ngx-dynamic-toast motion
21
+ ```
22
+
23
+ Add the global styles to your application's stylesheet configuration (e.g. `styles.css` or `angular.json` styles array):
24
+
25
+ ```css
26
+ @import "ngx-dynamic-toast/styles.css";
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Setup & Initialization
32
+
33
+ Ensure the viewport component is present at your application's root template (typically `app.component.html`), and inject the global viewport styles.
34
+
35
+ ### 1. Configure the Viewport in `app.component.ts`
36
+
37
+ ```typescript
38
+ import { Component } from '@angular/core';
39
+ import { DynamicToastViewportComponent } from 'ngx-dynamic-toast';
40
+
41
+ @Component({
42
+ selector: 'app-root',
43
+ standalone: true,
44
+ imports: [DynamicToastViewportComponent],
45
+ template: `
46
+ <div class="main-layout">
47
+ <!-- Your application route or contents -->
48
+ </div>
49
+
50
+ <!-- Global Toast Viewport -->
51
+ <dt-viewport
52
+ theme="system"
53
+ position="top-right"
54
+ [offset]="{ top: '16px', right: '16px' }">
55
+ </dt-viewport>
56
+ `
57
+ })
58
+ export class AppComponent {}
13
59
  ```
14
60
 
61
+ ### 2. Global Configuration via Dependency Injection Providers
62
+
63
+ You can configure global settings (such as theme, position, default durations, etc.) during application bootstrap using the `provideDynamicToast` provider function in your `app.config.ts`:
64
+
65
+ ```typescript
66
+ import { ApplicationConfig } from '@angular/core';
67
+ import { provideDynamicToast } from 'ngx-dynamic-toast';
68
+
69
+ export const appConfig: ApplicationConfig = {
70
+ providers: [
71
+ // Configure default properties globally
72
+ provideDynamicToast({
73
+ theme: 'system',
74
+ position: 'top-right',
75
+ offset: { top: '24px', right: '24px' }
76
+ })
77
+ ]
78
+ };
79
+ ```
80
+
81
+ ---
82
+
15
83
  ## Basic Usage
16
84
 
17
- Inject the `DynamicToastService` into your component and start firing toasts!
85
+ Inject the `DynamicToastService` inside any component or service to trigger generic notifications.
86
+
87
+ ```typescript
88
+ import { Component, inject } from '@angular/core';
89
+ import { DynamicToastService } from 'ngx-dynamic-toast';
90
+
91
+ @Component({
92
+ selector: 'app-telemetry-trigger',
93
+ standalone: true,
94
+ template: `<button (click)="notifySync()">Sync Database</button>`
95
+ })
96
+ export class TelemetryTriggerComponent {
97
+ private toast = inject(DynamicToastService);
98
+
99
+ notifySync() {
100
+ this.toast.success('Database sync complete', {
101
+ description: 'All local transactions successfully synchronized with replica-us-east.',
102
+ duration: 4000
103
+ });
104
+ }
105
+ }
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Advanced Usage
18
111
 
19
- ```ts
20
- import { Component, inject } from "@angular/core";
21
- import { DynamicToastService } from "ngx-dynamic-toast";
112
+ ### 1. Stateful Async Loading & Upgrading
113
+
114
+ Launch a persistent loading toast and programmatically morph it upon resolution:
115
+
116
+ ```typescript
117
+ import { Component, inject } from '@angular/core';
118
+ import { DynamicToastService } from 'ngx-dynamic-toast';
119
+
120
+ @Component({
121
+ selector: 'app-bundle-compiler',
122
+ standalone: true,
123
+ template: `<button (click)="compileBundle()">Compile Bundle</button>`
124
+ })
125
+ export class BundleCompilerComponent {
126
+ private toast = inject(DynamicToastService);
127
+
128
+ compileBundle() {
129
+ // 1. Trigger the persistent loading status
130
+ const toastId = this.toast.loading('Compiling bundle...', {
131
+ description: 'Optimizing modules (48%)'
132
+ });
133
+
134
+ // 2. Perform long-running asynchronous logic
135
+ setTimeout(() => {
136
+ // 3. Upgrade the toast directly to success
137
+ this.toast.update(toastId, {
138
+ state: 'success',
139
+ title: 'Bundle compiled',
140
+ description: 'Production build complete. Output size is 142KB.',
141
+ duration: 3000
142
+ });
143
+ }, 2000);
144
+ }
145
+ }
146
+ ```
147
+
148
+ ### 2. Dynamic Island Anchors
149
+
150
+ Warp notifications directly around specific interactive DOM elements. The target element remains perfectly nested and interactive inside the expanding card:
151
+
152
+ ```typescript
153
+ import { Component, inject } from '@angular/core';
154
+ import { DynamicToastService, DynamicIslandDirective } from 'ngx-dynamic-toast';
22
155
 
23
156
  @Component({
24
- selector: "app-root",
157
+ selector: 'app-secure-vault',
25
158
  standalone: true,
159
+ imports: [DynamicIslandDirective],
26
160
  template: `
27
- <button (click)="showToast()">Show Toast</button>
28
- <dt-viewport></dt-viewport>
161
+ <!-- Bind directive with a unique identifier -->
162
+ <div dtDynamicIsland dtIslandId="vault-anchor" class="anchor-container">
163
+ <button (click)="saveConfigurations()">Save System Config</button>
164
+ </div>
29
165
  `,
166
+ styles: [`
167
+ .anchor-container {
168
+ display: inline-block;
169
+ position: relative; /* Stacking context wrapper for island anchors */
170
+ }
171
+ `]
30
172
  })
31
- export class AppComponent {
32
- private toastService = inject(DynamicToastService);
173
+ export class SecureVaultComponent {
174
+ private toast = inject(DynamicToastService);
33
175
 
34
- showToast() {
35
- this.toastService.success({
36
- title: "Hello World!",
37
- description: "This is a beautifully animated toast notification.",
176
+ saveConfigurations() {
177
+ const toastId = this.toast.loading('Saving details...', {
178
+ anchorId: 'vault-anchor',
179
+ duration: 999999
38
180
  });
181
+
182
+ setTimeout(() => {
183
+ this.toast.update(toastId, {
184
+ state: 'success',
185
+ title: 'Configurations saved',
186
+ description: 'Global system variables written to cloud vault.',
187
+ duration: 2500
188
+ });
189
+ }, 2000);
39
190
  }
40
191
  }
41
192
  ```
42
193
 
43
- ## Advanced Examples
44
194
 
45
- Check out the [examples/example-usage.component.ts](examples/example-usage.component.ts) file for a complete demonstration of:
195
+ ---
196
+
197
+ ## Dismissing & Interaction
198
+
199
+ `ngx-dynamic-toast` provides multiple intuitive options to dismiss or interact with active notifications:
200
+
201
+ 1. **Hover to Reveal Close (X) Button**: Hovering over an active toast smoothly fades in a micro-close `X` icon on the right side of the pill. Clicking this button immediately dismisses the toast.
202
+ 2. **Elastic Swipe Gestures**: You can drag or flick any toast up or down using touch/pointer controls. Swiping past a threshold of `30px` triggers an elastic dismissal animation.
203
+ 3. **Tactile Click Feedback**: Standard click actions on the toast trigger a subtle iOS-style `:active` scaling press feedback (`0.97` scale) to confirm the user's action before dismissal.
204
+
205
+ ---
206
+
207
+ ## API Reference
208
+
209
+ ### `DynamicToastService`
210
+
211
+ | Method | Signature | Description |
212
+ | :--- | :--- | :--- |
213
+ | `success(title, options?)` | `string` | Fires a success notification |
214
+ | `error(title, options?)` | `string` | Fires an error notification |
215
+ | `info(title, options?)` | `string` | Fires an information notification |
216
+ | `warning(title, options?)` | `string` | Fires a warning notification |
217
+ | `loading(title, options?)` | `string` | Fires a persistent loading notification |
218
+ | `show(config)` | `string` | Fires a custom notification based on full config state |
219
+ | `update(id, config)` | `void` | Transitions an existing notification to a new state |
220
+ | `dismiss(id)` | `void` | Dismisses a specific notification |
221
+ | `clear()` | `void` | Dismisses all active notifications |
222
+
223
+ ### `DynamicToastOptions`
224
+
225
+ ```typescript
226
+ export interface DynamicToastOptions {
227
+ description?: string;
228
+ duration?: number; // ms
229
+ anchorId?: string; // Target Dynamic Island anchor ID
230
+ button?: {
231
+ title: string;
232
+ onClick: () => void;
233
+ };
234
+ }
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Design Customization
240
+
241
+ The layout leverages CSS custom properties for effortless theme integration. You can overwrite these variables globally:
242
+
243
+ ```css
244
+ :root {
245
+ --dt-font-sans: 'Inter', sans-serif;
246
+ --dt-radius-pill: 16px;
247
+ --dt-color-success: #10b981;
248
+ --dt-color-error: #ef4444;
249
+ --dt-color-info: #06b6d4;
250
+ --dt-color-warning: #f59e0b;
251
+ }
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Credits & Inspiration
46
257
 
47
- - Success, Error, Warning, and Info toasts.
48
- - Toasts with action buttons.
49
- - Promise-based toasts (loading -> success/error).
50
- - Different viewport positions.
51
- - Custom durations and styling.
258
+ The original concept, styling formulas, custom SVG gooey filter transitions, and API architectures are credited to **Aryan Hia** and the amazing work on the [Sileo](https://github.com/hiaaryan/sileo) project. This library brings that precise level of UI engineering and developer experience to Angular.
52
259
 
53
260
  ## License
54
261
 
55
- MIT - See the Sileo repository for original conceptual licensing.
262
+ This project is licensed under the MIT License.