Skip to content

Commit 0839d36

Browse files
committed
refactor(toast): inherit methods from toggle directive
1 parent 0b4ccd9 commit 0839d36

File tree

4 files changed

+47
-64
lines changed

4 files changed

+47
-64
lines changed

projects/igniteui-angular/src/lib/core/styles/components/toast/_toast-component.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,5 @@
88
@include b(igx-toast) {
99
$this: bem--selector-to-string(&);
1010
@include register-component(str-slice($this, 2, -1));
11-
1211
@extend %igx-toast-display !optional;
13-
14-
@include m(active) {
15-
@extend %igx-toast--active !optional;
16-
}
1712
}

projects/igniteui-angular/src/lib/core/styles/components/toast/_toast-theme.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
), $variant);
103103

104104
%igx-toast-display {
105-
position: absolute;
106105
display: inline-flex;
107106
justify-content: center;
108107
align-items: center;
@@ -115,17 +114,6 @@
115114
border-radius: --var($theme, 'border-radius');
116115
box-shadow: map-get($theme, 'shadow');
117116
backdrop-filter: blur(10px);
118-
z-index: 999999;
119-
left: -999999px;
120-
top: -999999px;
121-
opacity: 0;
122-
}
123-
124-
%igx-toast--active {
125-
position: relative;
126-
left: initial;
127-
top: initial;
128-
opacity: 1;
129117
}
130118
}
131119

projects/igniteui-angular/src/lib/toast/toast.component.ts

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { CommonModule } from '@angular/common';
22
import { DeprecateProperty } from '../core/deprecateDecorators';
33
import {
4+
ChangeDetectorRef,
45
Component,
56
ElementRef,
67
EventEmitter,
78
HostBinding,
89
Inject,
910
Input,
1011
NgModule,
11-
OnDestroy,
12-
OnInit,
1312
Optional,
1413
Output,
1514
} from '@angular/core';
1615
import { IgxNavigationService, IToggleView } from '../core/navigation';
16+
import { IgxToggleDirective } from '../directives/toggle/toggle.directive';
1717
import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive';
1818
import {
1919
OverlaySettings,
@@ -60,7 +60,8 @@ export type IgxToastPosition = keyof typeof IgxToastPositionEnum;
6060
selector: 'igx-toast',
6161
templateUrl: 'toast.component.html',
6262
})
63-
export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
63+
export class IgxToastComponent extends IgxToggleDirective
64+
implements IToggleView {
6465
private _isVisible = false;
6566

6667
/**
@@ -201,7 +202,6 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
201202
* ```
202203
* @memberof IgxToastComponent
203204
*/
204-
@HostBinding('class.igx-toast--active')
205205
@Input()
206206
public get isVisible() {
207207
return this._isVisible;
@@ -262,7 +262,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
262262
* @memberof IgxToastComponent
263263
*/
264264
public get element() {
265-
return this.elementRef.nativeElement;
265+
return this._element.nativeElement;
266266
}
267267

268268
/**
@@ -276,16 +276,14 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
276276
*/
277277
private timeoutId: number;
278278

279-
/**
280-
* @hidden
281-
*/
282-
private overlayId: string;
283-
284279
constructor(
285-
private elementRef: ElementRef,
286-
@Optional() private navService: IgxNavigationService,
287-
@Inject(IgxOverlayService) private overlayService: IgxOverlayService
288-
) {}
280+
private _element: ElementRef,
281+
cdr: ChangeDetectorRef,
282+
@Optional() navService: IgxNavigationService,
283+
@Inject(IgxOverlayService) overlayService: IgxOverlayService
284+
) {
285+
super(_element, cdr, overlayService, navService);
286+
}
289287

290288
/**
291289
* Shows the toast.
@@ -311,29 +309,29 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
311309
closeOnEscape: false,
312310
closeOnOutsideClick: false,
313311
modal: false,
314-
outlet: this.outlet
312+
outlet: this.outlet,
315313
};
316314

317315
if (message !== undefined) {
318316
this.toastMessage = message;
319317
}
320318

321-
this.overlayId = this.overlayService.attach(
322-
this.elementRef,
323-
overlaySettings
324-
);
325-
326-
this.onShowing.emit(this);
327-
this._isVisible = true;
319+
this.onOpening.subscribe(() => {
320+
this.isVisible = true;
321+
this.onShowing.emit(this);
322+
});
328323

329324
if (this.autoHide) {
330325
this.timeoutId = window.setTimeout(() => {
331326
this.hide();
332327
}, this.displayTime);
333328
}
334329

335-
this.overlayService.show(this.overlayId);
336-
this.onShown.emit(this);
330+
super.open(overlaySettings);
331+
332+
this.onOpened.subscribe(() => {
333+
this.onShown.emit(this);
334+
});
337335
}
338336

339337
/**
@@ -344,11 +342,18 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
344342
* @memberof IgxToastComponent
345343
*/
346344
public hide(): void {
347-
this.onHiding.emit(this);
348-
this._isVisible = false;
349-
this.onHidden.emit(this);
350-
this.overlayService.hide(this.overlayId);
351345
clearInterval(this.timeoutId);
346+
347+
this.onClosing.subscribe(() => {
348+
this.isVisible = false;
349+
this.onHiding.emit(this);
350+
});
351+
352+
super.close();
353+
354+
this.onClosed.subscribe(() => {
355+
this.onHidden.emit(this);
356+
});
352357
}
353358

354359
/**
@@ -375,25 +380,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
375380
* @memberof IgxToastComponent
376381
*/
377382
public toggle() {
378-
this._isVisible ? this.close() : this.open();
379-
}
380-
381-
/**
382-
* @hidden
383-
*/
384-
public ngOnInit() {
385-
if (this.navService && this.id) {
386-
this.navService.add(this.id, this);
387-
}
388-
}
389-
390-
/**
391-
* @hidden
392-
*/
393-
public ngOnDestroy() {
394-
if (this.navService && this.id) {
395-
this.navService.remove(this.id);
396-
}
383+
super.toggle();
397384
}
398385
}
399386

src/app/toast/toast.sample.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ <h4 class="sample-title">Top Position</h4>
6464
</button>
6565
</div>
6666
</article>
67+
68+
<article class="column">
69+
<h4 class="sample-title">Toggle Toast</h4>
70+
<div class="btn-group">
71+
<button
72+
igxButton="raised"
73+
igxRipple="white"
74+
(click)="toast.toggle()"
75+
>
76+
Toggle Toast
77+
</button>
78+
</div>
79+
</article>
6780
</div>
6881

6982
<div igxOverlayOutlet #outlet="overlay-outlet"></div>

0 commit comments

Comments
 (0)