@nanahoshi/mona-ui 0.25.0 → 0.26.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/README.md +2 -0
- package/command/package.json +4 -0
- package/docs/auto-complete.md +733 -0
- package/docs/avatar.md +220 -0
- package/docs/breadcrumb.md +320 -0
- package/docs/button-group.md +392 -0
- package/docs/button.md +256 -0
- package/docs/calendar.md +515 -0
- package/docs/card.md +292 -0
- package/docs/chart.md +4058 -0
- package/docs/checkbox.md +374 -0
- package/docs/chip.md +339 -0
- package/docs/circular-progress-bar.md +287 -0
- package/docs/collapsible.md +308 -0
- package/docs/color-gradient.md +336 -0
- package/docs/color-palette.md +317 -0
- package/docs/color-picker.md +387 -0
- package/docs/combo-box.md +764 -0
- package/docs/command.md +582 -0
- package/docs/contextmenu.md +530 -0
- package/docs/date-picker.md +251 -0
- package/docs/datetime-picker.md +284 -0
- package/docs/decimal-textbox.md +260 -0
- package/docs/dialog.md +822 -0
- package/docs/dropdown-button.md +507 -0
- package/docs/dropdown-list.md +779 -0
- package/docs/editor.md +374 -0
- package/docs/expansion-panel.md +348 -0
- package/docs/fieldset.md +217 -0
- package/docs/forms.md +162 -0
- package/docs/grid.md +2053 -0
- package/docs/input.md +197 -0
- package/docs/installation.md +54 -0
- package/docs/introduction.md +46 -0
- package/docs/label.md +340 -0
- package/docs/list-box.md +637 -0
- package/docs/list-view.md +584 -0
- package/docs/menubar.md +559 -0
- package/docs/multi-select.md +765 -0
- package/docs/notification.md +460 -0
- package/docs/numeric-textbox.md +301 -0
- package/docs/otp-input.md +539 -0
- package/docs/pager.md +513 -0
- package/docs/placeholder.md +176 -0
- package/docs/popover.md +423 -0
- package/docs/popup-menu.md +658 -0
- package/docs/popup.md +617 -0
- package/docs/progress-bar.md +368 -0
- package/docs/radio-button.md +451 -0
- package/docs/range-slider.md +367 -0
- package/docs/rating.md +518 -0
- package/docs/scroll-view.md +375 -0
- package/docs/segmented.md +434 -0
- package/docs/sheet.md +348 -0
- package/docs/sidebar.md +1126 -0
- package/docs/skeleton.md +181 -0
- package/docs/slider.md +423 -0
- package/docs/spinner.md +370 -0
- package/docs/split-button.md +522 -0
- package/docs/splitter.md +342 -0
- package/docs/stepper.md +539 -0
- package/docs/switch.md +340 -0
- package/docs/tabs.md +542 -0
- package/docs/textarea.md +196 -0
- package/docs/textbox.md +332 -0
- package/docs/theming.md +403 -0
- package/docs/time-picker.md +254 -0
- package/docs/tooltip-directive.md +340 -0
- package/docs/tooltip.md +321 -0
- package/docs/tree-view.md +1018 -0
- package/docs/window.md +663 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +8 -0
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-button.mjs +14 -2
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +108 -22
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-chip.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +16 -2
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-command.mjs +924 -0
- package/fesm2022/nanahoshi-mona-ui-common.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +10 -6
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +55 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +13 -0
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +5 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs → nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs → nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs} +18 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs} +4653 -4529
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +168 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +19 -1
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +14 -0
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +32 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +15 -8
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +8 -5
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +14 -6
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +48 -183
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +7 -3
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +8 -3
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +10 -7
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +18 -21
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +11 -8
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +9 -1
- package/fesm2022/nanahoshi-mona-ui-theme.mjs +53 -21
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +16 -5
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +13 -11
- package/fesm2022/nanahoshi-mona-ui-window.mjs +12 -5
- package/i18n/catalogs/en-US.messages.json +10 -0
- package/internal/popup-menu/package.json +4 -0
- package/llms.txt +123 -0
- package/locales/ar-sa/ar-sa.messages.json +10 -0
- package/locales/de-de/de-de.messages.json +10 -0
- package/locales/es-es/es-es.messages.json +10 -0
- package/locales/fr-fr/fr-fr.messages.json +10 -0
- package/locales/id-id/id-id.messages.json +10 -0
- package/locales/it-it/it-it.messages.json +10 -0
- package/locales/ja-jp/ja-jp.messages.json +10 -0
- package/locales/ko-kr/ko-kr.messages.json +10 -0
- package/locales/pt-br/pt-br.messages.json +10 -0
- package/locales/ru-ru/ru-ru.messages.json +10 -0
- package/locales/tr-tr/tr-tr.messages.json +10 -0
- package/locales/zh-cn/zh-cn.messages.json +10 -0
- package/locales/zh-tw/zh-tw.messages.json +10 -0
- package/package.json +9 -1
- package/styles.css +12 -2
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +8 -0
- package/types/nanahoshi-mona-ui-button.d.ts +12 -0
- package/types/nanahoshi-mona-ui-calendar.d.ts +3 -0
- package/types/nanahoshi-mona-ui-chart.d.ts +200 -0
- package/types/nanahoshi-mona-ui-check-box.d.ts +4 -0
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-collapsible.d.ts +10 -0
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-command.d.ts +253 -0
- package/types/nanahoshi-mona-ui-common.d.ts +17 -1
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-dialog.d.ts +58 -1
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +7 -3
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +55 -1
- package/types/nanahoshi-mona-ui-editor.d.ts +31 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +13 -0
- package/types/nanahoshi-mona-ui-fieldset.d.ts +5 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +162 -35
- package/types/nanahoshi-mona-ui-i18n.d.ts +144 -1
- package/types/nanahoshi-mona-ui-internal-list.d.ts +16 -1
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +165 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +21 -2
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -5
- package/types/nanahoshi-mona-ui-label.d.ts +1 -0
- package/types/nanahoshi-mona-ui-list-box.d.ts +27 -4
- package/types/nanahoshi-mona-ui-list-view.d.ts +34 -1
- package/types/nanahoshi-mona-ui-list.d.ts +1 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +10 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +10 -3
- package/types/nanahoshi-mona-ui-multi-select.d.ts +3 -3
- package/types/nanahoshi-mona-ui-notification.d.ts +9 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
- package/types/nanahoshi-mona-ui-pager.d.ts +5 -1
- package/types/nanahoshi-mona-ui-popover.d.ts +9 -1
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +48 -161
- package/types/nanahoshi-mona-ui-popup.d.ts +16 -0
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-rating.d.ts +2 -0
- package/types/nanahoshi-mona-ui-segmented.d.ts +1 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +2 -0
- package/types/nanahoshi-mona-ui-spinner.d.ts +7 -0
- package/types/nanahoshi-mona-ui-split-button.d.ts +7 -4
- package/types/nanahoshi-mona-ui-stepper.d.ts +11 -2
- package/types/nanahoshi-mona-ui-tabs.d.ts +4 -1
- package/types/nanahoshi-mona-ui-text-box.d.ts +9 -1
- package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-tooltip.d.ts +10 -2
- package/types/nanahoshi-mona-ui-tree-view.d.ts +6 -5
- package/types/nanahoshi-mona-ui-window.d.ts +66 -1
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
# Notification
|
|
2
|
+
|
|
3
|
+
> Transient toast notifications with optional auto-dismiss.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/notification`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-notification`
|
|
8
|
+
|
|
9
|
+
`NotificationService` shows transient, positioned toast notifications with optional auto-dismiss and a progress bar.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Notifications are shown imperatively through `NotificationService`, not by placing `<mona-notification>` directly in a template. The service dynamically creates a `mona-notification-container` (one per screen `position`) and mounts each notification inside it.
|
|
14
|
+
|
|
15
|
+
**Use `NotificationService` when you need to:**
|
|
16
|
+
|
|
17
|
+
- Show a transient toast message in response to an action (save success, validation error, background task completion)
|
|
18
|
+
- Auto-dismiss a message after a delay, optionally with a visible countdown
|
|
19
|
+
- Render custom content (a string, an `ng-template`, or an arbitrary component) inside a notification
|
|
20
|
+
|
|
21
|
+
**Use a closely related Mona UI component instead when:**
|
|
22
|
+
|
|
23
|
+
- The message must remain visible and interactive indefinitely as part of the page layout — use an inline alert/banner instead. Notification is only for transient, dismissible messages.
|
|
24
|
+
- You need a modal, focus-trapping interruption — use `Dialog` or `Window`. Notification is non-modal and never takes focus when it appears.
|
|
25
|
+
|
|
26
|
+
## Import & Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { NotificationService } from "@nanahoshi/mona-ui/notification";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Inject `NotificationService` (it is `providedIn: "root"`, so no module setup is required) and call `show()`:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
export class MyComponent {
|
|
36
|
+
readonly #notificationService = inject(NotificationService);
|
|
37
|
+
|
|
38
|
+
save(): void {
|
|
39
|
+
this.#notificationService.show({
|
|
40
|
+
type: "success",
|
|
41
|
+
content: "Your changes have been saved.",
|
|
42
|
+
duration: 4000,
|
|
43
|
+
progressBar: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### NotificationService
|
|
50
|
+
|
|
51
|
+
`NotificationService` is the entire public surface consumers interact with directly — there is no notification component to place in a template. It is a root-provided (`providedIn: "root"`) singleton, so a single instance manages every notification across the application, grouped by screen `position`.
|
|
52
|
+
|
|
53
|
+
| Method | Description |
|
|
54
|
+
|-------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
55
|
+
| `hide(id: string): void` | Closes the notification with the given `id`, wherever its container is positioned. No-op if no notification with that `id` is currently shown. |
|
|
56
|
+
| `hideAll(): void` | Closes every currently visible notification, across all positions. |
|
|
57
|
+
| `show(options: NotificationOptions): NotificationRef` | Creates a notification and returns a `NotificationRef`. If a notification with the same `id` already exists at the resolved `position`, returns a ref to that existing notification instead of creating a duplicate. |
|
|
58
|
+
|
|
59
|
+
See [Anatomy & Options Resolution](#anatomy) for how `show()` fills in defaults, and [API](#api) for the full `NotificationOptions` / `NotificationRef` shapes.
|
|
60
|
+
|
|
61
|
+
## Anatomy
|
|
62
|
+
|
|
63
|
+
`show()` resolves defaults before creating the notification:
|
|
64
|
+
|
|
65
|
+
| Option | Resolved default when omitted |
|
|
66
|
+
|------------|--------------------------------------------------------------------------|
|
|
67
|
+
| `id` | A generated identifier |
|
|
68
|
+
| `position` | `"topright"` |
|
|
69
|
+
| `type` | `"info"` |
|
|
70
|
+
| `title` | Derived from `type` (e.g. `"Info"`, `"Success"`, `"Warning"`, `"Error"`) |
|
|
71
|
+
| `closable` | `true`, for timed notifications too — see [Dismissal](#dismissal) |
|
|
72
|
+
|
|
73
|
+
`show()` does not mutate the `options` object passed to it.
|
|
74
|
+
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
### Types
|
|
78
|
+
|
|
79
|
+
`type` sets the icon, the color and how urgently the notification is announced. These close after 5 seconds and show a countdown bar.
|
|
80
|
+
|
|
81
|
+
`types-example.component.ts`
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { Component, inject } from "@angular/core";
|
|
85
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
86
|
+
import { NotificationService, type NotificationType } from "@nanahoshi/mona-ui/notification";
|
|
87
|
+
|
|
88
|
+
@Component({
|
|
89
|
+
selector: "app-notification-types-example",
|
|
90
|
+
imports: [ButtonDirective],
|
|
91
|
+
templateUrl: "./types-example.component.html"
|
|
92
|
+
})
|
|
93
|
+
export class NotificationTypesExampleComponent {
|
|
94
|
+
readonly #notificationService = inject(NotificationService);
|
|
95
|
+
protected readonly messages: Record<NotificationType, string> = {
|
|
96
|
+
error: "The file couldn't be uploaded.",
|
|
97
|
+
info: "A new version is available.",
|
|
98
|
+
success: "Your changes have been saved.",
|
|
99
|
+
warning: "Your session ends in 5 minutes."
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
protected notify(type: NotificationType): void {
|
|
103
|
+
this.#notificationService.show({ content: this.messages[type], duration: 5000, progressBar: true, type });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`types-example.component.html`
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<div class="flex flex-wrap gap-2">
|
|
112
|
+
<button monaButton look="info" type="button" (click)="notify('info')">Info</button>
|
|
113
|
+
<button monaButton look="success" type="button" (click)="notify('success')">Success</button>
|
|
114
|
+
<button monaButton look="warning" type="button" (click)="notify('warning')">Warning</button>
|
|
115
|
+
<button monaButton look="error" type="button" (click)="notify('error')">Error</button>
|
|
116
|
+
</div>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Template content
|
|
120
|
+
|
|
121
|
+
A template gets the `NotificationRef` as its implicit context and the `data` as `data`.
|
|
122
|
+
|
|
123
|
+
`template-example.component.ts`
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import type { TemplateRef } from "@angular/core";
|
|
127
|
+
import { Component, inject, signal } from "@angular/core";
|
|
128
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
129
|
+
import { NotificationService } from "@nanahoshi/mona-ui/notification";
|
|
130
|
+
|
|
131
|
+
@Component({
|
|
132
|
+
selector: "app-notification-template-example",
|
|
133
|
+
imports: [ButtonDirective],
|
|
134
|
+
templateUrl: "./template-example.component.html"
|
|
135
|
+
})
|
|
136
|
+
export class NotificationTemplateExampleComponent {
|
|
137
|
+
readonly #notificationService = inject(NotificationService);
|
|
138
|
+
protected readonly files = signal(["budget.xlsx", "report.pdf", "roadmap.docx"]);
|
|
139
|
+
|
|
140
|
+
protected moveToBin(file: string, undoTemplate: TemplateRef<unknown>): void {
|
|
141
|
+
this.files.update(files => files.filter(item => item !== file));
|
|
142
|
+
this.#notificationService.show({ content: undoTemplate, data: { file }, duration: 8000 });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected undo(file: string): void {
|
|
146
|
+
this.files.update(files => [...files, file].sort());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`template-example.component.html`
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<ul class="flex max-w-sm flex-col gap-2">
|
|
155
|
+
@for (file of files(); track file) {
|
|
156
|
+
<li class="flex items-center justify-between gap-2">
|
|
157
|
+
<span>{{ file }}</span>
|
|
158
|
+
<button monaButton size="small" type="button" (click)="moveToBin(file, undoTemplate)">Move to bin</button>
|
|
159
|
+
</li>
|
|
160
|
+
} @empty {
|
|
161
|
+
<li>The folder is empty.</li>
|
|
162
|
+
}
|
|
163
|
+
</ul>
|
|
164
|
+
|
|
165
|
+
<ng-template #undoTemplate let-data="data" let-ref>
|
|
166
|
+
<div class="flex items-center gap-2 p-2">
|
|
167
|
+
<span>Moved {{ data.file }} to the bin.</span>
|
|
168
|
+
<button monaButton look="link" type="button" (click)="undo(data.file); ref.hide()">Undo</button>
|
|
169
|
+
</div>
|
|
170
|
+
</ng-template>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Updating a notification
|
|
174
|
+
|
|
175
|
+
`update()` changes the content, title, type or close button of a notification that is already shown, and announces the new message.
|
|
176
|
+
|
|
177
|
+
`update-example.component.ts`
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { Component, inject } from "@angular/core";
|
|
181
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
182
|
+
import { NotificationService } from "@nanahoshi/mona-ui/notification";
|
|
183
|
+
|
|
184
|
+
@Component({
|
|
185
|
+
selector: "app-notification-update-example",
|
|
186
|
+
imports: [ButtonDirective],
|
|
187
|
+
templateUrl: "./update-example.component.html"
|
|
188
|
+
})
|
|
189
|
+
export class NotificationUpdateExampleComponent {
|
|
190
|
+
readonly #notificationService = inject(NotificationService);
|
|
191
|
+
|
|
192
|
+
protected upload(): void {
|
|
193
|
+
const ref = this.#notificationService.show({
|
|
194
|
+
closable: false,
|
|
195
|
+
content: "Uploading report.pdf…",
|
|
196
|
+
title: "Uploading"
|
|
197
|
+
});
|
|
198
|
+
// Stands in for an upload to a server.
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
ref.update({ closable: true, content: "report.pdf was uploaded.", title: "Done", type: "success" });
|
|
201
|
+
}, 2500);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`update-example.component.html`
|
|
207
|
+
|
|
208
|
+
```html
|
|
209
|
+
<button monaButton look="primary" type="button" (click)="upload()">Upload report</button>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Dismissal
|
|
213
|
+
|
|
214
|
+
Every notification has a close button unless you set `closable: false`, timed ones included, so a user can dismiss a message before its time is up. With `duration`, the notification also closes on its own after that many milliseconds.
|
|
215
|
+
|
|
216
|
+
The countdown pauses while the pointer is over the notification, while focus is inside it, and while the browser window is in the background. Hover and focus are tracked separately, so moving the pointer away doesn't restart it while focus is still inside. It resumes with the time that was left, measured by the clock, so a short notification isn't stretched by a slow or throttled tab.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// No duration: stays until the user closes it.
|
|
220
|
+
this.#notificationService.show({ content: "Manual dismiss only." });
|
|
221
|
+
|
|
222
|
+
// Closes after 5s, and has a close button.
|
|
223
|
+
this.#notificationService.show({ content: "Auto-dismissing.", duration: 5000 });
|
|
224
|
+
|
|
225
|
+
// Closes after 5s, with no close button. Avoid this for messages users need time to read.
|
|
226
|
+
this.#notificationService.show({ content: "Brief.", duration: 5000, closable: false });
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Application-wide defaults
|
|
230
|
+
|
|
231
|
+
`provideNotificationDefaults()` sets how every notification behaves, for example to let users turn auto-hide off (WCAG 2.2.1):
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { provideNotificationDefaults } from "@nanahoshi/mona-ui/notification";
|
|
235
|
+
|
|
236
|
+
bootstrapApplication(AppComponent, {
|
|
237
|
+
providers: [provideNotificationDefaults({ autoHide: false, maxVisible: 3 })]
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
| Default | Value | Effect |
|
|
242
|
+
|---------------------|--------|------------------------------------------------------------------------------------|
|
|
243
|
+
| `autoHide` | `true` | Whether notifications with a `duration` close on their own. |
|
|
244
|
+
| `durationScale` | `1` | A factor applied to every `duration`; `2` keeps notifications twice as long. |
|
|
245
|
+
| `maxVisible` | none | The most notifications shown at once per position. The oldest closes to make room. |
|
|
246
|
+
| `pauseOnWindowBlur` | `true` | Whether the countdown pauses while the browser window doesn't have focus. |
|
|
247
|
+
|
|
248
|
+
### Content types
|
|
249
|
+
|
|
250
|
+
`content` accepts a plain string, a `TemplateRef`, or a component `Type`. Pass `data` for a template or component to use:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
this.#notificationService.show({ content: "Plain text notification." });
|
|
254
|
+
|
|
255
|
+
this.#notificationService.show({ content: this.undoTemplate, data: { file: "report.pdf" } });
|
|
256
|
+
|
|
257
|
+
this.#notificationService.show({ content: UploadNotificationComponent, data: { fileName: "report.pdf" } });
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
A template gets the `NotificationRef` as its implicit context and the `data` as `data` (see the template example above). A component injects them:
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
@Component({ template: `<p class="p-2">Uploading {{ data.fileName }}…</p>` })
|
|
264
|
+
export class UploadNotificationComponent {
|
|
265
|
+
protected readonly data = inject<{ fileName: string }>(NOTIFICATION_DATA);
|
|
266
|
+
protected readonly ref = inject(NOTIFICATION_REF);
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Positioning and scoping
|
|
271
|
+
|
|
272
|
+
Notifications are grouped into one container per `position` (`"top"`, `"topleft"`, `"topright"`, `"bottom"`, `"bottomleft"`, `"bottomright"`), appended to `document.body` by default:
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
this.#notificationService.show({ content: "Bottom-left toast.", position: "bottomleft" });
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Pass `appendTo` (a `ViewContainerRef`) to scope the notification container to a specific element instead of the document body — useful for notifications confined to a panel or card:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
this.#notificationService.show({ content: "Scoped notification.", appendTo: this.scopedContainer() });
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Managing a notification after showing it
|
|
285
|
+
|
|
286
|
+
`show()` returns a `NotificationRef`:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
const ref = this.#notificationService.show({ content: "Uploading…", id: "upload-1" });
|
|
290
|
+
|
|
291
|
+
ref.afterHide.subscribe(() => console.log("Notification closed"));
|
|
292
|
+
ref.update({ content: "Upload complete.", type: "success" });
|
|
293
|
+
ref.hide();
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
`update()` changes the content, title, type or close button of a notification that is already shown, and announces the new message. `afterHide` emits once the notification's leave animation has ended and it has been removed.
|
|
297
|
+
|
|
298
|
+
Calling `show()` again with the same `id` (at the same `position`) returns the existing `NotificationRef` instead of creating a duplicate notification. Use `NotificationService.hide(id)` or `NotificationService.hideAll()` to close notifications without holding onto a `NotificationRef`.
|
|
299
|
+
|
|
300
|
+
## Behavior
|
|
301
|
+
|
|
302
|
+
**`closable: false` with no `duration` can't be dismissed by the user.** Close it yourself with `ref.hide()` or `hide(id)`.
|
|
303
|
+
|
|
304
|
+
**Reusing an `id` doesn't change an already-shown notification.** `show()` returns the existing ref and discards the new `options`; call `ref.update()` to change it.
|
|
305
|
+
|
|
306
|
+
**`id` uniqueness is scoped per `position`.** The same `id` at two different positions creates two independent notifications.
|
|
307
|
+
|
|
308
|
+
**Notifications at one position share a container**, created when the first is shown and removed with the last. A notification shown and hidden in the same tick leaves nothing behind. A container on `document.body` takes the app's direction and the active Mona locale as `dir` and `lang`.
|
|
309
|
+
|
|
310
|
+
**The countdown bar is drawn in the type's theme color**, through its CSS variable, so it follows a theme switch. Reduced motion turns the enter and leave animations off.
|
|
311
|
+
|
|
312
|
+
## Forms Integration
|
|
313
|
+
|
|
314
|
+
Not applicable. Notification does not accept or emit user input and has no form control integration.
|
|
315
|
+
|
|
316
|
+
## Accessibility
|
|
317
|
+
|
|
318
|
+
### Keyboard
|
|
319
|
+
|
|
320
|
+
The close button is a native `<button>` (Enter / Space). When a notification closes while it has focus, focus moves to the next notification that can take it, or back to where it was before it entered the notifications.
|
|
321
|
+
|
|
322
|
+
### Announcements and ARIA
|
|
323
|
+
|
|
324
|
+
Each notification is announced through the CDK `LiveAnnouncer` once it has rendered, and again after `update()`: politely for `info` and `success`, assertively for `error` and `warning`. The notification itself isn't a live region, since one inserted with its text already in it is often skipped by screen readers. The announcement is the title and the text for string content, or the rendered text of a template or component.
|
|
325
|
+
|
|
326
|
+
| Element | Attribute | Value |
|
|
327
|
+
|-----------------------|---------------|-------------------------------------------------------|
|
|
328
|
+
| Container | `role` | `"region"` |
|
|
329
|
+
| Container | `aria-label` | `"Notifications"` (the `notification.region` message) |
|
|
330
|
+
| Countdown bar wrapper | `aria-hidden` | `"true"`: the time left isn't announced |
|
|
331
|
+
| Close button | `aria-label` | `closeTitle`, or the localized `"Close"` |
|
|
332
|
+
|
|
333
|
+
**Consumer responsibilities:**
|
|
334
|
+
|
|
335
|
+
- The close button's accessible name defaults to `"Close"`; set `closeTitle` to override it.
|
|
336
|
+
- When using a custom component or `TemplateRef` as `content`, the consumer is responsible for that content's own accessibility (labels, focus order, etc.). Its rendered text is what gets announced.
|
|
337
|
+
- Give users enough time: keep a close button on timed notifications, and consider `provideNotificationDefaults({ autoHide: false })` or a `durationScale` as a user setting.
|
|
338
|
+
|
|
339
|
+
## API
|
|
340
|
+
|
|
341
|
+
Everything below is imported from `@nanahoshi/mona-ui/notification`.
|
|
342
|
+
|
|
343
|
+
### `NotificationService`
|
|
344
|
+
|
|
345
|
+
#### Methods
|
|
346
|
+
|
|
347
|
+
| Signature | Description |
|
|
348
|
+
| --- | --- |
|
|
349
|
+
| `hide(id: string): void` | Closes the notification with the given `id`, wherever its container is positioned. No-op if no notification with that `id` is currently shown. |
|
|
350
|
+
| `hideAll(): void` | Closes every currently visible notification, across all positions. |
|
|
351
|
+
| `show(options: NotificationOptions): NotificationRef` | Creates a notification and returns a `NotificationRef`. If a notification with the same `id` already exists at the resolved `position`, returns a ref to that existing notification instead of creating a duplicate. |
|
|
352
|
+
|
|
353
|
+
### `provideNotificationDefaults`
|
|
354
|
+
|
|
355
|
+
Sets application-wide notification behavior: whether timed notifications close on their own, how much longer they
|
|
356
|
+
stay, how many show at once, and whether the countdown pauses while the window is in the background.
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
function provideNotificationDefaults(defaults: Partial<NotificationDefaults>): EnvironmentProviders;
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Types
|
|
363
|
+
|
|
364
|
+
#### `NOTIFICATION_DATA`
|
|
365
|
+
|
|
366
|
+
The `data` given in the notification's options, for a content component or template to inject.
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
const NOTIFICATION_DATA: InjectionToken<unknown>;
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
#### `NOTIFICATION_DEFAULT_MESSAGES`
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
const NOTIFICATION_DEFAULT_MESSAGES: { close: string; error: string; info: string; region: string; success: string; warning: string; };
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### `NOTIFICATION_DEFAULTS`
|
|
379
|
+
|
|
380
|
+
Application-wide notification settings. Provide them with `provideNotificationDefaults()`.
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
const NOTIFICATION_DEFAULTS: InjectionToken<NotificationDefaults>;
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
#### `NOTIFICATION_REF`
|
|
387
|
+
|
|
388
|
+
The reference of the notification a content component or template is shown in.
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const NOTIFICATION_REF: InjectionToken<NotificationRef>;
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
#### `NotificationRef`
|
|
395
|
+
|
|
396
|
+
| Name | Type | Description |
|
|
397
|
+
| --- | --- | --- |
|
|
398
|
+
| `afterHide` (read-only) | `Observable<void>` | Emits once the notification has finished closing, after its leave animation, and been removed. |
|
|
399
|
+
| `content` (read-only) | `ComponentRef<unknown> \| null` | The dynamically created content component's reference, or `null` when the notification's content is a string or `TemplateRef`, or before the component has been created. |
|
|
400
|
+
| `id` (read-only) | `string` | The notification's id: the one given in its options, or a generated one. |
|
|
401
|
+
|
|
402
|
+
**Methods**
|
|
403
|
+
|
|
404
|
+
| Signature | Description |
|
|
405
|
+
| --- | --- |
|
|
406
|
+
| `hide(): void` | Closes the notification. |
|
|
407
|
+
| `update(changes: NotificationUpdate): void` | Changes the content, title, type or close button of the notification. The new message is announced to assistive technology. |
|
|
408
|
+
|
|
409
|
+
#### `NotificationDefaults`
|
|
410
|
+
|
|
411
|
+
Application-wide settings for notifications, given with `provideNotificationDefaults()`.
|
|
412
|
+
|
|
413
|
+
| Name | Type | Description |
|
|
414
|
+
| --- | --- | --- |
|
|
415
|
+
| `autoHide` (read-only) | `boolean` | Whether notifications with a `duration` close on their own. Turn it off to leave every notification open until the user closes it (WCAG 2.2.1). |
|
|
416
|
+
| `durationScale` (read-only) | `number` | A factor applied to every `duration`, for example `2` to keep notifications twice as long. |
|
|
417
|
+
| `maxVisible?` (read-only) | `number` | The most notifications shown at once at each position. The oldest closes to make room for a new one. Without it, there is no limit. |
|
|
418
|
+
| `pauseOnWindowBlur` (read-only) | `boolean` | Whether the countdown pauses while the browser window doesn't have focus. |
|
|
419
|
+
|
|
420
|
+
#### `NotificationOptions`
|
|
421
|
+
|
|
422
|
+
| Name | Type | Description |
|
|
423
|
+
| --- | --- | --- |
|
|
424
|
+
| `appendTo?` | `ViewContainerRef` | The container to append the notification's container to. Defaults to `document.body` when omitted. |
|
|
425
|
+
| `closable?` | `boolean` | Whether a close button is rendered on the notification. Timed notifications have one too, so they can be dismissed before their time is up. |
|
|
426
|
+
| `closeTitle?` | `string` | The accessible title/tooltip for the close button. Defaults to localized "Close". |
|
|
427
|
+
| `content` | `string \| TemplateRef<unknown> \| Type<unknown>` | The notification's content. Accepts plain text, a `TemplateRef`, or a component `Type` to render. A template gets the `NotificationRef` as `$implicit` and `data` as `data`; a component can inject `NOTIFICATION_REF` and `NOTIFICATION_DATA`. |
|
|
428
|
+
| `data?` | `unknown` | Data for a content component or template, available through `NOTIFICATION_DATA` or the template's `data` context property. |
|
|
429
|
+
| `duration?` | `number` | The time, in milliseconds, before the notification automatically closes. Omit to keep the notification open until manually closed. The countdown pauses while the notification is hovered or has focus, and while the window is in the background. |
|
|
430
|
+
| `height?` | `number \| string` | The notification's height. A number is treated as pixels. |
|
|
431
|
+
| `id?` | `string` | A unique identifier for the notification. Reusing an `id` for the same `position` returns the existing notification instead of creating a new one. |
|
|
432
|
+
| `position?` | `NotificationPosition` | The screen position the notification is anchored to. |
|
|
433
|
+
| `progressBar?` | `boolean` | Whether a countdown progress bar is displayed for a timed (`duration`) notification. |
|
|
434
|
+
| `title?` | `string` | The notification's title. Defaults to localized title derived from `type` (e.g. "Info", "Success", "Warning", "Error"). |
|
|
435
|
+
| `type?` | `NotificationType` | The notification's semantic type, controlling its icon, color, and accessibility announcement urgency. |
|
|
436
|
+
| `width?` | `number \| string` | The notification's width. A number is treated as pixels. |
|
|
437
|
+
|
|
438
|
+
#### `NotificationPosition`
|
|
439
|
+
|
|
440
|
+
The screen position a notification container is anchored to.
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
type NotificationPosition = "bottom" | "bottomleft" | "bottomright" | "top" | "topleft" | "topright";
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
#### `NotificationType`
|
|
447
|
+
|
|
448
|
+
The semantic type of a notification, controlling its icon, color, and accessibility announcement urgency.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
type NotificationType = "error" | "info" | "success" | "warning";
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
#### `NotificationUpdate`
|
|
455
|
+
|
|
456
|
+
The options `NotificationRef.update()` can change on a notification that is already shown.
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
type NotificationUpdate = Partial<Pick<NotificationOptions, "closable" | "content" | "title" | "type">>;
|
|
460
|
+
```
|