@filip.mazev/modal 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## Features
8
8
 
9
- * Service-Driven: Open and close modals from anywhere in your application using GenericModalService.
9
+ * Service-Driven: Open and close modals from anywhere in your application using ModalService.
10
10
  * Flexible Layouts: Supports center, left, and right positioning.
11
11
  * Mobile Optimized: Native-feeling swipe-to-close gestures for mobile devices.
12
12
  * Dynamic Data: Pass data to modal components with full type safety.
@@ -21,7 +21,7 @@ Please install both @filip.mazev/blocks-core and @filip.mazev/modal for propert
21
21
  npm i @filip.mazev/blocks-core@latest @filip.mazev/modal@latest
22
22
  ```
23
23
 
24
- ### 1. Theme Configuration
24
+ ### Theme Configuration
25
25
 
26
26
  To enable the library's stylization, import the theme provider in your global styles (styles.scss):
27
27
 
@@ -54,47 +54,16 @@ Other themes are also available such as:
54
54
  * `$orange-company-light-theme-config`
55
55
  * `$orange-company-dark-theme-config`
56
56
 
57
- ### 2. Register the Service
58
-
59
- In your root component (usually `app.component.ts` or `app.ts`), register the `ViewContainerRef` and `Renderer2` so the service knows where to attach modals:
60
-
61
- ```typescript
62
- import { Component, inject, Renderer2, signal, ViewContainerRef } from '@angular/core';
63
- import { RouterOutlet } from '@angular/router';
64
- import { GenericModalService } from '@filip.mazev/modal';
65
-
66
- @Component({
67
- selector: 'app-root',
68
- imports: [
69
- RouterOutlet
70
- ],
71
- templateUrl: './app.html',
72
- styleUrl: './app.scss'
73
- })
74
- export class App {
75
- protected readonly title = signal('Your App Name');
76
-
77
- private viewContainerRef = inject(ViewContainerRef);
78
- private renderer2 = inject(Renderer2);
79
-
80
- private modals = inject(GenericModalService);
81
-
82
- constructor() {
83
- this.modals.register(this.viewContainerRef, this.renderer2);
84
- }
85
- }
86
- ```
87
-
88
57
  ## Usage
89
58
 
90
- ### 1. Create a Modal Component
59
+ ### Create a Modal Component
91
60
 
92
- Your modal content components must extend `GenericModal<TData, TResult>`:
61
+ Your modal content components must extend `IModal<TData, TResult>`:
93
62
 
94
63
  Typescript:
95
64
 
96
65
  ```typescript
97
- import { GenericModal, GENERIC_MODAL_DATA, ModalHeaderDirective, ModalFooterDirective } from '@filip.mazev/modal';
66
+ import { Modal, ModalHeaderDirective, ModalFooterDirective } from '@filip.mazev/modal';
98
67
 
99
68
  @Component({
100
69
  selector: 'app-my-modal-component',
@@ -105,20 +74,8 @@ import { GenericModal, GENERIC_MODAL_DATA, ModalHeaderDirective, ModalFooterDire
105
74
  templateUrl: './my-modal-component.html',
106
75
  styleUrl: './my-modal-component.scss',
107
76
  })
108
- export class MyModalComponent extends GenericModal<MyData, MyResult> {
109
- protected data = inject<MyData>(GENERIC_MODAL_DATA);
110
-
111
- constructor() {
112
- super();
113
- }
77
+ export class MyModalComponent extends Modal<MyData, MyResult> {
114
78
 
115
- override afterModalGet(): void {
116
- // This is called after the modal service has returned the instance of the generated modal to this component. You can access this.modal only after this
117
- }
118
-
119
- override onDestroy(): void {
120
- // Perform onDestroy logic here as this method is called on ngOnDestroy on GenericModal
121
- }
122
79
  }
123
80
  ```
124
81
 
@@ -129,18 +86,22 @@ HTML (Template):
129
86
  Example Header
130
87
  </div>
131
88
 
132
- <div>
133
- Lorem ipsum dolor sit, amet consectetur adipisicing elit. A, iste voluptatum accusamus facere explicabo impedit exercitationem dolore...
134
- </div>
89
+ <h1>
90
+ {{ data.Title }}
91
+ </h1>
92
+
93
+ <p>
94
+ {{ data.Body }}
95
+ </p>
135
96
 
136
97
  <div *modalFooter>
137
98
  Example Footer
138
99
  </div>
139
100
  ```
140
101
 
141
- ### About `GenericModalRef<D, R>`
102
+ ### About `ModalRef<D, R>`
142
103
 
143
- Accessible via this.modal inside any component that extends GenericModal. This reference provides programmatic control over the active modal instance, access to its configuration, and observable streams for its lifecycle events.
104
+ Accessible via this.modal inside any component that extends Modal. This reference provides programmatic control over the active modal instance, access to its configuration, and observable streams for its lifecycle events.
144
105
 
145
106
  #### Methods
146
107
 
@@ -148,19 +109,18 @@ Accessible via this.modal inside any component that extends GenericModal. This r
148
109
  * `state` (ModalCloseMode): The state of the closing action (e.g., 'confirm' or 'cancel'). Defaults to 'cancel'.
149
110
  * `result` (R): Optional data to return to the component that opened the modal.
150
111
  * `forceClose` (boolean): If true, bypasses any confirmCloseConfig checks or guards. Defaults to false.
151
- * `modalState$()`: Returns an `Observable<GenericModalState>`. Emits the current lifecycle state of the modal (OPENING, OPEN, CLOSING, CLOSED).
112
+ * `modalState$()`: Returns an `Observable<ModalState>`. Emits the current lifecycle state of the modal (OPENING, OPEN, CLOSING, CLOSED).
152
113
  * `backdropClick()`: Returns an `Observable<MouseEvent>`. Emits an event whenever the user clicks on the modal's backdrop.
153
- * `afterClosed()`: Returns an `Observable<IGenericCloseResult<R>>`. Emits the final result object (containing the state and data) once the modal has fully closed and animations have finished.
114
+ * `afterClosed()`: Returns an `Observable<IModalCloseResult<R>>`. Emits the final result object (containing the state and data) once the modal has fully closed and animations have finished.
154
115
 
155
116
  #### Properties
156
117
 
157
- * `modalConfig: (GenericModalConfig<D> | undefined)` Access to the configuration object used to open this modal. Useful for retrieving custom options or identifying the modal.
118
+ * `modalConfig: (ModalConfig<D> | undefined)` Access to the configuration object used to open this modal. Useful for retrieving custom options or identifying the modal.
158
119
  * `componentRef: (ComponentRef<C>)` The Angular ComponentRef of the content component (your component) inside the modal.
159
- * `modalContainerRef: (ComponentRef<GenericModalComponent>)` The Angular ComponentRef of the wrapper container (the shell responsible for the backdrop, animations, and layout).
120
+ * `modalContainerRef: (ComponentRef<ModalComponent>)` The Angular ComponentRef of the wrapper container (the shell responsible for the backdrop, animations, and layout).
160
121
  * `modalContainerElement: (HTMLElement)` The native HTML element of the modal container.
161
- * `selfIdentifier: ({ constructor: Function })` An object identifying the constructor of the component, used internally for instance tracking.
162
122
 
163
- #### `IGenericCloseResult`
123
+ #### `IModalCloseResult`
164
124
 
165
125
  The structure of the object returned when a modal closes, accessible via the observable from afterClosed(). Contains:
166
126
 
@@ -169,23 +129,22 @@ The structure of the object returned when a modal closes, accessible via the obs
169
129
 
170
130
  ### 2. Opening the Modal
171
131
 
172
- Use the GenericModalService to launch your component:
132
+ Use the ModalService to launch your component:
173
133
 
174
134
  ```typescript
175
- private modals = inject(GenericModalService);
135
+ private modals = inject(ModalService);
176
136
 
177
137
  ...
178
138
 
179
139
  const modalRef = this.modals.open<MyData, MyResult>(MyModalComponent, {
180
140
  data: { id: 1 }, // Must be of the type specified in MyData
181
141
  style: {
182
- position: 'right', // Slide in from the right (left and center are also available options)
183
- handleMobile: true, // True by default, means that on smaller screens the modal will automatically go into a bottom sheet view
142
+ layout: 'right', // Slide in from the right (left and center are also available options)
184
143
  },
185
144
  bannerText: 'Modal Title Here'
186
145
  });
187
146
 
188
- modalRef.afterClosed().subscribe(result: IGenericCloseResult<MyData> => {
147
+ modalRef.afterClosed().subscribe(result: IModalCloseResult<MyData> => {
189
148
  // result.state can be 'confirm' or 'cancel'
190
149
  console.log('Modal closed with action:', result.state);
191
150
 
@@ -198,20 +157,21 @@ modalRef.afterClosed().subscribe(result: IGenericCloseResult<MyData> => {
198
157
 
199
158
  ## Configuration Options
200
159
 
201
- ### `IGenericModalConfig`
160
+ ### `IModalConfig`
202
161
 
203
162
  Controls the behavior and content of the modal container:
204
163
 
205
164
  * `open` |`boolean`|: (optional) Whether the modal should be open or not, will default to true.
206
- * `afterClose` |``Function``|: (optional) The function to run after the modal closes.
207
- * `confirmCloseConfig` |``IGenericConfirmCloseConfig<ConfirmComponentData, ConfirmComponent>``|: (optional) The configuration for the confirm close modal (e.g., a "Discard changes?" prompt), will default to `{ confirmClose: false }`. `ConfirmComponentData and ConfirmComponent` need to be specified.
165
+ * `afterClose` |`Function`|: (optional) The function to run after the modal closes.
166
+ * `closeGuard` |`ModalCloseGuard`| (optional) The guard that will determine whether the modal can be closed or not
167
+ * `closeGuardOnlyOnCancel` |`boolean`| (optional) Whether the close guard should only be checked on cancel actions, will default to true
208
168
  * `disableClose` |`boolean`|: (optional) Whether the modal should be closable or not, will default to false. This applies to the close button, escape key, and backdrop.
209
169
  * `disableCloseOnBackdropClick` |`boolean`|: (optional) Whether the modal shouldn't be closable specifically when the user clicks on the backdrop, will default to false.
210
170
  * `disableCloseOnNavigation` |`boolean`|: (optional) Whether the modal should remain open when the user navigates away from the current page, will default to false.
211
171
  * `enableExtremeOverflowHandling` |`boolean`|: (optional) Whether the modal should enable extreme overflow handling for complex scrolling scenarios (may cause issues with keypress registration), will default to false.
212
172
  * `webkitOnlyOverflowMobileHandling` |`boolean`|: (optional) Whether the modal should only handle overflow for webkit browsers on mobile or for all browsers, will default to true. Webkite sometimes handles `overflow: hidden` poorly, this will ensure that scrolling is disabled totally for everything that is not within the modal while it is open.
213
- * `data` |`TData`|: (optional) The data to pass to the component of the modal. The component needs to use the @Inject(GENERIC_MODAL_DATA) or `data = inject<string>(GENERIC_MODAL_DATA);` (modern syntax) decorator to receive this.
214
- * `style` |`IGenericModalStyleConfig`|: (optional) The visual style configuration for the modal (position, backdrop, etc.), will default to an empty object.
173
+ * `data` |`TData`|: (optional) The data to pass to the component of the modal. The component needs to use the @Inject(MODAL_DATA) or `data = inject<string>(MODAL_DATA);` (modern syntax) decorator to receive this.
174
+ * `style` |`IModalStyleConfig`|: (optional) The visual style configuration for the modal (layout, backdrop, etc.), will default to an empty object.
215
175
  * `bannerText` |`string`|: (optional) The text to display in the header banner of the modal.
216
176
  * `contentClasses` |`string`|: (optional) Custom CSS classes to apply directly to the content container of the modal.
217
177
  * `contentStyles` |`string`|: (optional) Inline CSS styles to apply directly to the content container of the modal.
@@ -219,37 +179,25 @@ Controls the behavior and content of the modal container:
219
179
  * `disableConsoleInfo` |`boolean`|: (optional) Whether to suppress library info logs in the console, will default to false.
220
180
  * `id` |`string`|: (optional) The unique identifier of the modal, will default to a random string if not provided.
221
181
 
222
- ### `IGenericModalStyleConfig`
182
+ ### `IModalStyleConfig`
223
183
 
224
184
  Controls the visual appearance:
225
185
 
226
- * `position` |`ModalPoistion`|: (optional) The position of the modal (can be 'center', 'left', or 'right'), will default to 'center'.
227
- * `handleMobile` |`boolean`|: (optional) Whether the modal should automatically switch to a mobile configuration (swipeable sheet) when the screen width drops below a certain breakpoint.
186
+ * `layout` |`ModalLayout`|: (optional) The layout of the modal (can be 'center', 'left', 'right' or 'bottom-sheet'), will default to 'center'.
187
+ * `breakpoints` |`Partial<Record<BreakpointKey, ModalLayout>>`|: (optional) The breakpoints for responsive layouts, will default to undefined.
228
188
  * `animate` |`boolean`|: (optional) Whether the modal should have open/close animations or not, will default to true.
229
189
  * `hasBackdrop` |`boolean`|: (optional) Whether the modal should have a dimmed backdrop or not, will default to true.
230
- * `closeDelay` |`number`|: (optional) The delay in milliseconds before the modal actually closes after the close action is triggered, will default to `GENERIC_MODAL_DEFAULT_ANIM_DURATION` = 175.
190
+ * `closeDelay` |`number`|: (optional) The delay in milliseconds before the modal actually closes after the close action is triggered, will default to `MODAL_DEFAULT_ANIM_DURATION` = 175.
231
191
  * `showCloseButton` |`boolean`|: (optional) Whether the modal should show a close button or not, will default to true.
232
- * `mobileConfig` |`IGenericSwipeableModalConfig`|: (optional) The configuration for the swipeable modal (swipe limits, height), will default to an empty object.
192
+ * `mobileConfig` |`IBottomSheetModalConfig`|: (optional) The configuration for the bottom sheet modal (swipe limits, height), will default to an empty object.
233
193
  * `contentWrapper` |`boolean`|: (optional) Whether the content should be wrapped in a default-styled container (providing padding/background) or not, will default to true.
234
194
  * `wrapperClasses` |`string`|: (optional) Custom CSS classes to apply to the wrapper of the modal.
235
195
  * `wrapperStyles` |`string`|: (optional) Inline CSS styles to apply to the wrapper of the modal.
236
196
  * `overrideFullHeight` |`boolean`|: (optional) Whether the modal should override the default full-height restriction or not, will default to false.
237
197
 
238
- ### `IGenericConfirmCloseConfig`
239
-
240
- Configuration for the confirmation modal triggered when a user attempts to close the parent modal (e.g., "Unsaved Changes"):
241
-
242
- * `confirmModalComponent` |`ComponentType<ConfirmComponent>`|: (required) The component class to use for the confirmation modal.
243
- * `confirmClose` |`boolean`|: (required) Whether the confirmation flow should be active. If false, the modal closes immediately without confirmation.
244
- * `confirmOnSubmit` |`boolean`|: (optional) Whether the confirmation should also trigger when the modal is closed via a "submit" (success) action. Defaults to false (meaning confirmation is only required for 'cancel' or backdrop closure).
245
- * `style` |`IGenericModalStyleConfig`|: (optional) The visual style configuration for the confirmation modal instance.
246
- * `data` |`ConfirmComponentData`|: (optional) The data to pass to the confirmation component. The component needs to use the @Inject(GENERIC_MODAL_DATA) decorator to receive this.
247
- * `bannerText` |`string`|: (optional) The text to display in the header banner of the confirmation modal.
248
- * `bypassSelfCheck` |`boolean`|: (optional) Whether the modal should bypass the internal check that ensures the confirmation is attached to the specific closing modal. Defaults to false.
249
-
250
- ### `IGenericSwipeableModalConfig`
198
+ ### `IBottomSheetModalConfig`
251
199
 
252
- Configuration for the mobile-optimized swipeable modal (bottom sheet):
200
+ Configuration for the mobile-optimized bottom sheet modal (bottom sheet):
253
201
 
254
202
  * `downSwipeLimit` |`number`|: (optional) The threshold factor for swiping downwards to close the modal. Determines how far the user must swipe down before the modal closes automatically. (calculated as windowHeight / downSwipeLimit).
255
- * `customHeight` |`number`|: (optional) A specific maximum height (in pixels) for the swipeable modal. If provided, this overrides the default dynamic height behavior.
203
+ * `customHeight` |`number`|: (optional) A specific maximum height (in pixels) for the bottom sheet modal. If provided, this overrides the default dynamic height behavior.