better-toast 0.0.1

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 ADDED
@@ -0,0 +1,94 @@
1
+ # better-toast
2
+
3
+ Toast notifications for **Angular** (standalone components): stacked messages, variants, swipe-to-dismiss, accessibility-friendly live region, and a small `ToasterService` API.
4
+
5
+ **Requirements:** Angular `^21.0.0` (`@angular/core`, `@angular/common`).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install better-toast
11
+ ```
12
+
13
+ ## Add the toaster once
14
+
15
+ Place a single `<better-toaster>` near the root of your app (for example in the root component) so the stack can render.
16
+
17
+ ```typescript
18
+ import { Component } from '@angular/core';
19
+ import { BetterToaster } from 'better-toast';
20
+
21
+ @Component({
22
+ selector: 'app-root',
23
+ imports: [BetterToaster],
24
+ template: `<better-toaster position="bottom-right" />`,
25
+ })
26
+ export class App {}
27
+ ```
28
+
29
+ Common inputs (all optional except using defaults):
30
+
31
+ | Input | Description |
32
+ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
33
+ | `duration` | Default auto-dismiss in ms for toasts that omit `durationMs` (also supports the literal `duration="Infinity"` for manual dismiss). |
34
+ | `position` | `top-left` \| `top-center` \| `top-right` \| `bottom-left` \| `bottom-center` \| `bottom-right` (default `bottom-right`). |
35
+ | `richColors` | When `true`, semantic background/border colors for success/error/info/warning. |
36
+ | `theme` | `light` \| `dark` \| `system` (default). |
37
+ | `closeButton` | Show per-toast dismiss control (default `true`). |
38
+ | `offset` / `mobileOffset` | Viewport inset for the stack (string or per-side object). |
39
+
40
+ Styles ship with the components; you do not need to import a separate CSS file for the default look.
41
+
42
+ ## Show toasts from anywhere
43
+
44
+ Inject `ToasterService` (`providedIn: 'root'`) and call the helpers. Each method returns a **toast id** you can pass to `dismiss(id)`.
45
+
46
+ ```typescript
47
+ import { Component, inject } from '@angular/core';
48
+ import { ToasterService } from 'better-toast';
49
+
50
+ @Component({
51
+ selector: 'app-example',
52
+ template: `<button type="button" (click)="notify()">Save</button>`,
53
+ })
54
+ export class ExampleComponent {
55
+ private readonly toaster = inject(ToasterService);
56
+
57
+ notify(): void {
58
+ this.toaster.success('Saved successfully');
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Variants and helpers
64
+
65
+ - **Text:** `show`, `description`, `success`, `error`, `info`, `warning`, `loading`
66
+ - **Actions:** `action(message, { action: { label, onClick } })`, `cancel(message, { cancel: { label, onClick } })`
67
+ - **Custom UI:** `custom(Component, options)` (message area as a component), `headless(Component, options)` (full custom body, minimal chrome)
68
+ - **Async:** `promise(userPromise, { loading, success, error })` — one toast goes from loading → success/error
69
+ - **Control:** `dismiss(id)`, `clear()`
70
+
71
+ Example with options:
72
+
73
+ ```typescript
74
+ this.toaster.error('Something went wrong', {
75
+ description: 'Try again in a few minutes.',
76
+ durationMs: 6000,
77
+ });
78
+
79
+ const id = this.toaster.loading('Working…');
80
+ // later:
81
+ this.toaster.dismiss(id);
82
+ ```
83
+
84
+ Constants re-exported for typing and defaults include `DEFAULT_TOAST_DURATION_MS`, `TOAST_DURATION_MANUAL_DISMISS`, `TOAST_VARIANTS`, `TOASTER_POSITIONS`, and default ARIA label helpers.
85
+
86
+ ## API surface
87
+
88
+ Everything is exported from the package entry point `better-toast`:
89
+
90
+ - **Component:** `BetterToaster` (selector `better-toaster`)
91
+ - **Service:** `ToasterService`
92
+ - **Types:** `ToastOptions`, `ToastVariant`, `ToasterPosition`, and the other types listed in the package’s `public-api.ts`
93
+
94
+ For full behavior (icons, headless mode, class names, accessibility labels), see the source and TSDoc under `projects/better-toast/src`.