Skip to content

Commit b8b6153

Browse files
authored
Merge pull request #162 from cal-smith/modal
fix(modal): refactor modalService.show and add interfaces
2 parents ef584a0 + e11b041 commit b8b6153

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

src/modal/alert-modal.interface.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export interface AlertModalData {
2+
/**
3+
* Use of `modalType` is deprecated, use `type` instead
4+
*/
5+
modalType?: string;
6+
/**
7+
* type of the modal
8+
*/
9+
type?: "default" | "danger";
10+
/**
11+
* Use of `modalLabel` is deprecated, use `label` instead
12+
*/
13+
modalLabel?: string;
14+
/**
15+
* Additional label shown over the modal
16+
*/
17+
label?: string;
18+
/**
19+
* Use of `modalTitle` is deprecated, use `title` instead
20+
*/
21+
modalTitle?: string;
22+
/**
23+
* Primary title for the modal
24+
*/
25+
title?: string;
26+
/**
27+
* Use of `modalContent` is deprecated, use `content` instead
28+
*/
29+
modalContent?: string;
30+
/**
31+
* Content for the modal body, could include HTML tags
32+
*/
33+
content?: string;
34+
/**
35+
* Array of `ModalButton`s
36+
*/
37+
buttons?: Array<ModalButton>;
38+
}
39+
40+
export interface ModalButton {
41+
/**
42+
* Display value of the button
43+
*/
44+
text: string;
45+
/**
46+
* Button type
47+
*/
48+
type: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger--primary" = "primary";
49+
/**
50+
* Callback for the button `click` event
51+
*/
52+
click: function;
53+
}

src/modal/modal.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ModalPlaceholderService } from "./modal-placeholder.service";
1010
import { ReplaySubject } from "rxjs";
1111
import { Injectable } from "@angular/core";
1212
import { AlertModalComponent } from "./alert-modal.component";
13+
import { AlertModalData } from "./alert-modal.interface";
1314

1415

1516
/**
@@ -86,14 +87,14 @@ export class ModalService {
8687
* @returns {ComponentRef<any>}
8788
* @memberof ModalService
8889
*/
89-
show(data: {modalType?: string, modalLabel?: string, modalTitle?: string, modalContent?: string, buttons?: []}) {
90+
show(data: AlertModalData) {
9091
return this.create({
9192
component: AlertModalComponent,
9293
inputs: {
93-
modalType: data.modalType,
94-
modalLabel: data.modalLabel,
95-
modalTitle: data.modalTitle,
96-
modalContent: data.modalContent,
94+
modalType: data.type || data.modalType,
95+
modalLabel: data.label || data.modalLabel,
96+
modalTitle: data.title || data.modalTitle,
97+
modalContent: data.content || data.modalContent,
9798
buttons: data.buttons || []
9899
}
99100
});

0 commit comments

Comments
 (0)