Skip to content

Commit 55c937f

Browse files
authored
Merge pull request #171 from cal-smith/a11y
fix for alert modal not having useful types
2 parents 37be1b7 + 291ca4d commit 55c937f

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

.storybook/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
77
"lib": [
8-
"es2015",
8+
"es2016",
99
"dom"
1010
],
1111
"sourceMap": true,

src/modal/alert-modal.interface.ts

Lines changed: 16 additions & 2 deletions
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
*/
@@ -37,6 +42,15 @@ export interface AlertModalData {
3742
buttons?: Array<ModalButton>;
3843
}
3944

45+
export enum ModalButtonType {
46+
primary = "primary",
47+
secondary = "secondary",
48+
tertiary = "tertiary",
49+
ghost = "ghost",
50+
danger = "danger",
51+
danger_primary = "danger--primary"
52+
}
53+
4054
export interface ModalButton {
4155
/**
4256
* Display value of the button
@@ -45,7 +59,7 @@ export interface ModalButton {
4559
/**
4660
* Button type
4761
*/
48-
type: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger--primary";
62+
type: ModalButtonType;
4963
/**
5064
* Callback for the button `click` event
5165
*/

src/modal/modal.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// modules
22
import {
33
NgModule,
4-
ComponentFactoryResolver,
54
Optional,
65
SkipSelf
76
} from "@angular/core";
87
import { CommonModule } from "@angular/common";
98
import { TranslateModule } from "@ngx-translate/core";
10-
import { StaticIcon, StaticIconModule } from "./../icon/static-icon.module";
9+
import { StaticIconModule } from "./../icon/static-icon.module";
1110

1211
// imports
1312
import { ModalPlaceholderComponent } from "./modal-placeholder.component";
@@ -23,6 +22,7 @@ import { ButtonModule } from "../forms/forms.module";
2322
// exports
2423
export { default as Modal } from "./modal.decorator";
2524
export { ModalService } from "./modal.service";
25+
export * from "./alert-modal.interface";
2626

2727
// either provides a new instance of ModalPlaceholderService, or returns the parent
2828
export function MODAL_PLACEHOLDER_SERVICE_PROVIDER_FACTORY(parentService: ModalPlaceholderService) {

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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, AlertModalType } from "./alert-modal.interface";
1011

1112
@Modal()
1213
@Component({
@@ -60,20 +61,20 @@ class ModalStory {
6061
`
6162
})
6263
class AlertModalStory {
63-
@Input() modalType: string;
64+
@Input() modalType: AlertModalType;
6465
@Input() modalLabel: string;
6566
@Input() modalTitle: string;
6667
@Input() modalContent: string;
67-
@Input() buttons: any;
68+
@Input() buttons: Array<ModalButton>;
6869

6970
constructor(private modalService: ModalService) { }
7071

7172
openModal() {
7273
this.modalService.show({
7374
modalType: this.modalType,
74-
modalLabel: this.modalLabel,
75-
modalTitle: this.modalTitle,
76-
modalContent: this.modalContent,
75+
label: this.modalLabel,
76+
title: this.modalTitle,
77+
content: this.modalContent,
7778
buttons: this.buttons
7879
});
7980
}

tsconfig-aot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"declaration": true,
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
7-
"lib": ["es2015", "dom"],
7+
"lib": ["es2016", "dom"],
88
"sourceMap": true,
99
"module": "es2015",
1010
"moduleResolution": "node",

tsconfig-demo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"declaration": true,
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
7-
"lib": ["es2015", "dom"],
7+
"lib": ["es2016", "dom"],
88
"sourceMap": true,
99
"mapRoot": "./",
1010
"module": "es2015",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"declaration": true,
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
7-
"lib": ["es2015", "dom"],
7+
"lib": ["es2016", "dom"],
88
"sourceMap": true,
99
"mapRoot": "./",
1010
"module": "es2015",

0 commit comments

Comments
 (0)