@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
package/docs/dialog.md
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
# Dialog
|
|
2
|
+
|
|
3
|
+
> Modal or non-modal messages, confirmations and content dialogs.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/dialog`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-dialog`
|
|
8
|
+
|
|
9
|
+
`DialogComponent` and `DialogService` display a modal or non-modal message, confirmation, or content dialog with an optional icon, description, and action buttons.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Dialog displays a modal (or non-modal) message centered in the viewport, with an optional icon, title, description, free-form content, and a row of action buttons. It is built on `PopupService` internally, like every other Mona UI overlay.
|
|
14
|
+
|
|
15
|
+
There are two ways to use it:
|
|
16
|
+
|
|
17
|
+
- **`DialogComponent`** (`<mona-dialog>`) is declarative. Place it behind an `@if` in your template; the dialog opens after the first render and closes when the host element is destroyed or when the consumer closes it.
|
|
18
|
+
- **`DialogService`** is imperative. Call `show()` with a `DialogSettings` object to open a dialog from code — useful from a service, an event handler, or anywhere without a fixed `@if` in a template. `confirm()` and `alert()` are shortcuts for the two most common prompts.
|
|
19
|
+
|
|
20
|
+
Both close the same way: an action button, the close button, Escape, or a programmatic close all close the dialog, and every close reports one result.
|
|
21
|
+
|
|
22
|
+
**Use `Dialog` when:**
|
|
23
|
+
|
|
24
|
+
- You need a modal confirmation, message, or short form, with a title/description/actions layout already built in
|
|
25
|
+
- You want built-in action-button wiring (`DialogAction[]` + a single `action`/`result` event) instead of composing buttons yourself
|
|
26
|
+
|
|
27
|
+
**Use `Window` instead when:**
|
|
28
|
+
|
|
29
|
+
- The user needs to drag, resize, minimize, or maximize the overlay
|
|
30
|
+
- The content is closer to a floating panel than a message or confirmation
|
|
31
|
+
|
|
32
|
+
**Use `Popup` directly when:**
|
|
33
|
+
|
|
34
|
+
- You need a custom anchored overlay with no title/action-row structure at all
|
|
35
|
+
|
|
36
|
+
## Import & Quick Start
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { DialogComponent } from "@nanahoshi/mona-ui/dialog";
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
@if (dialogVisible()) {
|
|
44
|
+
<mona-dialog
|
|
45
|
+
title="Discard changes?"
|
|
46
|
+
text="Your changes have not been saved."
|
|
47
|
+
[actions]="[{ text: 'Cancel' }, { text: 'Discard', look: 'error' }]"
|
|
48
|
+
(close)="dialogVisible.set(false)">
|
|
49
|
+
</mona-dialog>
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`DialogComponent` opens automatically once its host renders; there is no explicit `open()` call for declarative usage.
|
|
54
|
+
|
|
55
|
+
Imperative usage returns a `DialogRef` synchronously. The dialog closes itself when an action is clicked; `result` says how it closed:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { inject } from "@angular/core";
|
|
59
|
+
import { DialogService } from "@nanahoshi/mona-ui/dialog";
|
|
60
|
+
|
|
61
|
+
protected readonly dialogService = inject(DialogService);
|
|
62
|
+
|
|
63
|
+
confirmDiscard(): void {
|
|
64
|
+
const dialogRef = this.dialogService.show({
|
|
65
|
+
title: "Discard changes?",
|
|
66
|
+
text: "Your changes have not been saved.",
|
|
67
|
+
actions: [{ text: "Cancel" }, { data: "discard", text: "Discard", look: "error" }]
|
|
68
|
+
});
|
|
69
|
+
dialogRef.result.subscribe(result => {
|
|
70
|
+
if (!result.viaClose && result.action.data === "discard") {
|
|
71
|
+
this.discard();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For a yes/no question, `confirm()` does the same with built-in, translated OK and Cancel buttons:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
this.dialogService.confirm({ title: "Discard changes?", text: "Your changes have not been saved." }).subscribe(ok => {
|
|
81
|
+
if (ok) {
|
|
82
|
+
this.discard();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Anatomy
|
|
88
|
+
|
|
89
|
+
Dialog has five structural template directives, each an `ng-template` placed as projected content inside `<mona-dialog>...</mona-dialog>`. Only the content template receives a context (see [Content from a template or a component](#content-from-a-template-or-a-component)).
|
|
90
|
+
|
|
91
|
+
| Directive | Selector | Replaces |
|
|
92
|
+
|--------------------------------------|----------------------------------------------|------------------------------------|
|
|
93
|
+
| `DialogTitleTemplateDirective` | `ng-template[monaDialogTitleTemplate]` | The `title` input |
|
|
94
|
+
| `DialogDescriptionTemplateDirective` | `ng-template[monaDialogDescriptionTemplate]` | The `description` input |
|
|
95
|
+
| `DialogContentTemplateDirective` | `ng-template[monaDialogContentTemplate]` | The `text` input |
|
|
96
|
+
| `DialogIconTemplateDirective` | `ng-template[monaDialogIconTemplate]` | The built-in `type` icon |
|
|
97
|
+
| `DialogFooterTemplateDirective` | `ng-template[monaDialogFooterTemplate]` | The generated `actions` button row |
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<mona-dialog title="Delete file?">
|
|
101
|
+
<ng-template monaDialogIconTemplate>
|
|
102
|
+
<svg lucideTriangleAlert [size]="32"></svg>
|
|
103
|
+
</ng-template>
|
|
104
|
+
<ng-template monaDialogFooterTemplate>
|
|
105
|
+
<div class="flex justify-end gap-2 p-2">
|
|
106
|
+
<button monaButton (click)="dialogVisible.set(false)">Cancel</button>
|
|
107
|
+
<button monaButton look="error" (click)="delete()">Delete</button>
|
|
108
|
+
</div>
|
|
109
|
+
</ng-template>
|
|
110
|
+
</mona-dialog>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When a footer template is provided, it replaces the built-in action-button row entirely — `actions` and `actionsLayout` no longer render anything, and Enter no longer triggers a default action.
|
|
114
|
+
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
### Action buttons and results
|
|
118
|
+
|
|
119
|
+
`basic-example.component.ts`
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { Component, signal } from "@angular/core";
|
|
123
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
124
|
+
import type { DialogAction, DialogActionEvent } from "@nanahoshi/mona-ui/dialog";
|
|
125
|
+
import { DialogComponent } from "@nanahoshi/mona-ui/dialog";
|
|
126
|
+
|
|
127
|
+
@Component({
|
|
128
|
+
selector: "app-dialog-basic-example",
|
|
129
|
+
imports: [ButtonDirective, DialogComponent],
|
|
130
|
+
templateUrl: "./basic-example.component.html"
|
|
131
|
+
})
|
|
132
|
+
export class DialogBasicExampleComponent {
|
|
133
|
+
protected readonly actions: DialogAction<string>[] = [
|
|
134
|
+
{ data: "keep", default: true, text: "Keep editing" },
|
|
135
|
+
{ data: "discard", look: "error", text: "Discard" }
|
|
136
|
+
];
|
|
137
|
+
protected readonly lastChoice = signal("none");
|
|
138
|
+
protected readonly open = signal(false);
|
|
139
|
+
|
|
140
|
+
protected onAction(event: DialogActionEvent): void {
|
|
141
|
+
this.lastChoice.set(event.action.text);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`basic-example.component.html`
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
150
|
+
<button monaButton aria-haspopup="dialog" type="button" (click)="open.set(true)">Discard draft</button>
|
|
151
|
+
<span aria-live="polite" class="text-sm">Last choice: {{ lastChoice() }}</span>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
@if (open()) {
|
|
155
|
+
<mona-dialog
|
|
156
|
+
text="The draft and its attachments will be removed."
|
|
157
|
+
title="Discard this draft?"
|
|
158
|
+
type="warning"
|
|
159
|
+
[actions]="actions"
|
|
160
|
+
(action)="onAction($event)"
|
|
161
|
+
(close)="open.set(false)" />
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Each `DialogAction` renders as a `monaButton` with that action's `text`, `look`, `rounded`, `iconOnly`, and `cssClass`. Clicking one emits `action` (and `DialogRef.action$`); unless a subscriber calls `event.preventDefault()`, the dialog then closes on its own, for `<mona-dialog>` and `DialogService.show()` alike. Give actions a `data` value to tell them apart without comparing their (translated) text.
|
|
166
|
+
|
|
167
|
+
### Default action
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
protected readonly actions: DialogAction[] = [
|
|
171
|
+
{ text: "Cancel" },
|
|
172
|
+
{ default: true, look: "primary", text: "Save" }
|
|
173
|
+
];
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Pressing Enter inside the dialog triggers the action marked `default: true`, as in a form. Enter on a control that handles it itself (a button, a link, a text area, a select, a checkbox, a menu, an option…) does what that control does instead. `confirm()` and `alert()` make OK the default.
|
|
177
|
+
|
|
178
|
+
### Severity type and icon
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<mona-dialog type="error" title="Something went wrong" text="The file could not be saved."> </mona-dialog>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`type` accepts `"info" | "success" | "warning" | "error" | "confirm"`, each with a built-in icon, or `null` to render no icon at all. `"confirm"`, `"error"`, and `"warning"` also switch the rendered ARIA role — see [Accessibility](#accessibility).
|
|
185
|
+
|
|
186
|
+
On `<mona-dialog>`, `type` defaults to `"info"`, so a dialog without `type` shows the info icon. For a dialog with no icon, such as one holding a form, set `[type]="null"`. `DialogService.show()` has no default type: leave `type` out of the settings, or set it to `null`, and the dialog has no icon. `alert()` defaults to `"info"` and `confirm()` to `"confirm"`.
|
|
187
|
+
|
|
188
|
+
### Custom content instead of plain text
|
|
189
|
+
|
|
190
|
+
A content template replaces `text`. Here Enter in the text box triggers the default Save action.
|
|
191
|
+
|
|
192
|
+
`content-example.component.ts`
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { Component, signal } from "@angular/core";
|
|
196
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
197
|
+
import type { DialogAction, DialogActionEvent } from "@nanahoshi/mona-ui/dialog";
|
|
198
|
+
import { DialogComponent, DialogContentTemplateDirective } from "@nanahoshi/mona-ui/dialog";
|
|
199
|
+
import { TextBoxComponent } from "@nanahoshi/mona-ui/text-box";
|
|
200
|
+
|
|
201
|
+
@Component({
|
|
202
|
+
selector: "app-dialog-content-example",
|
|
203
|
+
imports: [ButtonDirective, DialogComponent, DialogContentTemplateDirective, TextBoxComponent],
|
|
204
|
+
templateUrl: "./content-example.component.html"
|
|
205
|
+
})
|
|
206
|
+
export class DialogContentExampleComponent {
|
|
207
|
+
protected readonly actions: DialogAction<string>[] = [
|
|
208
|
+
{ data: "cancel", text: "Cancel" },
|
|
209
|
+
{ data: "save", default: true, look: "primary", text: "Save" }
|
|
210
|
+
];
|
|
211
|
+
protected readonly draftName = signal("");
|
|
212
|
+
protected readonly name = signal("Quarterly report");
|
|
213
|
+
protected readonly open = signal(false);
|
|
214
|
+
|
|
215
|
+
protected onAction(event: DialogActionEvent): void {
|
|
216
|
+
if (event.action.data === "save" && this.draftName().trim()) {
|
|
217
|
+
this.name.set(this.draftName().trim());
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
protected rename(): void {
|
|
222
|
+
this.draftName.set(this.name());
|
|
223
|
+
this.open.set(true);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`content-example.component.html`
|
|
229
|
+
|
|
230
|
+
```html
|
|
231
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
232
|
+
<span class="text-sm">Project: {{ name() }}</span>
|
|
233
|
+
<button monaButton aria-haspopup="dialog" type="button" (click)="rename()">Rename</button>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
@if (open()) {
|
|
237
|
+
<mona-dialog
|
|
238
|
+
title="Rename project"
|
|
239
|
+
[actions]="actions"
|
|
240
|
+
[type]="null"
|
|
241
|
+
(action)="onAction($event)"
|
|
242
|
+
(close)="open.set(false)">
|
|
243
|
+
<ng-template monaDialogContentTemplate>
|
|
244
|
+
<div class="flex flex-col gap-1">
|
|
245
|
+
<label for="dialog-content-example-name">Project name</label>
|
|
246
|
+
<mona-text-box inputId="dialog-content-example-name" [(value)]="draftName" />
|
|
247
|
+
</div>
|
|
248
|
+
</ng-template>
|
|
249
|
+
</mona-dialog>
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### A form in a dialog
|
|
254
|
+
|
|
255
|
+
Bind a signal form inside a content template. Save is the default action, so Enter in a text field triggers it. While the form is invalid, the `action` handler calls `event.preventDefault()`, which keeps the dialog open, and marks the form touched to show the errors. Once the form is valid, Save closes the dialog.
|
|
256
|
+
|
|
257
|
+
`form-example.component.ts`
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
import { Component, signal } from "@angular/core";
|
|
261
|
+
import { email, form, FormField, required } from "@angular/forms/signals";
|
|
262
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
263
|
+
import type { DialogAction, DialogActionEvent } from "@nanahoshi/mona-ui/dialog";
|
|
264
|
+
import { DialogComponent, DialogContentTemplateDirective } from "@nanahoshi/mona-ui/dialog";
|
|
265
|
+
import { LabelComponent } from "@nanahoshi/mona-ui/label";
|
|
266
|
+
import { TextBoxComponent } from "@nanahoshi/mona-ui/text-box";
|
|
267
|
+
|
|
268
|
+
interface ContactModel {
|
|
269
|
+
email: string;
|
|
270
|
+
name: string;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@Component({
|
|
274
|
+
selector: "app-dialog-form-example",
|
|
275
|
+
imports: [
|
|
276
|
+
ButtonDirective,
|
|
277
|
+
DialogComponent,
|
|
278
|
+
DialogContentTemplateDirective,
|
|
279
|
+
FormField,
|
|
280
|
+
LabelComponent,
|
|
281
|
+
TextBoxComponent
|
|
282
|
+
],
|
|
283
|
+
templateUrl: "./form-example.component.html"
|
|
284
|
+
})
|
|
285
|
+
export class DialogFormExampleComponent {
|
|
286
|
+
readonly #model = signal<ContactModel>({ email: "", name: "" });
|
|
287
|
+
protected readonly actions: DialogAction<string>[] = [
|
|
288
|
+
{ data: "cancel", text: "Cancel" },
|
|
289
|
+
{ data: "save", default: true, look: "primary", text: "Save" }
|
|
290
|
+
];
|
|
291
|
+
protected readonly contact = form(this.#model, path => {
|
|
292
|
+
required(path.name, { message: "Enter a name." });
|
|
293
|
+
required(path.email, { message: "Enter an email address." });
|
|
294
|
+
email(path.email, { message: "Enter a valid email address." });
|
|
295
|
+
});
|
|
296
|
+
protected readonly open = signal(false);
|
|
297
|
+
protected readonly saved = signal<ContactModel | null>(null);
|
|
298
|
+
|
|
299
|
+
protected onAction(event: DialogActionEvent): void {
|
|
300
|
+
if (event.action.data !== "save") {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (this.contact().invalid()) {
|
|
304
|
+
// Keeps the dialog open and shows every field's error.
|
|
305
|
+
event.preventDefault();
|
|
306
|
+
this.contact().markAsTouched();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
this.saved.set(this.#model());
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
protected openDialog(): void {
|
|
313
|
+
this.#model.set({ email: "", name: "" });
|
|
314
|
+
this.contact().reset();
|
|
315
|
+
this.open.set(true);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
`form-example.component.html`
|
|
321
|
+
|
|
322
|
+
```html
|
|
323
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
324
|
+
<button monaButton aria-haspopup="dialog" type="button" (click)="openDialog()">Add contact</button>
|
|
325
|
+
@if (saved(); as contact) {
|
|
326
|
+
<span class="text-sm">Saved: {{ contact.name }} ({{ contact.email }})</span>
|
|
327
|
+
}
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
@if (open()) {
|
|
331
|
+
<mona-dialog
|
|
332
|
+
title="Add contact"
|
|
333
|
+
[actions]="actions"
|
|
334
|
+
[type]="null"
|
|
335
|
+
(action)="onAction($event)"
|
|
336
|
+
(close)="open.set(false)">
|
|
337
|
+
<ng-template monaDialogContentTemplate>
|
|
338
|
+
<div class="flex flex-col gap-3">
|
|
339
|
+
<div class="flex flex-col gap-1">
|
|
340
|
+
<mona-label text="Name">
|
|
341
|
+
<mona-text-box aria-describedby="dialog-form-example-name-error" [formField]="contact.name" />
|
|
342
|
+
</mona-label>
|
|
343
|
+
<p aria-live="polite" class="text-sm text-error" id="dialog-form-example-name-error">
|
|
344
|
+
@if (contact.name().touched()) {
|
|
345
|
+
@for (error of contact.name().errors(); track error.kind) {
|
|
346
|
+
{{ error.message }}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
</p>
|
|
350
|
+
</div>
|
|
351
|
+
<div class="flex flex-col gap-1">
|
|
352
|
+
<mona-label text="Email">
|
|
353
|
+
<mona-text-box
|
|
354
|
+
aria-describedby="dialog-form-example-email-error"
|
|
355
|
+
type="email"
|
|
356
|
+
[formField]="contact.email" />
|
|
357
|
+
</mona-label>
|
|
358
|
+
<p aria-live="polite" class="text-sm text-error" id="dialog-form-example-email-error">
|
|
359
|
+
@if (contact.email().touched()) {
|
|
360
|
+
@for (error of contact.email().errors(); track error.kind) {
|
|
361
|
+
{{ error.message }}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
</p>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
</ng-template>
|
|
368
|
+
</mona-dialog>
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Enter triggers the default action only outside a `<form>` element: inside one, Enter is left to the form's own submit. The example doesn't use a `<form>` element; signal forms don't need one.
|
|
373
|
+
|
|
374
|
+
### A confirmation from code
|
|
375
|
+
|
|
376
|
+
`confirm()` opens a dialog with OK and Cancel, and emits `true` only for OK.
|
|
377
|
+
|
|
378
|
+
`service-example.component.ts`
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { Component, inject, signal } from "@angular/core";
|
|
382
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
383
|
+
import { DialogService } from "@nanahoshi/mona-ui/dialog";
|
|
384
|
+
|
|
385
|
+
@Component({
|
|
386
|
+
selector: "app-dialog-service-example",
|
|
387
|
+
imports: [ButtonDirective],
|
|
388
|
+
templateUrl: "./service-example.component.html"
|
|
389
|
+
})
|
|
390
|
+
export class DialogServiceExampleComponent {
|
|
391
|
+
readonly #dialogService = inject(DialogService);
|
|
392
|
+
protected readonly status = signal("Active");
|
|
393
|
+
|
|
394
|
+
protected archive(): void {
|
|
395
|
+
this.#dialogService
|
|
396
|
+
.confirm({
|
|
397
|
+
text: "Archived projects are read-only until you restore them.",
|
|
398
|
+
title: "Archive this project?"
|
|
399
|
+
})
|
|
400
|
+
.subscribe(confirmed => {
|
|
401
|
+
if (confirmed) {
|
|
402
|
+
this.status.set("Archived");
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`service-example.component.html`
|
|
410
|
+
|
|
411
|
+
```html
|
|
412
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
413
|
+
<button monaButton aria-haspopup="dialog" type="button" (click)="archive()">Archive project</button>
|
|
414
|
+
<span aria-live="polite" class="text-sm">Status: {{ status() }}</span>
|
|
415
|
+
</div>
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Content from a template or a component
|
|
419
|
+
|
|
420
|
+
`DialogService.show()` takes either a `TemplateRef` or a component class as `content`, and a `data` value for it.
|
|
421
|
+
|
|
422
|
+
A template receives `data` as its implicit context and the `DialogRef` as `dialogRef`:
|
|
423
|
+
|
|
424
|
+
```html
|
|
425
|
+
<ng-template #renameContent let-file let-dialogRef="dialogRef">
|
|
426
|
+
<p>Rename {{ file.name }}?</p>
|
|
427
|
+
<button monaButton (click)="dialogRef.close('renamed')">Rename</button>
|
|
428
|
+
</ng-template>
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
A component injects `DIALOG_DATA` and `DialogRef`:
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
@Component({
|
|
435
|
+
selector: "app-rename-file",
|
|
436
|
+
template: `<p>Rename {{ data.name }}?</p>`
|
|
437
|
+
})
|
|
438
|
+
export class RenameFileComponent {
|
|
439
|
+
protected readonly data = inject<{ name: string }>(DIALOG_DATA);
|
|
440
|
+
protected readonly dialogRef = inject(DialogRef<string>);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const dialogRef = this.dialogService.show<string, { name: string }>({
|
|
444
|
+
content: RenameFileComponent,
|
|
445
|
+
data: { name: "report.pdf" },
|
|
446
|
+
injector: this.#injector,
|
|
447
|
+
title: "Rename file"
|
|
448
|
+
});
|
|
449
|
+
dialogRef.component; // ComponentRef<RenameFileComponent>
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Pass `injector` to give the content the providers of the place that opened it (a feature's services, a form's providers); without it, the content resolves from the root injector.
|
|
453
|
+
|
|
454
|
+
### Preventing a close
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
protected onClose(event: PopupCloseEvent): void {
|
|
458
|
+
if (this.formDirty()) {
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
this.dialogVisible.set(false);
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
```html
|
|
467
|
+
<mona-dialog (close)="onClose($event)"> </mona-dialog>
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Updating an open dialog
|
|
471
|
+
|
|
472
|
+
Only a subset of inputs stay reactive after the dialog opens — see [Live vs. one-shot inputs](#live-vs-one-shot-inputs). Changing `title`, `text`, `type`, `actions`, or the other live inputs on an already-open `<mona-dialog>` updates it in place, without closing and reopening:
|
|
473
|
+
|
|
474
|
+
```html
|
|
475
|
+
<mona-dialog [title]="stepTitle()" [text]="stepText()" [type]="stepType()"> </mona-dialog>
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Closing with a value
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
const dialogRef = this.dialogService.show<number>({ title: "Pick a size", content: this.sizePicker() });
|
|
482
|
+
dialogRef.result.subscribe(result => {
|
|
483
|
+
if (result.viaClose && result.via === PopupCloseSource.Programmatic) {
|
|
484
|
+
this.size.set(result.value ?? 0);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// From the content:
|
|
489
|
+
dialogRef.close(42);
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
## Behavior
|
|
493
|
+
|
|
494
|
+
### Live vs. one-shot inputs
|
|
495
|
+
|
|
496
|
+
After the dialog opens, `<mona-dialog>` keeps `actions`, `actionsLayout`, `aria-label`, `closable`, `description`, `rounded`, `text`, `title`, and `type` reactive — changing any of them re-renders the open dialog in place.
|
|
497
|
+
|
|
498
|
+
All other inputs (`height`, `width`, `top`, `left`, `minHeight`, `minWidth`, `maxHeight`, `maxWidth`, `focusedElement`, `closeOnEscape`, `modal`, and every `*Template` projected via content) are read once when the dialog opens. Changing them afterward has no effect on the already-open dialog.
|
|
499
|
+
|
|
500
|
+
`DialogRef.update()` performs the same in-place update as the reactive inputs above; it is how `DialogService.show()` consumers can update an imperatively-opened dialog without closing it.
|
|
501
|
+
|
|
502
|
+
### Positioning and size
|
|
503
|
+
|
|
504
|
+
The dialog is centered in the viewport. `left` pins it that many pixels from the viewport's left edge and `top` that many pixels from the top; each one replaces centering on its own axis only, so `top` alone keeps the dialog centered horizontally. `left` is physical: it measures from the left edge in right-to-left pages too.
|
|
505
|
+
|
|
506
|
+
The dialog sizes itself to its content. Unless `maxHeight`/`maxWidth` are given, it stays 1rem inside the viewport on each side; when its content is taller, the header and footer stay in place and the body scrolls.
|
|
507
|
+
|
|
508
|
+
### The close contract
|
|
509
|
+
|
|
510
|
+
Every close — an action, the close (X) button, Escape, a programmatic `dialogRef.close(value)`, or a destroyed `<mona-dialog>` — goes through the same steps:
|
|
511
|
+
|
|
512
|
+
1. `close` / `DialogRef.close$` emits a `PopupCloseEvent`. Call `event.preventDefault()` synchronously to keep the dialog open (a close caused by destroying `<mona-dialog>` can't be kept). For an action, `action` / `DialogRef.action$` emits first, and preventing it keeps the dialog open as well.
|
|
513
|
+
2. `DialogRef.result` emits one `DialogResult` as the leave animation starts. It replays to late subscribers and completes once the dialog has closed.
|
|
514
|
+
3. `closed` / `DialogRef.closed$` emits the same `DialogResult` after the leave animation, then completes.
|
|
515
|
+
|
|
516
|
+
A second `close()` while the dialog is closing does nothing.
|
|
517
|
+
|
|
518
|
+
### `modal`
|
|
519
|
+
|
|
520
|
+
`modal` (default `true`) makes the dialog modal: a backdrop, `aria-modal="true"`, focus kept inside the dialog, page scroll locked, and the rest of the page `inert`, so a pointer, Tab, or a screen reader can't reach it. Popups opened from inside the dialog (a dropdown, a date picker) stay usable, and stacked modal dialogs keep the page inert until the last one closes.
|
|
521
|
+
|
|
522
|
+
A non-modal dialog (`modal: false`) does none of that: Tab can leave it, and the page stays usable and scrollable.
|
|
523
|
+
|
|
524
|
+
- `DialogPromptSettings` is `DialogSettings` without `actions`, `content`, `data`, and `footerTemplate`. The buttons are labelled with the `ok` and `cancel` dialog messages (override them through `messages`) and carry `data` values `DIALOG_OK` (`"ok"`) and `DIALOG_CANCEL` (`"cancel"`). `confirm()` defaults `type` to `"confirm"`, `alert()` to `"info"`.
|
|
525
|
+
|
|
526
|
+
## Forms Integration
|
|
527
|
+
|
|
528
|
+
Dialog is a container, not a form control, so it has no form integration.
|
|
529
|
+
|
|
530
|
+
## Accessibility
|
|
531
|
+
|
|
532
|
+
### Keyboard
|
|
533
|
+
|
|
534
|
+
The Escape key closes the dialog when `closeOnEscape` is `true` (the default). Enter triggers the [default action](#default-action), if there is one.
|
|
535
|
+
|
|
536
|
+
### Focus
|
|
537
|
+
|
|
538
|
+
A modal dialog keeps focus inside itself for as long as it is open — Tab and Shift+Tab cannot move focus to the rest of the page. When it opens, focus moves automatically to the first focusable element, unless `focusedElement` is provided, in which case focus moves there instead. When it closes, focus returns to the element that had it before, if that element is still focusable; set `restoreFocus: false` in `DialogSettings` to leave focus where it is.
|
|
539
|
+
|
|
540
|
+
### ARIA
|
|
541
|
+
|
|
542
|
+
| Attribute | When present | Value |
|
|
543
|
+
|--------------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
|
|
544
|
+
| `role` | Always | `"alertdialog"` when `type` is `"confirm"`, `"error"`, or `"warning"`; `"dialog"` otherwise |
|
|
545
|
+
| `aria-labelledby` | When `title` or a `monaDialogTitleTemplate` is present | ID of the title element |
|
|
546
|
+
| `aria-label` | When there is no title | The `aria-label` input, or the `ariaLabel` setting |
|
|
547
|
+
| `aria-describedby` | Only when `description` or a `monaDialogDescriptionTemplate` is present | ID of the description element |
|
|
548
|
+
| `aria-modal` | When `modal` is `true` | `"true"` |
|
|
549
|
+
|
|
550
|
+
Every dialog needs an accessible name: a `title`, a title template, or `aria-label` (`ariaLabel` in the service settings). In development mode, a dialog without one logs a warning.
|
|
551
|
+
|
|
552
|
+
## API
|
|
553
|
+
|
|
554
|
+
Everything below is imported from `@nanahoshi/mona-ui/dialog`.
|
|
555
|
+
|
|
556
|
+
### `DialogComponent`
|
|
557
|
+
|
|
558
|
+
**Selector:** `mona-dialog`
|
|
559
|
+
|
|
560
|
+
#### Inputs
|
|
561
|
+
|
|
562
|
+
| Name | Type | Default | Description |
|
|
563
|
+
| --- | --- | --- | --- |
|
|
564
|
+
| `actions` | `Iterable<DialogAction>` | `[]` | Sets the actions of the dialog. |
|
|
565
|
+
| `actionsLayout` | `ActionsLayout` | `"end"` | Sets the layout of the actions in the dialog footer. |
|
|
566
|
+
| `aria-label` | `string \| undefined` | `undefined` | Accessible name for the dialog when it has no `title` or title template. |
|
|
567
|
+
| `closable` | `boolean` | `true` | Sets the visibility of the close button in the dialog header. |
|
|
568
|
+
| `closeOnEscape` | `boolean` | `true` | Sets whether the dialog should close when the escape key is pressed. |
|
|
569
|
+
| `description` | `string` | — | Sets the description of the dialog. |
|
|
570
|
+
| `focusedElement` | `HTMLElement \| ElementRef<HTMLElement> \| string \| null` | — | Sets the element that should receive focus when the dialog is opened. When omitted, focus moves to the first focusable element automatically. |
|
|
571
|
+
| `height` | `number` | — | Sets the height of the dialog. |
|
|
572
|
+
| `left` | `number` | — | Sets the left position of the dialog. |
|
|
573
|
+
| `maxHeight` | `number` | — | Sets the maximum height of the dialog. |
|
|
574
|
+
| `maxWidth` | `number` | — | Sets the maximum width of the dialog. |
|
|
575
|
+
| `messages` | `Partial<DialogMessages>` | — | Sets the custom messages for the dialog. |
|
|
576
|
+
| `minHeight` | `number` | — | Sets the minimum height of the dialog. |
|
|
577
|
+
| `minWidth` | `number` | — | Sets the minimum width of the dialog. |
|
|
578
|
+
| `modal` | `boolean` | `true` | Whether the dialog is modal: a backdrop, `aria-modal="true"`, focus kept inside, page scroll locked, and the rest of the page inert. |
|
|
579
|
+
| `rounded` | `"large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the component. |
|
|
580
|
+
| `text` | `string` | — | Primary text content displayed by the component. |
|
|
581
|
+
| `title` | `string` | — | Title text displayed in the component header or trigger. |
|
|
582
|
+
| `top` | `number` | — | Sets the top position of the dialog. |
|
|
583
|
+
| `type` | `"confirm" \| "error" \| "info" \| "success" \| "warning"` | `"info"` | Visual severity type of the dialog, controlling its icon and semantic role. Set to `null` to render the dialog without an icon. |
|
|
584
|
+
| `width` | `number` | — | Sets the width of the dialog. |
|
|
585
|
+
|
|
586
|
+
#### Outputs
|
|
587
|
+
|
|
588
|
+
| Name | Type | Description |
|
|
589
|
+
| --- | --- | --- |
|
|
590
|
+
| `action` | `DialogActionEvent<unknown>` | Emitted when the user clicks an action button. Call `event.preventDefault()` on the emitted `DialogActionEvent` to keep the dialog open. |
|
|
591
|
+
| `close` | `PopupCloseEvent<unknown>` | Emits before the dialog closes, whatever closes it: an action, the close button, Escape, or the component being destroyed. Call `preventDefault()` to keep it open (a close caused by destruction can't be kept). |
|
|
592
|
+
| `closed` | `void` | Emits when the dialog has closed and its leave animation has finished. |
|
|
593
|
+
|
|
594
|
+
### `DialogContentTemplateDirective`
|
|
595
|
+
|
|
596
|
+
**Selector:** `ng-template[monaDialogContentTemplate]`
|
|
597
|
+
|
|
598
|
+
### `DialogDescriptionTemplateDirective`
|
|
599
|
+
|
|
600
|
+
**Selector:** `ng-template[monaDialogDescriptionTemplate]`
|
|
601
|
+
|
|
602
|
+
### `DialogFooterTemplateDirective`
|
|
603
|
+
|
|
604
|
+
**Selector:** `ng-template[monaDialogFooterTemplate]`
|
|
605
|
+
|
|
606
|
+
### `DialogIconTemplateDirective`
|
|
607
|
+
|
|
608
|
+
**Selector:** `ng-template[monaDialogIconTemplate]`
|
|
609
|
+
|
|
610
|
+
### `DialogTitleTemplateDirective`
|
|
611
|
+
|
|
612
|
+
**Selector:** `ng-template[monaDialogTitleTemplate]`
|
|
613
|
+
|
|
614
|
+
### `DialogService`
|
|
615
|
+
|
|
616
|
+
#### Methods
|
|
617
|
+
|
|
618
|
+
| Signature | Description |
|
|
619
|
+
| --- | --- |
|
|
620
|
+
| `alert(settings: DialogPromptSettings): Observable<void>` | Opens a dialog with an OK button. Emits once it closes, however it closes, then completes. The dialog opens when `alert()` is called, whether or not the result is subscribed to. |
|
|
621
|
+
| `confirm(settings: DialogPromptSettings): Observable<boolean>` | Opens a confirmation dialog with OK and Cancel buttons. Emits `true` for OK and `false` for anything else (Cancel, the close button, Escape), then completes. The dialog opens when `confirm()` is called, whether or not the result is subscribed to. |
|
|
622
|
+
| `show<R = unknown, D = unknown>(settings: DialogSettings<D>): DialogRef<R>` | Opens a dialog. |
|
|
623
|
+
|
|
624
|
+
### `DialogRef`
|
|
625
|
+
|
|
626
|
+
A handle on an open dialog. The close contract:
|
|
627
|
+
- `action$` emits when an action button is clicked, before the dialog closes; `preventDefault()` keeps it open.
|
|
628
|
+
- `close$` emits before any close, and `preventDefault()` keeps the dialog open.
|
|
629
|
+
- `result` emits how the dialog closed as soon as the close goes ahead, and `closed$` emits the same result once
|
|
630
|
+
the dialog is gone. All of them complete when it closes.
|
|
631
|
+
|
|
632
|
+
**Type parameters:** `R = unknown`
|
|
633
|
+
|
|
634
|
+
#### Properties
|
|
635
|
+
|
|
636
|
+
| Name | Type | Description |
|
|
637
|
+
| --- | --- | --- |
|
|
638
|
+
| `action$` (read-only) | `Observable<DialogActionEvent>` | Emits when an action button is clicked, before the dialog closes. Call `preventDefault()` on the event to keep the dialog open. Completes when the dialog closes. |
|
|
639
|
+
| `close$` (read-only) | `Observable<PopupCloseEvent<R>>` | Emits before the dialog closes, whatever closes it. Call `preventDefault()` to keep it open. Completes when the dialog closes. |
|
|
640
|
+
| `closed$` (read-only) | `Observable<DialogResult<R>>` | Emits the dialog's result once it has closed and its leave animation has finished, then completes. |
|
|
641
|
+
| `component` (read-only) | `ComponentRef<unknown> \| null` | The component given as `content`, or `null` for template and text content. |
|
|
642
|
+
| `element` (read-only) | `HTMLElement` | The dialog's overlay element. |
|
|
643
|
+
| `height` (read-only) | `number` | The dialog's current rendered height, in pixels. |
|
|
644
|
+
| `popupRef` (read-only) | `PopupRef` | The underlying `PopupRef`, for advanced overlay access. |
|
|
645
|
+
| `result` (read-only) | `Observable<DialogResult<R>>` | Emits how the dialog closed (an action, the close button, Escape, a backdrop click or `close()`) as soon as the close goes ahead, then completes when the dialog is gone. Late subscribers get the result too. |
|
|
646
|
+
| `width` (read-only) | `number` | The dialog's current rendered width, in pixels. |
|
|
647
|
+
|
|
648
|
+
#### Methods
|
|
649
|
+
|
|
650
|
+
| Signature | Description |
|
|
651
|
+
| --- | --- |
|
|
652
|
+
| `close(result?: R): void` | Closes the dialog. The value is the `value` of the result, which reports the close as programmatic. |
|
|
653
|
+
| `update(data: Partial<DialogSettings>): void` | Updates the dialog's content and appearance in place without closing and reopening it. Only the fields provided are changed; anything omitted keeps its current value. |
|
|
654
|
+
|
|
655
|
+
### `DialogActionEvent`
|
|
656
|
+
|
|
657
|
+
Emitted when the user clicks a dialog action button. Call `preventDefault()` to keep the dialog open.
|
|
658
|
+
|
|
659
|
+
**Type parameters:** `T = unknown`
|
|
660
|
+
**Extends:** `PreventableEvent`
|
|
661
|
+
|
|
662
|
+
#### Properties
|
|
663
|
+
|
|
664
|
+
| Name | Type | Description |
|
|
665
|
+
| --- | --- | --- |
|
|
666
|
+
| `action` (read-only) | `DialogAction<T>` | The action that was clicked. |
|
|
667
|
+
|
|
668
|
+
### Types
|
|
669
|
+
|
|
670
|
+
#### `DIALOG_CANCEL`
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
const DIALOG_CANCEL: "cancel";
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
#### `DIALOG_DATA`
|
|
677
|
+
|
|
678
|
+
The `data` a dialog was opened with, for a component given as its `content`.
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
const DIALOG_DATA: InjectionToken<unknown>;
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
#### `DIALOG_DEFAULT_MESSAGES`
|
|
685
|
+
|
|
686
|
+
```typescript
|
|
687
|
+
const DIALOG_DEFAULT_MESSAGES: MonaDialogMessages;
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
#### `DIALOG_OK`
|
|
691
|
+
|
|
692
|
+
Marks the buttons `confirm()` and `alert()` add, so their result can be read without comparing text.
|
|
693
|
+
|
|
694
|
+
```typescript
|
|
695
|
+
const DIALOG_OK: "ok";
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
#### `DialogAction`
|
|
699
|
+
|
|
700
|
+
**Type parameters:** `T = unknown`
|
|
701
|
+
|
|
702
|
+
| Name | Type | Description |
|
|
703
|
+
| --- | --- | --- |
|
|
704
|
+
| `cssClass?` | `string` | Additional class applied to the action button. |
|
|
705
|
+
| `data?` | `T` | Arbitrary data associated with the action, readable from `DialogActionEvent.action.data`. |
|
|
706
|
+
| `default?` | `boolean` | The action Enter triggers when focus is in the dialog but not on a button, link, text area or other control that handles Enter itself. Mark at most one action. |
|
|
707
|
+
| `iconOnly?` | `boolean` | Renders the button as icon-only. |
|
|
708
|
+
| `look?` | `"clear" \| "default" \| "error" \| "ghost" \| "info" \| "link" \| "outline" \| "primary" \| "secondary" \| "success" \| "warning"` | The action button's visual style. |
|
|
709
|
+
| `rounded?` | `"full" \| "large" \| "medium" \| "none" \| "small"` | The action button's border-radius preset. Falls back to the dialog's own `rounded` when omitted. |
|
|
710
|
+
| `text` | `string` | Required. The button's label. |
|
|
711
|
+
|
|
712
|
+
#### `DialogSettings`
|
|
713
|
+
|
|
714
|
+
The settings object accepted by `DialogService.show()`. Fields mirror the `DialogComponent` inputs of the same name
|
|
715
|
+
(`actions`, `actionsLayout`, `ariaLabel`, `closable`, `closeOnEscape`, `description`, `focusedElement`, `height`,
|
|
716
|
+
`left`, `maxHeight`, `maxWidth`, `minHeight`, `minWidth`, `modal`, `rounded`, `text`, `title`, `top`, `type`,
|
|
717
|
+
`width`), plus these service-only fields:
|
|
718
|
+
|
|
719
|
+
**Type parameters:** `D = unknown`
|
|
720
|
+
|
|
721
|
+
| Name | Type | Description |
|
|
722
|
+
| --- | --- | --- |
|
|
723
|
+
| `actions?` | `Iterable<DialogAction>` | The buttons in the dialog footer. When omitted, the dialog shows an OK button, plus a Cancel button when `type` is `"confirm"`. Pass an empty list for no buttons. |
|
|
724
|
+
| `actionsLayout?` | `ActionsLayout` | How the action buttons are aligned in the footer. |
|
|
725
|
+
| `ariaLabel?` | `string` | Accessible name for the dialog when it has no `title` or `titleTemplate`. |
|
|
726
|
+
| `closable?` | `boolean` | Whether the header shows a close button. |
|
|
727
|
+
| `closeOnEscape?` | `boolean` | Whether pressing Escape closes the dialog. |
|
|
728
|
+
| `content?` | `TemplateRef<unknown> \| Type<unknown>` | The dialog's body: a template, or a component. A template gets the dialog's `data` as `$implicit` and the `DialogRef` as `dialogRef`; a component can inject `DIALOG_DATA` and `DialogRef`. |
|
|
729
|
+
| `data?` | `D` | Data for the content: `DIALOG_DATA` in a component, `$implicit` in a template. |
|
|
730
|
+
| `description?` | `string` | Text shown under the title, and used as the dialog's accessible description. |
|
|
731
|
+
| `descriptionTemplate?` | `TemplateRef<unknown>` | Template rendered in place of `description`. |
|
|
732
|
+
| `focusedElement?` | `HTMLElement \| ElementRef<HTMLElement> \| string \| null` | The element that receives focus when the dialog opens: an element, an element reference, or a CSS selector matched inside the dialog. When omitted, focus moves to the first focusable element. |
|
|
733
|
+
| `footerTemplate?` | `TemplateRef<unknown>` | Template rendered in place of the generated action-button row. |
|
|
734
|
+
| `height?` | `number` | Height in pixels. When omitted, the dialog fits its content. |
|
|
735
|
+
| `iconTemplate?` | `TemplateRef<unknown>` | Template rendered in place of the built-in `type` icon. |
|
|
736
|
+
| `injector?` | `Injector` | Parent injector for the dialog's content, so a component given as `content` can inject what the opener provides. Defaults to the application injector. |
|
|
737
|
+
| `left?` | `number` | Distance from the viewport's left edge in pixels. When omitted, the dialog is centered horizontally. |
|
|
738
|
+
| `maxHeight?` | `number` | Maximum height in pixels. When omitted, the dialog stays 1rem inside the viewport and its body scrolls. |
|
|
739
|
+
| `maxWidth?` | `number` | Maximum width in pixels. When omitted, the dialog stays 1rem inside the viewport. |
|
|
740
|
+
| `messages?` | `Partial<DialogMessages>` | Overrides for the dialog's messages (close button label, OK, Cancel). |
|
|
741
|
+
| `minHeight?` | `number` | Minimum height in pixels. |
|
|
742
|
+
| `minWidth?` | `number` | Minimum width in pixels. |
|
|
743
|
+
| `modal?` | `boolean` | Whether the dialog is modal: a backdrop, `aria-modal="true"`, focus kept inside, page scroll locked, and the rest of the page inert. A non-modal dialog does none of these. |
|
|
744
|
+
| `restoreFocus?` | `boolean` | Whether focus goes back to where it was when the dialog opened, once it closes. |
|
|
745
|
+
| `rounded?` | `"large" \| "medium" \| "none" \| "small"` | Border-radius preset for the dialog and its action buttons. |
|
|
746
|
+
| `text?` | `string` | Text shown in the dialog's body when no `content` is given. |
|
|
747
|
+
| `title?` | `string` | Text shown in the dialog header, and used as the dialog's accessible name. |
|
|
748
|
+
| `titleTemplate?` | `TemplateRef<unknown>` | Template rendered in place of `title`. |
|
|
749
|
+
| `top?` | `number` | Distance from the viewport's top edge in pixels. When omitted, the dialog is centered vertically. |
|
|
750
|
+
| `type?` | `"confirm" \| "error" \| "info" \| "success" \| "warning"` | The dialog's severity, which picks its icon. `"confirm"`, `"error"` and `"warning"` give the dialog the `alertdialog` role. When omitted, `show()` renders no icon; `alert()` uses `"info"` and `confirm()` uses `"confirm"`. |
|
|
751
|
+
| `width?` | `number` | Width in pixels. When omitted, the dialog fits its content. |
|
|
752
|
+
|
|
753
|
+
#### `ActionsLayout`
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
type ActionsLayout = "end" | "center" | "start" | "stretched";
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
#### `DialogPromptSettings`
|
|
760
|
+
|
|
761
|
+
Settings for the `alert()` and `confirm()` helpers, which bring their own buttons.
|
|
762
|
+
|
|
763
|
+
```typescript
|
|
764
|
+
type DialogPromptSettings = Omit<DialogSettings, "actions" | "content" | "data" | "footerTemplate">;
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
#### `DialogResult`
|
|
768
|
+
|
|
769
|
+
How a dialog closed. Every close produces one: an action button (`viaClose: false`), or anything else
|
|
770
|
+
(`viaClose: true`): the close button, Escape, a backdrop click, or `close()`.
|
|
771
|
+
|
|
772
|
+
```typescript
|
|
773
|
+
type DialogResult<R = unknown> = | { readonly action: DialogAction; readonly via: PopupCloseSource.Action; readonly viaClose: false; } | { readonly via: Exclude<PopupCloseSource, PopupCloseSource.Action>; readonly value?: R; readonly viaClose: true; };
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
#### `Action`
|
|
777
|
+
|
|
778
|
+
From `@nanahoshi/mona-ui/common`.
|
|
779
|
+
|
|
780
|
+
A function taking a `P` and returning an `R`.
|
|
781
|
+
|
|
782
|
+
```typescript
|
|
783
|
+
type Action<P = void, R = void> = (arg: P) => R;
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
#### `DialogMessages`
|
|
787
|
+
|
|
788
|
+
From `@nanahoshi/mona-ui/i18n`.
|
|
789
|
+
|
|
790
|
+
```typescript
|
|
791
|
+
type DialogMessages = MonaDialogMessages;
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
#### `MonaDialogMessages`
|
|
795
|
+
|
|
796
|
+
From `@nanahoshi/mona-ui/i18n`.
|
|
797
|
+
|
|
798
|
+
| Name | Type | Description |
|
|
799
|
+
| --- | --- | --- |
|
|
800
|
+
| `cancel` (read-only) | `string` | The label of the Cancel button that `confirm()` and a `"confirm"` dialog without `actions` add. |
|
|
801
|
+
| `closeDialog` (read-only) | `string` | The accessible name of the close button in the dialog header. |
|
|
802
|
+
| `ok` (read-only) | `string` | The label of the OK button that `alert()`, `confirm()` and a dialog without `actions` add. |
|
|
803
|
+
|
|
804
|
+
#### `PreventableEvent`
|
|
805
|
+
|
|
806
|
+
From `@nanahoshi/mona-ui/common`.
|
|
807
|
+
|
|
808
|
+
**Type parameters:** `E extends Event = Event`
|
|
809
|
+
|
|
810
|
+
| Name | Type | Description |
|
|
811
|
+
| --- | --- | --- |
|
|
812
|
+
| `originalEvent` (read-only) | `E \| undefined` | The DOM event that caused this one, when there is one. |
|
|
813
|
+
| `type` (read-only) | `string \| undefined` | A name for the kind of event, when the component that emits it sets one. |
|
|
814
|
+
|
|
815
|
+
**Methods**
|
|
816
|
+
|
|
817
|
+
| Signature | Description |
|
|
818
|
+
| --- | --- |
|
|
819
|
+
| `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
|
|
820
|
+
| `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
|
|
821
|
+
|
|
822
|
+
**Documented elsewhere:** [`PopupCloseEvent`](popup.md), [`PopupCloseSource`](popup.md), [`PopupRef`](popup.md)
|