-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfirm-dialog.component.ts
More file actions
87 lines (82 loc) · 3.17 KB
/
confirm-dialog.component.ts
File metadata and controls
87 lines (82 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Component, Input, TemplateRef } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common';
import { ConfirmDialog } from 'primeng/confirmdialog';
import { Button } from 'primeng/button';
import { PrimeTemplate } from 'primeng/api';
export type ConfirmDialogSize = 'sm' | 'default' | 'lg' | 'xlg';
export type ConfirmDialogSeverity = 'success' | 'info' | 'warn' | 'help' | 'danger' | 'default';
@Component({
selector: 'confirm-dialog',
host: { style: 'display: contents' },
standalone: true,
imports: [ConfirmDialog, Button, PrimeTemplate, NgTemplateOutlet],
template: `
<p-confirmDialog [key]="key" [styleClass]="computedClass" appendTo="body">
<ng-template pTemplate="headless" let-message let-onAccept="onAccept" let-onReject="onReject">
@if (headerTemplate) {
<ng-container [ngTemplateOutlet]="headerTemplate"
[ngTemplateOutletContext]="{ $implicit: message, onAccept, onReject }">
</ng-container>
} @else {
<div class="p-dialog-header">
<div class="p-dialog-title">
<i [class]="message.icon"></i>
<span>{{ message.header }}</span>
</div>
<button
class="p-button p-component p-button-icon-only p-button-rounded p-button-text p-dialog-close-button"
type="button"
(click)="onReject()"
>
<span class="p-button-icon ti ti-x"></span>
</button>
</div>
}
<div class="p-dialog-content">
<p>{{ message.message }}</p>
</div>
@if (footerTemplate) {
<ng-container [ngTemplateOutlet]="footerTemplate"
[ngTemplateOutletContext]="{ $implicit: message, onAccept, onReject }">
</ng-container>
} @else {
<div class="p-dialog-footer">
<p-button
[label]="message.rejectLabel"
variant="text"
(onClick)="onReject()"
></p-button>
<p-button
[label]="message.acceptLabel"
[severity]="message.acceptButtonProps?.severity"
(onClick)="onAccept()"
></p-button>
</div>
}
</ng-template>
</p-confirmDialog>
`,
})
export class ConfirmDialogComponent {
@Input() key = '';
@Input() size: ConfirmDialogSize = 'default';
@Input() severity: ConfirmDialogSeverity = 'default';
@Input() headerTemplate: TemplateRef<any> | null = null;
@Input() footerTemplate: TemplateRef<any> | null = null;
get computedClass(): string {
const classes: string[] = [];
if (this.size === 'sm') classes.push('p-confirmdialog-sm');
else if (this.size === 'lg') classes.push('p-confirmdialog-lg');
else if (this.size === 'xlg') classes.push('p-confirmdialog-xlg');
const severityMap: Record<ConfirmDialogSeverity, string> = {
success: 'p-confirm-dialog-accept',
info: 'p-confirm-dialog-info',
warn: 'p-confirm-dialog-warn',
help: 'p-confirm-dialog-help',
danger: 'p-confirm-dialog-error',
default: '',
};
if (severityMap[this.severity]) classes.push(severityMap[this.severity]);
return classes.join(' ');
}
}