File

src/notification/notification.component.ts

Description

Notification messages are displayed toward the top of the UI and do not interrupt user’s work.

See demo

Extends

BaseNotification

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings
Accessors

Constructor

constructor(notificationDisplayService: NotificationDisplayService, i18n: I18n)
Parameters :
Name Type Optional
notificationDisplayService NotificationDisplayService No
i18n I18n No

Inputs

notificationObj
Type : NotificationContent

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

Outputs

close
Type : EventEmitter<any>
Inherited from BaseNotification

Emits on close.

HostBindings

attr.id
Type : string
Default value : `notification-${Notification.notificationCount++}`
class.cds--inline-notification
Type : boolean
Default value : true
class.cds--inline-notification--error
Type : boolean
class.cds--inline-notification--hide-close-button
Type : boolean
class.cds--inline-notification--info
Type : boolean
class.cds--inline-notification--info-square
Type : boolean
class.cds--inline-notification--low-contrast
Type : any
class.cds--inline-notification--success
Type : boolean
class.cds--inline-notification--warning
Type : boolean
class.cds--inline-notification--warning-alt
Type : boolean
attr.role
Type : string
Inherited from BaseNotification

Set role attribute for component Status is default for inline-notification & toast component alertdialog is default for actionable-notification

Methods

destroy
destroy()
Inherited from BaseNotification
Returns : void
onClick
onClick(action, event)
Inherited from BaseNotification
Parameters :
Name Optional
action No
event No
Returns : void
onClose
onClose()
Inherited from BaseNotification

Emits close event.

Returns : void

Properties

notificationClass
Default value : true
Decorators :
@HostBinding('class.cds--inline-notification')
Private Static notificationCount
Type : number
Default value : 0
notificationID
Default value : `notification-${Notification.notificationCount++}`
Decorators :
@HostBinding('attr.id')
Protected _notificationObj
Type : NotificationContent
Default value : Object.assign({}, this.defaultNotificationObj)
Inherited from BaseNotification
componentRef
Type : ComponentRef<BaseNotification>
Inherited from BaseNotification
Protected defaultNotificationObj
Type : NotificationContent
Default value : { title: "", message: "", type: "info" as NotificationType, showClose: true, closeLabel: this.i18n.get("NOTIFICATION.CLOSE_BUTTON"), role: "status" }
Inherited from BaseNotification
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

Accessors

notificationObj
getnotificationObj()

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

setnotificationObj(obj: NotificationContent)
Parameters :
Name Type Optional
obj NotificationContent No
Returns : void
isError
getisError()
isInfo
getisInfo()
isInfoSquare
getisInfoSquare()
isSuccess
getisSuccess()
isWarning
getisWarning()
isWarningAlt
getisWarningAlt()
isLowContrast
getisLowContrast()
isCloseHidden
getisCloseHidden()
import {
	Component,
	Input,
	HostBinding
} from "@angular/core";

import { NotificationContent } from "./notification-content.interface";
import { I18n } from "carbon-components-angular/i18n";
import { NotificationDisplayService } from "./notification-display.service";
import { isObservable, of } from "rxjs";
import { BaseNotification } from "./base-notification.component";

/**
 * Notification messages are displayed toward the top of the UI and do not interrupt user’s work.
 *
 * [See demo](../../?path=/story/components-notification--basic)
 */
@Component({
	selector: "cds-notification, cds-inline-notification, ibm-notification, ibm-inline-notification",
	template: `
		<div class="cds--inline-notification__details">
			<svg
				[cdsIcon]="iconDictionary[notificationObj.type]"
				size="20"
				*ngIf="notificationObj.type"
				class="cds--inline-notification__icon">
			</svg>
			<div class="cds--inline-notification__text-wrapper">
				<div *ngIf="!notificationObj.template" cdsNotificationTitle [innerHTML]="notificationObj.title"></div>
				<div *ngIf="!notificationObj.template" cdsNotificationSubtitle>
					<span [innerHTML]="notificationObj.message"></span>
				</div>
				<ng-container *ngTemplateOutlet="notificationObj.template; context: { $implicit: notificationObj}"></ng-container>
			</div>
		</div>
		<button
			*ngIf="!isCloseHidden"
			(click)="onClose()"
			class="cds--inline-notification__close-button"
			[attr.aria-label]="notificationObj.closeLabel | async"
			type="button">
			<svg cdsIcon="close" size="16" class="cds--inline-notification__close-icon"></svg>
		</button>
	`
})
export class Notification 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(): NotificationContent {
		return this._notificationObj;
	}
	set notificationObj(obj: NotificationContent) {
		if (obj.closeLabel && !isObservable(obj.closeLabel)) {
			obj.closeLabel = of(obj.closeLabel);
		}
		this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
	}

	@HostBinding("attr.id") notificationID = `notification-${Notification.notificationCount++}`;
	@HostBinding("class.cds--inline-notification") notificationClass = true;
	@HostBinding("class.cds--inline-notification--error") get isError() { return this.notificationObj.type === "error"; }
	@HostBinding("class.cds--inline-notification--info") get isInfo() { return this.notificationObj.type === "info"; }
	@HostBinding("class.cds--inline-notification--info-square") get isInfoSquare() { return this.notificationObj.type === "info-square"; }
	@HostBinding("class.cds--inline-notification--success") get isSuccess() { return this.notificationObj.type === "success"; }
	@HostBinding("class.cds--inline-notification--warning") get isWarning() { return this.notificationObj.type === "warning"; }
	@HostBinding("class.cds--inline-notification--warning-alt") get isWarningAlt() { return this.notificationObj.type === "warning-alt"; }
	@HostBinding("class.cds--inline-notification--low-contrast") get isLowContrast() { return this.notificationObj.lowContrast; }
	@HostBinding("class.cds--inline-notification--hide-close-button") get isCloseHidden() { return !this.notificationObj.showClose; }

	constructor(protected notificationDisplayService: NotificationDisplayService, protected i18n: I18n) {
		super(notificationDisplayService, i18n);
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""