Skip to content

Commit 291ca4d

Browse files
committed
update modal service to catch deprecated props
1 parent 848d065 commit 291ca4d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/modal/alert-modal.interface.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
export enum AlertModalType {
2+
default = "default",
3+
danger = "danger"
4+
}
5+
16
export interface AlertModalData {
27
/**
38
* Use of `modalType` is deprecated, use `type` instead
@@ -6,7 +11,7 @@ export interface AlertModalData {
611
/**
712
* type of the modal
813
*/
9-
type?: "default" | "danger";
14+
type?: AlertModalType;
1015
/**
1116
* Use of `modalLabel` is deprecated, use `label` instead
1217
*/

src/modal/modal.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ export class ModalService {
8888
* @memberof ModalService
8989
*/
9090
show(data: AlertModalData) {
91+
for (let key of Object.keys(data)) {
92+
if (["modalType", "modalLabel", "modalTitle", "modalContent"].includes(key)) {
93+
try {
94+
throw new Error(`${key} is deprecated, use ${key.replace("modal", "").toLowerCase()} instead`);
95+
} catch (error) {
96+
console.warn(error);
97+
}
98+
}
99+
}
91100
return this.create({
92101
component: AlertModalComponent,
93102
inputs: {

src/modal/modal.stories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ModalModule } from "../";
77
import { Component, Input, Inject } from "@angular/core";
88
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
99
import { Modal, ModalService } from "../";
10-
import { ModalButton } from "./alert-modal.interface";
10+
import { ModalButton, AlertModalType } from "./alert-modal.interface";
1111

1212
@Modal()
1313
@Component({
@@ -61,7 +61,7 @@ class ModalStory {
6161
`
6262
})
6363
class AlertModalStory {
64-
@Input() modalType: any;
64+
@Input() modalType: AlertModalType;
6565
@Input() modalLabel: string;
6666
@Input() modalTitle: string;
6767
@Input() modalContent: string;
@@ -71,7 +71,7 @@ class AlertModalStory {
7171

7272
openModal() {
7373
this.modalService.show({
74-
type: this.modalType,
74+
modalType: this.modalType,
7575
label: this.modalLabel,
7676
title: this.modalTitle,
7777
content: this.modalContent,

0 commit comments

Comments
 (0)