File

src/notification/toast.component.ts

Description

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

See demo

Extends

BaseNotification

Implements

OnInit

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 : ToastContent

Can have type, title, subtitle, and caption members.

type can be one of "error", "info", "info-square", "warning", "warning-alt", or "success"

Outputs

close
Type : EventEmitter<any>
Inherited from BaseNotification

Emits on close.

HostBindings

attr.id
Type : string
Default value : `toast-${Toast.toastCount++}`
class.cds--toast-notification
Type : boolean
Default value : true
class.cds--toast-notification--error
Type : boolean
class.cds--toast-notification--hide-close-button
Type : boolean
class.cds--toast-notification--info
Type : boolean
class.cds--toast-notification--info-square
Type : boolean
class.cds--toast-notification--low-contrast
Type : any
class.cds--toast-notification--success
Type : boolean
class.cds--toast-notification--warning
Type : boolean
class.cds--toast-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

ngOnInit
ngOnInit()
Returns : void
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

toastClass
Default value : true
Decorators :
@HostBinding('class.cds--toast-notification')
Private Static toastCount
Type : number
Default value : 0
toastID
Default value : `toast-${Toast.toastCount++}`
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()
setnotificationObj(obj: ToastContent)

Can have type, title, subtitle, and caption members.

type can be one of "error", "info", "info-square", "warning", "warning-alt", or "success"

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

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

/**
 * Toast messages are displayed toward the top of the UI and do not interrupt user’s work.
 *
 * [See demo](../../?path=/story/components-notification--toast)
 */
@Component({
	selector: "cds-toast, ibm-toast",
	template: `
		<svg
			[cdsIcon]="iconDictionary[notificationObj.type]"
			size="20"
			*ngIf="notificationObj.type"
			class="cds--toast-notification__icon">
		</svg>
		<div class="cds--toast-notification__details">
			<h3 *ngIf="!notificationObj.template" cdsToastTitle [innerHTML]="notificationObj.title"></h3>
			<div *ngIf="!notificationObj.template" cdsToastSubtitle>
				<span [innerHTML]="notificationObj.subtitle"></span>
			</div>
			<p *ngIf="!notificationObj.template" cdsToastCaption [innerHTML]="notificationObj.caption"></p>
			<ng-container *ngTemplateOutlet="notificationObj.template; context: { $implicit: notificationObj }"></ng-container>
		</div>
		<button
			*ngIf="!isCloseHidden"
			class="cds--toast-notification__close-button"
			type="button"
			[attr.aria-label]="notificationObj.closeLabel | async"
			(click)="onClose()">
			<svg cdsIcon="close" size="16" class="cds--toast-notification__close-icon"></svg>
		</button>
	`
})
export class Toast extends BaseNotification implements OnInit {
	private static toastCount = 0;
	/**
	 * Can have `type`, `title`, `subtitle`, and `caption` members.
	 *
	 * `type` can be one of `"error"`, `"info"`, `"info-square"`, `"warning"`, `"warning-alt"`, or `"success"`
	 */
	@Input() set notificationObj(obj: ToastContent) {
		if (obj.closeLabel && !isObservable(obj.closeLabel)) {
			obj.closeLabel = of(obj.closeLabel);
		}
		this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
	}

	get notificationObj(): ToastContent {
		return this._notificationObj as ToastContent;
	}


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

	constructor(protected notificationDisplayService: NotificationDisplayService, protected i18n: I18n) {
		super(notificationDisplayService, i18n);
	}

	ngOnInit() {
		if (!this.notificationObj.closeLabel) {
			this.notificationObj.closeLabel = this.i18n.get().NOTIFICATION.CLOSE_BUTTON;
		}
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""