src/notification/actionable-notification.component.ts
Actionable notification allows for interactive elements within a notification. There are two variants offered, inline & toast.
selector | cds-actionable-notification, ibm-actionable-notification |
template |
|
constructor(notificationDisplayService: NotificationDisplayService, i18n: I18n)
|
|||||||||
Parameters :
|
notificationObj | |
Type : ActionableContent
|
|
Can have
|
close | |
Type : EventEmitter<any>
|
|
Inherited from
BaseNotification
|
|
Defined in
BaseNotification:41
|
|
Emits on close. |
attr.aria-labelledBy |
Type : string
|
Default value : this.notificationID
|
class.cds--actionable-notification |
Type : boolean
|
Default value : true
|
class.cds--actionable-notification--error |
Type : boolean
|
class.cds--actionable-notification--hide-close-button |
Type : boolean
|
class.cds--actionable-notification--info |
Type : boolean
|
class.cds--actionable-notification--info-square |
Type : boolean
|
class.cds--actionable-notification--low-contrast |
Type : any
|
class.cds--actionable-notification--success |
Type : boolean
|
class.cds--actionable-notification--toast |
Type : boolean
|
class.cds--actionable-notification--warning |
Type : boolean
|
class.cds--actionable-notification--warning-alt |
Type : boolean
|
attr.role |
Type : string
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:34
|
Set role attribute for component
|
destroy |
destroy()
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:90
|
Returns :
void
|
onClick | ||||||
onClick(action, event)
|
||||||
Inherited from
BaseNotification
|
||||||
Defined in
BaseNotification:79
|
||||||
Parameters :
Returns :
void
|
onClose |
onClose()
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:75
|
Emits close event.
Returns :
void
|
defaultNotificationObj |
Type : object
|
Default value : {
...this.defaultNotificationObj,
variant: "inline" as NotificationVariants,
role: "alertdialog"
}
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:106
|
Set default variant & role, alternatives can be provided through notificationObj property |
notificationClass |
Default value : true
|
Decorators :
@HostBinding('class.cds--actionable-notification')
|
Private Static notificationCount |
Type : number
|
Default value : 0
|
notificationID |
Default value : `actionable-notification-${ActionableNotification.notificationCount++}`
|
notificationLabel |
Default value : this.notificationID
|
Decorators :
@HostBinding('attr.aria-labelledBy')
|
Protected _notificationObj |
Type : NotificationContent
|
Default value : Object.assign({}, this.defaultNotificationObj)
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:65
|
componentRef |
Type : ComponentRef<BaseNotification>
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:44
|
Readonly iconDictionary |
Type : object
|
Default value : {
"error": "error--filled",
"info": "information--filled",
"info-square": "information--square--filled",
"success": "checkmark--filled",
"warning": "warning--filled",
"warning-alt": "warning--alt--filled"
}
|
Inherited from
BaseNotification
|
Defined in
BaseNotification:47
|
notificationObj | ||||||
getnotificationObj()
|
||||||
Can have
Returns :
ActionableContent
|
||||||
setnotificationObj(obj: ActionableContent)
|
||||||
Parameters :
Returns :
void
|
toastVariant |
gettoastVariant()
|
isError |
getisError()
|
isInfo |
getisInfo()
|
isInfoSquare |
getisInfoSquare()
|
isSuccess |
getisSuccess()
|
isWarning |
getisWarning()
|
isWarningAlt |
getisWarningAlt()
|
isLowContrast |
getisLowContrast()
|
isCloseHidden |
getisCloseHidden()
|
import {
Component,
Input,
HostBinding
} from "@angular/core";
import { isObservable, of } from "rxjs";
import { ActionableContent, NotificationVariants } from "./notification-content.interface";
import { I18n } from "carbon-components-angular/i18n";
import { NotificationDisplayService } from "./notification-display.service";
import { BaseNotification } from "./base-notification.component";
/**
* Actionable notification allows for interactive elements within a notification. There are two variants offered, inline & toast.
*
* [See demo](../../?path=/story/components-notification--actionable-notification)
*/
@Component({
selector: "cds-actionable-notification, ibm-actionable-notification",
template: `
<div class="cds--actionable-notification__details">
<svg
[cdsIcon]="iconDictionary[notificationObj.type]"
size="20"
*ngIf="notificationObj.type"
[ngClass]="{
'cds--inline-notification__icon': notificationObj.variant === 'inline',
'cds--toast-notification__icon': notificationObj.variant === 'toast'
}"
class="cds--actionable-notification__icon">
</svg>
<div class="cds--actionable-notification__text-wrapper">
<div class="cds--actionable-notification__content">
<div
cdsActionableTitle
*ngIf="!notificationObj.template"
[id]="notificationID"
[innerHTML]="notificationObj.title">
</div>
<div *ngIf="!notificationObj.template" cdsActionableSubtitle>
<span [innerHTML]="notificationObj.message"></span>
<ng-container *ngFor="let link of notificationObj.links">
<a cdsLink [href]="link.href">{{link.text}}</a>
</ng-container>
</div>
<ng-container *ngTemplateOutlet="notificationObj.template; context: { $implicit: notificationObj }"></ng-container>
</div>
</div>
</div>
<ng-container *ngIf="!notificationObj.actionsTemplate">
<button
*ngFor="let action of notificationObj.actions"
(click)="onClick(action, $event)"
[cdsButton]="notificationObj.variant === 'inline' ? 'ghost' : 'tertiary'"
size="sm"
cdsActionableButton>
{{action.text}}
</button>
</ng-container>
<ng-container *ngTemplateOutlet="notificationObj.actionsTemplate; context: { $implicit: notificationObj }"></ng-container>
<button
*ngIf="!isCloseHidden"
(click)="onClose()"
class="cds--actionable-notification__close-button"
[attr.aria-label]="notificationObj.closeLabel | async"
type="button">
<svg cdsIcon="close" size="16" class="cds--actionable-notification__close-icon"></svg>
</button>
`
})
export class ActionableNotification extends BaseNotification {
private static notificationCount = 0;
/**
* Can have `type`, `title`, and `message` members.
*
* `type` can be one of `"error"`, `"info"`, `"info-square"`, `"warning"`, `"warning-alt"`, or `"success"`
*
* `message` is the message to display
*/
@Input() get notificationObj(): ActionableContent {
return this._notificationObj;
}
set notificationObj(obj: ActionableContent) {
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
obj.closeLabel = of(obj.closeLabel);
}
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
}
notificationID = `actionable-notification-${ActionableNotification.notificationCount++}`;
@HostBinding("attr.aria-labelledBy") notificationLabel = this.notificationID;
@HostBinding("class.cds--actionable-notification") notificationClass = true;
@HostBinding("class.cds--actionable-notification--toast") get toastVariant() { return this.notificationObj.variant === "toast"; }
@HostBinding("class.cds--actionable-notification--error") get isError() { return this.notificationObj.type === "error"; }
@HostBinding("class.cds--actionable-notification--info") get isInfo() { return this.notificationObj.type === "info"; }
@HostBinding("class.cds--actionable-notification--info-square") get isInfoSquare() { return this.notificationObj.type === "info-square"; }
@HostBinding("class.cds--actionable-notification--success") get isSuccess() { return this.notificationObj.type === "success"; }
@HostBinding("class.cds--actionable-notification--warning") get isWarning() { return this.notificationObj.type === "warning"; }
@HostBinding("class.cds--actionable-notification--warning-alt") get isWarningAlt() { return this.notificationObj.type === "warning-alt"; }
@HostBinding("class.cds--actionable-notification--low-contrast") get isLowContrast() { return this.notificationObj.lowContrast; }
@HostBinding("class.cds--actionable-notification--hide-close-button") get isCloseHidden() { return !this._notificationObj.showClose; }
/**
* Set default variant & role, alternatives can be provided through notificationObj property
*/
defaultNotificationObj = {
...this.defaultNotificationObj,
variant: "inline" as NotificationVariants,
role: "alertdialog"
};
constructor(protected notificationDisplayService: NotificationDisplayService, protected i18n: I18n) {
super(notificationDisplayService, i18n);
}
}