|
| 1 | +import { Component, EventEmitter, Input, Output } from '@angular/core' |
| 2 | +import { DomSanitizer } from '@angular/platform-browser' |
| 3 | +import { |
| 4 | + NgClass, |
| 5 | + NgFor, |
| 6 | + NgSwitch, |
| 7 | + NgSwitchCase, |
| 8 | + NgSwitchDefault, |
| 9 | +} from '@angular/common' |
| 10 | +import { MatButtonModule } from '@angular/material/button' |
| 11 | +import { |
| 12 | + ActionSurfaceComponent, |
| 13 | + ActionSurfaceContainerComponent, |
| 14 | + BrandSecondaryDarkButtonDirective, |
| 15 | + UnderlineButtonDirective, |
| 16 | +} from '@orcid/ui' |
| 17 | + |
| 18 | +export type RegistryNotificationButtonVariant = 'text' | 'flat' | 'stroked' |
| 19 | + |
| 20 | +export interface RegistryNotificationAction { |
| 21 | + id?: string |
| 22 | + label: string |
| 23 | + variant?: RegistryNotificationButtonVariant |
| 24 | + color?: 'primary' | 'accent' | 'warn' |
| 25 | + underline?: boolean |
| 26 | + disabled?: boolean |
| 27 | +} |
| 28 | + |
| 29 | +export interface RegistryPermissionNotification { |
| 30 | + id?: string |
| 31 | + text: string |
| 32 | + icon?: string |
| 33 | + iconColor?: string |
| 34 | + actions: RegistryNotificationAction[] |
| 35 | +} |
| 36 | + |
| 37 | +export interface RegistryNotificationActionEvent { |
| 38 | + notificationIndex: number |
| 39 | + actionIndex: number |
| 40 | + notificationId?: string |
| 41 | + actionId?: string |
| 42 | + action: RegistryNotificationAction |
| 43 | +} |
| 44 | + |
| 45 | +@Component({ |
| 46 | + selector: 'orcid-registry-permission-notifications', |
| 47 | + standalone: true, |
| 48 | + imports: [ |
| 49 | + NgClass, |
| 50 | + NgFor, |
| 51 | + NgSwitch, |
| 52 | + NgSwitchCase, |
| 53 | + NgSwitchDefault, |
| 54 | + MatButtonModule, |
| 55 | + ActionSurfaceComponent, |
| 56 | + ActionSurfaceContainerComponent, |
| 57 | + BrandSecondaryDarkButtonDirective, |
| 58 | + UnderlineButtonDirective, |
| 59 | + ], |
| 60 | + templateUrl: './permission-notifications.component.html', |
| 61 | + styleUrls: ['./permission-notifications.component.scss'], |
| 62 | +}) |
| 63 | +export class PermissionNotificationsComponent { |
| 64 | + @Input() title = '' |
| 65 | + @Input() subtitle = '' |
| 66 | + @Input() notifications: RegistryPermissionNotification[] = [] |
| 67 | + |
| 68 | + @Output() actionClicked = new EventEmitter<RegistryNotificationActionEvent>() |
| 69 | + |
| 70 | + constructor(private _sanitizer: DomSanitizer) {} |
| 71 | + |
| 72 | + getTrustedHtml(text: string) { |
| 73 | + return this._sanitizer.bypassSecurityTrustHtml(text) |
| 74 | + } |
| 75 | + |
| 76 | + get visibleNotifications(): RegistryPermissionNotification[] { |
| 77 | + return (this.notifications || []).slice(0, 3) |
| 78 | + } |
| 79 | + |
| 80 | + onActionClick( |
| 81 | + notification: RegistryPermissionNotification, |
| 82 | + notificationIndex: number, |
| 83 | + action: RegistryNotificationAction, |
| 84 | + actionIndex: number |
| 85 | + ): void { |
| 86 | + this.actionClicked.emit({ |
| 87 | + notificationIndex, |
| 88 | + actionIndex, |
| 89 | + notificationId: notification.id, |
| 90 | + actionId: action.id, |
| 91 | + action, |
| 92 | + }) |
| 93 | + } |
| 94 | +} |
0 commit comments