@lhn/mat-alert
Version:
Implementation of MatDialog shown as an alert message
130 lines (119 loc) • 5.86 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/material/dialog'), require('@angular/platform-browser'), require('@angular/common'), require('@angular/material/button')) :
typeof define === 'function' && define.amd ? define('@lhn/mat-alert', ['exports', '@angular/core', '@angular/material/dialog', '@angular/platform-browser', '@angular/common', '@angular/material/button'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lhn = global.lhn || {}, global.lhn["mat-alert"] = {}), global.ng.core, global.ng.material.dialog, global.ng.platformBrowser, global.ng.common, global.ng.material.button));
})(this, (function (exports, core, dialog, platformBrowser, common, button) { 'use strict';
var MatAlertConfig = /** @class */ (function () {
function MatAlertConfig() {
}
return MatAlertConfig;
}());
var MAT_ALERT_DEFAULT_CONFIG = new core.InjectionToken('mat-alert.config');
var matAlertDefaultConfig = {
buttonText: 'Ok',
buttonTheme: null,
raisedButton: false,
autoFocus: true,
};
var MatAlertComponent = /** @class */ (function () {
function MatAlertComponent(data, sanitizer, defaultConfigs) {
this.sanitizer = sanitizer;
data.message = this._handleMessage(data.message);
this.config = Object.assign({}, defaultConfigs, data);
}
/**
* Handles the message and sanitize
*/
MatAlertComponent.prototype._handleMessage = function (message) {
message = message.toString().replace(/(\r\n|\r|\n)/g, '<br/>');
return this.sanitizer.bypassSecurityTrustHtml(message.toString());
};
return MatAlertComponent;
}());
MatAlertComponent.decorators = [
{ type: core.Component, args: [{
selector: 'lhn-mat-alert',
template: "\n <h1 mat-dialog-title>{{config.title}}</h1>\n <mat-dialog-content class=\"mat-typography\" *ngIf=\"config.message\">\n <h4 [innerHTML]=\"config.message\"></h4>\n </mat-dialog-content>\n <mat-dialog-actions align=\"end\">\n <button [class.mat-raised-button]=\"config.raisedButton\"\n [color]=\"config.buttonTheme\"\n mat-button\n mat-dialog-close\n type=\"button\">\n {{config.buttonText}}\n </button>\n </mat-dialog-actions>\n "
},] }
];
MatAlertComponent.ctorParameters = function () { return [
{ type: MatAlertConfig, decorators: [{ type: core.Inject, args: [dialog.MAT_DIALOG_DATA,] }] },
{ type: platformBrowser.DomSanitizer },
{ type: MatAlertConfig, decorators: [{ type: core.Inject, args: [MAT_ALERT_DEFAULT_CONFIG,] }] }
]; };
var MatAlert = /** @class */ (function () {
function MatAlert(dlg, defaultConfigs) {
this.dlg = dlg;
this.defaultConfigs = defaultConfigs;
}
/**
* Opens an alert dialog
*
* @param title Title for the alert
* @param message Message body. Can be an additional description
* @param config Configuration for the alert
* @param disableClose Flag for disable closing the alert clicking outside or pressing Escape
* @return Observable<void> The MatDialog's `afterClosed()` observable
*/
MatAlert.prototype.show = function (title, message, config, disableClose) {
if (message === void 0) { message = ''; }
if (config === void 0) { config = {}; }
if (disableClose === void 0) { disableClose = false; }
var _a;
config.title = title;
config.message = message || '';
var cfg = Object.assign({
minWidth: 300,
data: config,
role: 'alertdialog',
disableClose: disableClose,
hasBackdrop: (_a = config.hasBackdrop) !== null && _a !== void 0 ? _a : true,
}, this.defaultConfigs, config);
return this.dlg.open(MatAlertComponent, cfg).afterClosed();
};
return MatAlert;
}());
MatAlert.decorators = [
{ type: core.Injectable }
];
MatAlert.ctorParameters = function () { return [
{ type: dialog.MatDialog },
{ type: MatAlertConfig, decorators: [{ type: core.Inject, args: [MAT_ALERT_DEFAULT_CONFIG,] }] }
]; };
var ɵ0 = matAlertDefaultConfig;
var MatAlertModule = /** @class */ (function () {
function MatAlertModule() {
}
return MatAlertModule;
}());
MatAlertModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [MatAlertComponent],
entryComponents: [MatAlertComponent],
imports: [
common.CommonModule,
dialog.MatDialogModule,
button.MatButtonModule,
],
providers: [
MatAlert,
{ provide: MAT_ALERT_DEFAULT_CONFIG, useValue: ɵ0 },
],
},] }
];
/*
* Public API Surface of mat-alert
*/
/**
* Generated bundle index. Do not edit.
*/
exports.MatAlert = MatAlert;
exports.MatAlertModule = MatAlertModule;
exports["ɵ0"] = ɵ0;
exports["ɵa"] = MAT_ALERT_DEFAULT_CONFIG;
exports["ɵb"] = matAlertDefaultConfig;
exports["ɵc"] = MatAlertConfig;
exports["ɵd"] = MatAlertComponent;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=lhn-mat-alert.umd.js.map