Skip to content

Commit ac1b086

Browse files
committed
fix(toast): add margin to the toast component
Closes #6911
1 parent 6ff0fbe commit ac1b086

File tree

3 files changed

+34
-51
lines changed

3 files changed

+34
-51
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<div [ngClass]="mapPositionToClassName()" *ngIf="this.isVisible" [@animate]="'show'">
2-
{{ message }}
3-
</div>
1+
<span>{{ message }}</span>

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ let NEXT_ID = 0;
3232
* ```
3333
*/
3434
@Component({
35-
animations: [
35+
animations: [
3636
trigger('animate', [
37-
state('show', style({
37+
state('visible', style({
3838
opacity: 1
3939
})),
40-
transition('* => show', animate('.20s ease')),
41-
transition('show => *', animate('.40s ease-out'))
40+
transition('invisible => visible', animate('.20s ease')),
41+
transition('visible => invisible', animate('.40s ease-out'))
4242
])
4343
],
4444
selector: 'igx-toast',
@@ -50,19 +50,9 @@ let NEXT_ID = 0;
5050
`]
5151
})
5252
export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
53+
@HostBinding('@animate')
54+
private _animationState = 'invisible';
5355
private _isVisible = false;
54-
/**
55-
* Returns a list of available CSS classes.
56-
* ```typescript
57-
* let toastClasses = this.toast.CSS_CLASSES;
58-
* ```
59-
* @memberof IgxToastComponent
60-
*/
61-
public readonly CSS_CLASSES = {
62-
IGX_TOAST_BOTTOM: 'igx-toast--bottom',
63-
IGX_TOAST_MIDDLE: 'igx-toast--middle',
64-
IGX_TOAST_TOP: 'igx-toast--top'
65-
};
6656

6757
/**
6858
* Sets/gets the `id` of the toast.
@@ -121,6 +111,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
121111
*/
122112
@Output()
123113
public onHidden = new EventEmitter<IgxToastComponent>();
114+
124115
/**
125116
* Sets/gets the `role` attribute.
126117
* If not set, `role` will have value `"alert"`.
@@ -134,6 +125,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
134125
*/
135126
@Input()
136127
public role = 'alert';
128+
137129
/**
138130
* Sets/gets whether the toast will be hidden after the `displayTime` is over.
139131
* Default value is `true`.
@@ -186,7 +178,6 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
186178
public set isVisible(value) {
187179
this._isVisible = value;
188180
this.isVisibleChange.emit(this._isVisible);
189-
190181
}
191182

192183
/**
@@ -232,6 +223,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
232223
public get element() {
233224
return this.elementRef.nativeElement;
234225
}
226+
235227
/**
236228
* @hidden
237229
*/
@@ -253,6 +245,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
253245
clearInterval(this.timeoutId);
254246
this.onShowing.emit(this);
255247
this.isVisible = true;
248+
this._animationState = 'visible';
256249

257250
if (this.autoHide) {
258251
this.timeoutId = setTimeout(() => {
@@ -274,6 +267,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
274267
this.onHiding.emit(this);
275268
this.isVisible = false;
276269
this.onHidden.emit(this);
270+
this._animationState = 'invisible';
277271

278272
clearInterval(this.timeoutId);
279273
}
@@ -304,26 +298,22 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
304298
public toggle() {
305299
this.isVisible ? this.close() : this.open();
306300
}
307-
/**
308-
* Sets/gets the class name of the toast based on the `position` value.
309-
* ```typescript
310-
* let className = this.toast.mapPositionToClassName();
311-
* ```
312-
* @memberof IgxToastComponent
313-
*/
314-
public mapPositionToClassName(): any {
315-
if (this.position === IgxToastPosition.Top) {
316-
return this.CSS_CLASSES.IGX_TOAST_TOP;
317-
}
318301

319-
if (this.position === IgxToastPosition.Middle) {
320-
return this.CSS_CLASSES.IGX_TOAST_MIDDLE;
321-
}
302+
@HostBinding('class.igx-toast--top')
303+
public get cssClassTop(): boolean {
304+
return this.position === IgxToastPosition.Top;
305+
}
322306

323-
if (this.position === IgxToastPosition.Bottom) {
324-
return this.CSS_CLASSES.IGX_TOAST_BOTTOM;
325-
}
307+
@HostBinding('class.igx-toast--middle')
308+
public get cssClassMiddle(): boolean {
309+
return this.position === IgxToastPosition.Middle;
310+
}
311+
312+
@HostBinding('class.igx-toast--bottom')
313+
public get cssClassBottom(): boolean {
314+
return this.position === IgxToastPosition.Bottom;
326315
}
316+
327317
/**
328318
* @hidden
329319
*/
@@ -332,6 +322,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
332322
this.navService.add(this.id, this);
333323
}
334324
}
325+
335326
/**
336327
* @hidden
337328
*/

src/app/toast/toast.sample.css

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
height: 300px;
33
}
44

5-
.preview.bottom {
6-
background: url('/assets/images/rsrcs/toast-bg-bottom.svg') no-repeat;
7-
}
8-
9-
10-
.preview.middle {
11-
background: url('/assets/images/rsrcs/toast-bg-middle.svg') no-repeat;
12-
}
13-
14-
15-
.preview.top {
16-
background: url('/assets/images/rsrcs/toast-bg-top.svg') no-repeat;
17-
}
18-
195
.btn-group {
206
display: flex;
217
width: 300px;
228
margin-top: 16px;
239
justify-content: space-between;
2410
}
11+
12+
.igx-toast--bottom {
13+
margin-bottom: 16px;
14+
}
15+
16+
.igx-toast--top {
17+
margin-top: 16px;
18+
}

0 commit comments

Comments
 (0)