Skip to content

Commit 5604233

Browse files
committed
chore(*): add optional parameter to open method
1 parent 184b7b1 commit 5604233

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ All notable changes for each version of this project will be documented in this
3535
- `IgxColumnActionsComponent`
3636
- **Breaking Change** - The following input has been removed
3737
- Input `columns`. Use `igxGrid` `columns` input instead.
38+
- `IgxToastComponent`
39+
- **Deprecated** - The `position` input property has been deprecated. Use `positionSettings` input instead.
3840

3941
## 12.2.3
4042

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

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,41 @@ describe('IgxToast', () => {
5454
fixture.detectChanges();
5555
expect(toast.positionSettings.verticalDirection).toBe(-1);
5656
});
57+
});
58+
59+
describe('IgxToast with positionSettings', () => {
60+
configureTestSuite();
61+
beforeAll(waitForAsync(() => {
62+
TestBed.configureTestingModule({
63+
declarations: [ToastPositionSettingsTestComponent],
64+
imports: [NoopAnimationsModule, IgxToastModule]
65+
}).compileComponents();
66+
}));
67+
68+
let fixture: ComponentFixture<ToastPositionSettingsTestComponent>;
69+
let toast: IgxToastComponent;
70+
71+
beforeEach(() => {
72+
fixture = TestBed.createComponent(ToastPositionSettingsTestComponent);
73+
toast = fixture.componentInstance.toast;
74+
fixture.detectChanges();
75+
});
76+
77+
it('should be able to change positionSettings', () => {
78+
expect(toast.positionSettings.horizontalDirection).toBe(-1);
79+
expect(toast.positionSettings.verticalDirection).toBe(-0.5);
80+
toast.positionSettings = fixture.componentInstance.secondPositionSettings;
81+
fixture.detectChanges();
82+
expect(toast.positionSettings.horizontalDirection).toBe(-0.5);
83+
expect(toast.positionSettings.verticalDirection).toBe(-0.5);
84+
});
5785

58-
it('should be able to set custom positionSettings', () => {
59-
const defaultPositionSettings = toast.positionSettings;
60-
expect(defaultPositionSettings.horizontalDirection).toBe(-0.5);
61-
expect(defaultPositionSettings.verticalDirection).toBe(0);
62-
const newPositionSettings: PositionSettings = {
63-
openAnimation: useAnimation(slideInLeft, { params: { duration: '1000ms' } }),
64-
closeAnimation: useAnimation(slideInRight, { params: { duration: '1000ms' } }),
65-
horizontalDirection: HorizontalAlignment.Center,
66-
verticalDirection: VerticalAlignment.Middle,
67-
horizontalStartPoint: HorizontalAlignment.Center,
68-
verticalStartPoint: VerticalAlignment.Middle,
69-
minSize: { height: 100, width: 100 }
70-
};
71-
toast.positionSettings = newPositionSettings;
86+
it('positionSettings passed in the open method should be applied', () => {
87+
const positions = fixture.componentInstance.secondPositionSettings;
88+
toast.open(undefined, positions);
7289
fixture.detectChanges();
73-
const customPositionSettings = toast.positionSettings;
74-
expect(customPositionSettings.horizontalDirection).toBe(-0.5);
75-
expect(customPositionSettings.verticalDirection).toBe(-0.5);
76-
expect(customPositionSettings.openAnimation.options.params).toEqual({duration: '1000ms'});
77-
expect(customPositionSettings.minSize).toEqual({height: 100, width: 100});
90+
expect(toast.positionSettings.horizontalDirection).toBe(-0.5);
91+
expect(toast.positionSettings.verticalDirection).toBe(-0.5);
7892
});
7993
});
8094

@@ -86,3 +100,23 @@ class ToastInitializeTestComponent {
86100
public toast: IgxToastComponent;
87101
}
88102

103+
@Component({
104+
template: `<igx-toast #toast [positionSettings]="firstPositionSettings"></igx-toast>`,
105+
})
106+
class ToastPositionSettingsTestComponent {
107+
@ViewChild(IgxToastComponent, { static: true })
108+
public toast: IgxToastComponent;
109+
public firstPositionSettings: PositionSettings = {
110+
horizontalDirection: HorizontalAlignment.Left,
111+
verticalDirection: VerticalAlignment.Middle,
112+
horizontalStartPoint: HorizontalAlignment.Left,
113+
verticalStartPoint: VerticalAlignment.Middle
114+
};
115+
public secondPositionSettings: PositionSettings = {
116+
horizontalDirection: HorizontalAlignment.Center,
117+
verticalDirection: VerticalAlignment.Middle,
118+
horizontalStartPoint: HorizontalAlignment.Center,
119+
verticalStartPoint: VerticalAlignment.Middle
120+
};
121+
}
122+

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import {
88
Inject,
99
Input,
1010
NgModule,
11+
OnChanges,
1112
OnInit,
1213
Optional,
13-
Output
14+
Output,
15+
SimpleChanges
1416
} from '@angular/core';
1517
import { takeUntil } from 'rxjs/operators';
1618
import { IgxNavigationService } from '../core/navigation';
@@ -26,6 +28,7 @@ import { IgxNotificationsDirective } from '../directives/notification/notificati
2628
import { ToggleViewEventArgs } from '../directives/toggle/toggle.directive';
2729
import { useAnimation } from '@angular/animations';
2830
import { fadeIn, fadeOut } from '../animations/fade';
31+
import { DeprecateProperty } from '../core/deprecateDecorators';
2932

3033
let NEXT_ID = 0;
3134

@@ -63,7 +66,7 @@ export type IgxToastPosition = (typeof IgxToastPosition)[keyof typeof IgxToastPo
6366
selector: 'igx-toast',
6467
templateUrl: 'toast.component.html'
6568
})
66-
export class IgxToastComponent extends IgxNotificationsDirective implements OnInit {
69+
export class IgxToastComponent extends IgxNotificationsDirective implements OnInit, OnChanges {
6770
/**
6871
* @hidden
6972
*/
@@ -118,6 +121,7 @@ export class IgxToastComponent extends IgxNotificationsDirective implements OnIn
118121
*
119122
* @memberof IgxToastComponent
120123
*/
124+
@DeprecateProperty('`position` is deprecated. We suggest using `positionSettings` property instead.')
121125
@Input()
122126
public get position(): IgxToastPosition {
123127
return this._position;
@@ -167,7 +171,6 @@ export class IgxToastComponent extends IgxNotificationsDirective implements OnIn
167171
}
168172

169173
private _position: IgxToastPosition = 'bottom';
170-
171174
private _positionSettings: PositionSettings = {
172175
horizontalDirection: HorizontalAlignment.Center,
173176
verticalDirection: VerticalAlignment.Bottom,
@@ -204,14 +207,15 @@ export class IgxToastComponent extends IgxNotificationsDirective implements OnIn
204207
* this.toast.open();
205208
* ```
206209
*/
207-
public open(message?: string) {
210+
public open(message?: string, settings?: PositionSettings) {
208211
if (message !== undefined) {
209212
this.textMessage = message;
210213
}
211-
requestAnimationFrame(() => {
212-
this.strategy = new GlobalPositionStrategy(this.positionSettings);
213-
super.open();
214-
});
214+
if (settings !== undefined) {
215+
this.positionSettings = settings;
216+
}
217+
this.strategy = new GlobalPositionStrategy(this.positionSettings);
218+
super.open();
215219
}
216220

217221
/**
@@ -251,6 +255,12 @@ export class IgxToastComponent extends IgxNotificationsDirective implements OnIn
251255
? VerticalAlignment.Middle
252256
: VerticalAlignment.Top;
253257
}
258+
259+
public ngOnChanges(changes: SimpleChanges) {
260+
if (changes['position'] && this._positionSettings) {
261+
this._positionSettings.verticalDirection = this.calculatePosition();
262+
}
263+
}
254264
}
255265

256266
/**

0 commit comments

Comments
 (0)