Files

202 lines
20 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
import { Attribute, Component, ContentChild, Directive, EventEmitter, Input, Output, TemplateRef, ViewEncapsulation, } from '@angular/core';
import { take } from 'rxjs/operators';
import { ngbRunTransition } from '../util/transition/ngbTransition';
import { ngbToastFadeInTransition, ngbToastFadeOutTransition } from './toast-transition';
import { NgIf, NgTemplateOutlet } from '@angular/common';
import * as i0 from "@angular/core";
import * as i1 from "./toast-config";
/**
* This directive allows the usage of HTML markup or other directives
* inside of the toast's header.
*
* @since 5.0.0
*/
export class NgbToastHeader {
}
NgbToastHeader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbToastHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
NgbToastHeader.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbToastHeader, isStandalone: true, selector: "[ngbToastHeader]", ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbToastHeader, decorators: [{
type: Directive,
args: [{ selector: '[ngbToastHeader]', standalone: true }]
}] });
/**
* Toasts provide feedback messages as notifications to the user.
* Goal is to mimic the push notifications available both on mobile and desktop operating systems.
*
* @since 5.0.0
*/
export class NgbToast {
constructor(ariaLive, config, _zone, _element) {
this.ariaLive = ariaLive;
this._zone = _zone;
this._element = _element;
/**
* A template like `<ng-template ngbToastHeader></ng-template>` can be
* used in the projected content to allow markup usage.
*/
this.contentHeaderTpl = null;
/**
* An event fired after the animation triggered by calling `.show()` method has finished.
*
* @since 8.0.0
*/
this.shown = new EventEmitter();
/**
* An event fired after the animation triggered by calling `.hide()` method has finished.
*
* It can only occur in 2 different scenarios:
* - `autohide` timeout fires
* - user clicks on a closing cross
*
* Additionally this output is purely informative. The toast won't be removed from DOM automatically, it's up
* to the user to take care of that.
*
* @since 8.0.0
*/
this.hidden = new EventEmitter();
if (this.ariaLive == null) {
this.ariaLive = config.ariaLive;
}
this.delay = config.delay;
this.autohide = config.autohide;
this.animation = config.animation;
}
ngAfterContentInit() {
this._zone.onStable
.asObservable()
.pipe(take(1))
.subscribe(() => {
this._init();
this.show();
});
}
ngOnChanges(changes) {
if ('autohide' in changes) {
this._clearTimeout();
this._init();
}
}
/**
* Triggers toast closing programmatically.
*
* The returned observable will emit and be completed once the closing transition has finished.
* If the animations are turned off this happens synchronously.
*
* Alternatively you could listen or subscribe to the `(hidden)` output
*
* @since 8.0.0
*/
hide() {
this._clearTimeout();
const transition = ngbRunTransition(this._zone, this._element.nativeElement, ngbToastFadeOutTransition, {
animation: this.animation,
runningTransition: 'stop',
});
transition.subscribe(() => {
this.hidden.emit();
});
return transition;
}
/**
* Triggers toast opening programmatically.
*
* The returned observable will emit and be completed once the opening transition has finished.
* If the animations are turned off this happens synchronously.
*
* Alternatively you could listen or subscribe to the `(shown)` output
*
* @since 8.0.0
*/
show() {
const transition = ngbRunTransition(this._zone, this._element.nativeElement, ngbToastFadeInTransition, {
animation: this.animation,
runningTransition: 'continue',
});
transition.subscribe(() => {
this.shown.emit();
});
return transition;
}
_init() {
if (this.autohide && !this._timeoutID) {
this._timeoutID = setTimeout(() => this.hide(), this.delay);
}
}
_clearTimeout() {
if (this._timeoutID) {
clearTimeout(this._timeoutID);
this._timeoutID = null;
}
}
}
NgbToast.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbToast, deps: [{ token: 'aria-live', attribute: true }, { token: i1.NgbToastConfig }, { token: i0.NgZone }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
NgbToast.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.0", type: NgbToast, isStandalone: true, selector: "ngb-toast", inputs: { animation: "animation", delay: "delay", autohide: "autohide", header: "header" }, outputs: { shown: "shown", hidden: "hidden" }, host: { attributes: { "role": "alert", "aria-atomic": "true" }, properties: { "attr.aria-live": "ariaLive", "class.fade": "animation" }, classAttribute: "toast" }, queries: [{ propertyName: "contentHeaderTpl", first: true, predicate: NgbToastHeader, descendants: true, read: TemplateRef, static: true }], exportAs: ["ngbToast"], usesOnChanges: true, ngImport: i0, template: `
<ng-template #headerTpl>
<strong class="me-auto">{{ header }}</strong>
</ng-template>
<ng-template [ngIf]="contentHeaderTpl || header">
<div class="toast-header">
<ng-template [ngTemplateOutlet]="contentHeaderTpl || headerTpl"></ng-template>
<button
type="button"
class="btn-close"
aria-label="Close"
i18n-aria-label="@@ngb.toast.close-aria"
(click)="hide()"
>
</button>
</div>
</ng-template>
<div class="toast-body">
<ng-content></ng-content>
</div>
`, isInline: true, styles: ["ngb-toast{display:block}ngb-toast .toast-header .close{margin-left:auto;margin-bottom:.25rem}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbToast, decorators: [{
type: Component,
args: [{ selector: 'ngb-toast', exportAs: 'ngbToast', standalone: true, imports: [NgIf, NgTemplateOutlet], encapsulation: ViewEncapsulation.None, host: {
role: 'alert',
'[attr.aria-live]': 'ariaLive',
'aria-atomic': 'true',
class: 'toast',
'[class.fade]': 'animation',
}, template: `
<ng-template #headerTpl>
<strong class="me-auto">{{ header }}</strong>
</ng-template>
<ng-template [ngIf]="contentHeaderTpl || header">
<div class="toast-header">
<ng-template [ngTemplateOutlet]="contentHeaderTpl || headerTpl"></ng-template>
<button
type="button"
class="btn-close"
aria-label="Close"
i18n-aria-label="@@ngb.toast.close-aria"
(click)="hide()"
>
</button>
</div>
</ng-template>
<div class="toast-body">
<ng-content></ng-content>
</div>
`, styles: ["ngb-toast{display:block}ngb-toast .toast-header .close{margin-left:auto;margin-bottom:.25rem}\n"] }]
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
type: Attribute,
args: ['aria-live']
}] }, { type: i1.NgbToastConfig }, { type: i0.NgZone }, { type: i0.ElementRef }]; }, propDecorators: { animation: [{
type: Input
}], delay: [{
type: Input
}], autohide: [{
type: Input
}], header: [{
type: Input
}], contentHeaderTpl: [{
type: ContentChild,
args: [NgbToastHeader, { read: TemplateRef, static: true }]
}], shown: [{
type: Output
}], hidden: [{
type: Output
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9hc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvdG9hc3QvdG9hc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUVOLFNBQVMsRUFDVCxTQUFTLEVBQ1QsWUFBWSxFQUNaLFNBQVMsRUFDVCxZQUFZLEVBQ1osS0FBSyxFQUVMLE1BQU0sRUFFTixXQUFXLEVBQ1gsaUJBQWlCLEdBR2pCLE1BQU0sZUFBZSxDQUFDO0FBR3ZCLE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUd0QyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUNwRSxPQUFPLEVBQUUsd0JBQXdCLEVBQUUseUJBQXlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN6RixPQUFPLEVBQUUsSUFBSSxFQUFFLGdCQUFnQixFQUFFLE1BQU0saUJBQWlCLENBQUM7OztBQUV6RDs7Ozs7R0FLRztBQUVILE1BQU0sT0FBTyxjQUFjOzsyR0FBZCxjQUFjOytGQUFkLGNBQWM7MkZBQWQsY0FBYztrQkFEMUIsU0FBUzttQkFBQyxFQUFFLFFBQVEsRUF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