mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-16 13:25:13 +00:00
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { inject, Injectable } from '@angular/core';
|
|
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
|
|
import { FuseConfirmationConfig } from '@fuse/services/confirmation/confirmation.types';
|
|
import { FuseConfirmationDialogComponent } from '@fuse/services/confirmation/dialog/dialog.component';
|
|
import { merge } from 'lodash-es';
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
export class FuseConfirmationService
|
|
{
|
|
private _matDialog: MatDialog = inject(MatDialog);
|
|
private _defaultConfig: FuseConfirmationConfig = {
|
|
title : 'Confirm action',
|
|
message : 'Are you sure you want to confirm this action?',
|
|
icon : {
|
|
show : true,
|
|
name : 'heroicons_outline:exclamation-triangle',
|
|
color: 'warn',
|
|
},
|
|
actions : {
|
|
confirm: {
|
|
show : true,
|
|
label: 'Confirm',
|
|
color: 'warn',
|
|
},
|
|
cancel : {
|
|
show : true,
|
|
label: 'Cancel',
|
|
},
|
|
},
|
|
dismissible: false,
|
|
};
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
constructor()
|
|
{
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
open(config: FuseConfirmationConfig = {}): MatDialogRef<FuseConfirmationDialogComponent>
|
|
{
|
|
// Merge the user config with the default config
|
|
const userConfig = merge({}, this._defaultConfig, config);
|
|
|
|
// Open the dialog
|
|
return this._matDialog.open(FuseConfirmationDialogComponent, {
|
|
autoFocus : false,
|
|
disableClose: !userConfig.dismissible,
|
|
data : userConfig,
|
|
panelClass : 'fuse-confirmation-dialog-panel',
|
|
});
|
|
}
|
|
}
|