• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.41
/projects/igniteui-angular/src/lib/toast/toast.component.ts
1
import {
2
    ChangeDetectorRef,
3
    Component,
4
    ElementRef,
5
    EventEmitter,
6
    HostBinding,
7
    Inject,
8
    Input,
9
    OnInit,
10
    Optional,
11
    Output
12
} from '@angular/core';
13
import { takeUntil } from 'rxjs/operators';
14
import { IgxNavigationService } from '../core/navigation';
15
import {
16
    IgxOverlayService,
17
    HorizontalAlignment,
18
    VerticalAlignment,
19
    GlobalPositionStrategy,
20
    PositionSettings
21
} from '../services/public_api';
22
import { IgxNotificationsDirective } from '../directives/notification/notifications.directive';
23
import { ToggleViewEventArgs } from '../directives/toggle/toggle.directive';
24
import { useAnimation } from '@angular/animations';
25
import { fadeIn, fadeOut } from 'igniteui-angular/animations';
26

27
let NEXT_ID = 0;
2✔
28

29
/**
30
 * **Ignite UI for Angular Toast** -
31
 * [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/toast)
32
 *
33
 * The Ignite UI Toast provides information and warning messages that are non-interactive and cannot
34
 * be dismissed by the user. Toasts can be displayed at the bottom, middle, or top of the page.
35
 *
36
 * Example:
37
 * ```html
38
 * <button type="button" igxButton (click)="toast.open()">Show notification</button>
39
 * <igx-toast #toast displayTime="1000">
40
 *      Notification displayed
41
 * </igx-toast>
42
 * ```
43
 */
44
@Component({
45
    selector: 'igx-toast',
46
    templateUrl: 'toast.component.html',
47
    standalone: true
48
})
49
export class IgxToastComponent extends IgxNotificationsDirective implements OnInit {
2✔
50
    /**
51
     * @hidden
52
     */
53
    @HostBinding('class.igx-toast')
UNCOV
54
    public cssClass = 'igx-toast';
×
55

56
    /**
57
     * Sets/gets the `id` of the toast.
58
     * If not set, the `id` will have value `"igx-toast-0"`.
59
     * ```html
60
     * <igx-toast id = "my-first-toast"></igx-toast>
61
     * ```
62
     * ```typescript
63
     * let toastId = this.toast.id;
64
     * ```
65
     */
66
    @HostBinding('attr.id')
67
    @Input()
UNCOV
68
    public override id = `igx-toast-${NEXT_ID++}`;
×
69

70
    /**
71
     * Sets/gets the `role` attribute.
72
     * If not set, `role` will have value `"alert"`.
73
     * ```html
74
     * <igx-toast [role] = "'notify'"></igx-toast>
75
     * ```
76
     * ```typescript
77
     * let toastRole = this.toast.role;
78
     * ```
79
     *
80
     * @memberof IgxToastComponent
81
     */
82
    @HostBinding('attr.role')
83
    @Input()
UNCOV
84
    public role = 'alert';
×
85

86
    /**
87
     * @hidden
88
     */
89
    @Output()
UNCOV
90
    public isVisibleChange = new EventEmitter<ToggleViewEventArgs>();
×
91

92
    /**
93
     * Get the position and animation settings used by the toast.
94
     * ```typescript
95
     * @ViewChild('toast', { static: true }) public toast: IgxToastComponent;
96
     * let currentPosition: PositionSettings = this.toast.positionSettings
97
     * ```
98
     */
99
     @Input()
100
     public get positionSettings(): PositionSettings {
UNCOV
101
         return this._positionSettings;
×
102
     }
103

104
     /**
105
      * Set the position and animation settings used by the toast.
106
      * ```html
107
      * <igx-toast [positionSettings]="newPositionSettings"></igx-toast>
108
      * ```
109
      * ```typescript
110
      * import { slideInTop, slideOutBottom } from 'igniteui-angular';
111
      * ...
112
      * @ViewChild('toast', { static: true }) public toast: IgxToastComponent;
113
      *  public newPositionSettings: PositionSettings = {
114
      *      openAnimation: useAnimation(slideInTop, { params: { duration: '1000ms', fromPosition: 'translateY(100%)'}}),
115
      *      closeAnimation: useAnimation(slideOutBottom, { params: { duration: '1000ms', fromPosition: 'translateY(0)'}}),
116
      *      horizontalDirection: HorizontalAlignment.Left,
117
      *      verticalDirection: VerticalAlignment.Middle,
118
      *      horizontalStartPoint: HorizontalAlignment.Left,
119
      *      verticalStartPoint: VerticalAlignment.Middle
120
      *  };
121
      * this.toast.positionSettings = this.newPositionSettings;
122
      * ```
123
      */
124
     public set positionSettings(settings: PositionSettings) {
UNCOV
125
         this._positionSettings = settings;
×
126
     }
127

UNCOV
128
     private _positionSettings: PositionSettings = {
×
129
        horizontalDirection: HorizontalAlignment.Center,
130
        verticalDirection: VerticalAlignment.Bottom,
131
        openAnimation: useAnimation(fadeIn),
132
        closeAnimation: useAnimation(fadeOut),
133
     };
134

135
    /**
136
     * Gets the nativeElement of the toast.
137
     * ```typescript
138
     * let nativeElement = this.toast.element;
139
     * ```
140
     *
141
     * @memberof IgxToastComponent
142
     */
143
    public override get element() {
UNCOV
144
        return this._element.nativeElement;
×
145
    }
146

147
    constructor(
UNCOV
148
        private _element: ElementRef,
×
149
        cdr: ChangeDetectorRef,
150
        @Optional() navService: IgxNavigationService,
151
        @Inject(IgxOverlayService) overlayService: IgxOverlayService
152
    ) {
UNCOV
153
        super(_element, cdr, overlayService, navService);
×
154
    }
155

156
    /**
157
     * Shows the toast.
158
     * If `autoHide` is enabled, the toast will hide after `displayTime` is over.
159
     *
160
     * ```typescript
161
     * this.toast.open();
162
     * ```
163
     */
164
    public override open(message?: string, settings?: PositionSettings) {
UNCOV
165
        if (message !== undefined) {
×
UNCOV
166
            this.textMessage = message;
×
167
        }
UNCOV
168
        if (settings !== undefined) {
×
UNCOV
169
            this.positionSettings = settings;
×
170
        }
UNCOV
171
        this.strategy = new GlobalPositionStrategy(this.positionSettings);
×
UNCOV
172
        super.open();
×
173
    }
174

175
    /**
176
     * Opens or closes the toast, depending on its current state.
177
     *
178
     * ```typescript
179
     * this.toast.toggle();
180
     * ```
181
     */
182
     public override toggle() {
UNCOV
183
        if (this.collapsed || this.isClosing) {
×
UNCOV
184
            this.open();
×
185
        } else {
UNCOV
186
            this.close();
×
187
        }
188
    }
189

190
    /**
191
     * @hidden
192
     */
193
    public override ngOnInit() {
UNCOV
194
        this.opened.pipe(takeUntil(this.destroy$)).subscribe(() => {
×
UNCOV
195
            const openedEventArgs: ToggleViewEventArgs = { owner: this, id: this._overlayId };
×
UNCOV
196
            this.isVisibleChange.emit(openedEventArgs);
×
197
        });
198

UNCOV
199
        this.closed.pipe(takeUntil(this.destroy$)).subscribe(() => {
×
UNCOV
200
            const closedEventArgs: ToggleViewEventArgs = { owner: this, id: this._overlayId };
×
UNCOV
201
            this.isVisibleChange.emit(closedEventArgs);
×
202
        });
203
    }
204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc