You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libs/inform/README.md
+106-2Lines changed: 106 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,11 @@ For more information about the build process, authors, contributions and issues,
21
21
22
22
## Concept
23
23
24
-
`ngx-inform` is a package to help facilitate common user information use-cases such as tooltips, toasts and snackbars.
24
+
`ngx-inform` is a package to help facilitate common user information use-cases such as tooltips, toasts and snackbars.
25
25
26
-
Currently the package provides a `ngxTooltip` directive which can be used to attach a customizable ARIA compliant tooltip to any component.
26
+
At its core, `ngx-inform` is build to be WCAG and ARIA compliant, and will throw errors whenever the necessary setup has not been provided to ensure said compliancy.
27
+
28
+
Currently the package provides a `ngxTooltip` directive which can be used to attach a customizable ARIA compliant tooltip to any component and the `ngxModalService` which allows for both custom and predefined global modals to be used throughout the application.
27
29
28
30
## Directives
29
31
@@ -85,3 +87,105 @@ On top of these two inputs, we have two additional inputs, being `ngxTooltipComp
85
87
```
86
88
87
89
When you wish to disable a tooltip and thus prevent it from being shown, you can use the `ngxTooltipDisabled` property. By default, this property is false.
90
+
91
+
## Services
92
+
93
+
### NgxModalService
94
+
95
+
The `NgxModalService` provides a WCAG/ARIA compliant approach to the Angular CDK `Dialog` service. It is important to understand that, unlike the Dialog service of the CDK, `ngx-inform`**will enforce WCAG/ARIA compliance**. Because of that, certain configuration of the CDK Dialog becomes mandatory and other options that would result in incompliance have been disabled.
96
+
97
+
### Setup
98
+
99
+
You can use the `NgxModalService` without any prior setup, but the `ngx-inform` package does provide the ability to provide a global configuration that can be applied for all modals. On top of that, you can provide default modals with your specific configuration.
100
+
101
+
```ts
102
+
provideNgxModalConfiguration({
103
+
closeOnNavigation: true,
104
+
autoClose: true
105
+
modals: {
106
+
confirm: {
107
+
component: ConfirmModalComponent,
108
+
role: 'alertdialog',
109
+
panelClass: 'panel-confirm',
110
+
},
111
+
},
112
+
}),
113
+
```
114
+
115
+
Using the above configuration, we can set several properties that will be applied to the modals globally. These properties are:
| closeOnNavigation | Whether the modal closes on navigation, by default this is `true`|
119
+
| direction | The reading direction of the modal. |
120
+
| hasBackdrop | Whether or not we wish to set a backdrop, by default this is `true`. |
121
+
| panelClass | A class set to the `overlay` element |
122
+
| autoClose | Whether the modal automatically closes after the initial interaction emitted by the `action` output. By default this is `true`. |
123
+
124
+
On top of that, by passing a `modals` record, we can define a set preset modals we can use throughout the entire application. We can setup default modals for confirmation, navigating away from a route, etc. Next to overwrites of the global properties above, we can also provide the following properties:
| role | The ARIA role of the modal, either `dialog` or `alertDialog`|
129
+
| component | An implementation of the `NgxModalAbstractComponent`|
130
+
| data | Any data we wish to provide to the component. |
131
+
132
+
### Implementation
133
+
134
+
The `NgxModalService` allows for two ways of opening a modal. Either by opening a predefined modal we set in the configuration, or a custom modal by passing a new modal component.
135
+
136
+
To make the modals ARIA compliant either a `label` or a `labelledById` must be provided. If the role of a modal was set to `alertdialog`, the `describedById` property is also required.
137
+
138
+
When opening a modal we can overwrite all the globally and modal-specific configuration using the same properties as mentioned earlier. On top of that, we can set several other properties. These properties are:
| injector | Injector used for the instantiation of the component to be attached. If provided, takes precedence over the injector indirectly provided by ViewContainerRef. |
143
+
| viewContainerRef | Where the attached component should live in Angular's logical component tree. This affects what is available for injection and the change detection order for the component instantiated inside of the dialog. This does not affect where the dialog content will be rendered. |
144
+
| restoreFocus | Whether the dialog should restore focus to the previously-focused element upon closing.|
145
+
| autoFocus | Where the dialog should focus on open. |
146
+
147
+
#### Predefined modal
148
+
149
+
If we set a predefined modal, we can now call said modal using the `open` method on `NgxModalService`.
150
+
151
+
```ts
152
+
this.modalService
153
+
.open<'Confirm'|'Deny'>({
154
+
type: 'confirm',
155
+
describedById: 'confirm-button',
156
+
labelledById: 'confirm-label',
157
+
data: {
158
+
title: 'Please confirm your actions!'
159
+
}
160
+
})
161
+
.pipe(
162
+
tap(action=> {
163
+
if(action==='Confirm') {
164
+
// Perform confirm logic
165
+
}
166
+
167
+
// Perform non-confirm logic
168
+
})
169
+
)
170
+
.subscribe();
171
+
```
172
+
#### Custom modal
173
+
174
+
We can always create a custom modal for feature-specific use-cases. We do this by providing a component.
0 commit comments