Skip to content

Commit cd3fc87

Browse files
committed
Added a couple of new options:
1. HTML for the close button 2. Options for selecting the type of ease (one for showing and one for hiding) 3. Options to configure the ease time (in and out) Amend and force push for renaming hideEasingTime to hideEaseTime There is a small breaking change indeed: animate('{{ hideEasingTime }}ms {{ hideEasing }}') but now there is flexibility for choosing different ease times for showing and hiding the toaster.
1 parent f2c4c42 commit cd3fc87

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

src/app/home/home.component.html

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@
3131
placeholder="Toast message"
3232
></textarea>
3333
</div>
34-
34+
<div class="form-group mb-3">
35+
<label for="toastMessage">
36+
<strong>Close Button HTML</strong>
37+
</label>
38+
<textarea
39+
[(ngModel)]="options.closeHtml"
40+
rows="2"
41+
class="form-control"
42+
name="closeHtml"
43+
id="closeHtml"
44+
placeholder="HTML for the close button"
45+
></textarea>
46+
</div>
3547
<div class="form-group mb-3">
3648
<div class="form-check">
3749
<input
@@ -281,6 +293,38 @@
281293
id="toastExtendedTimeout"
282294
/>
283295
</div>
296+
<div class="form-group mb-3">
297+
<label for="toastHideEaseTime">
298+
<strong>Hide Ease Time</strong>
299+
</label>
300+
<input
301+
type="text"
302+
[(ngModel)]="toastr.toastrConfig.hideEaseTime"
303+
(ngModelChange)="fixNumber('hideEaseTime')"
304+
class="form-control"
305+
id="toastHideEaseTime"
306+
/>
307+
</div>
308+
<div class="form-group mb-3">
309+
<label for="toastShowEaseType">Ease Type</label>
310+
<select class="form-control"
311+
name="easeType"
312+
id="toastShowEaseType"
313+
[(ngModel)]="toastr.toastrConfig.easing">
314+
<option [ngValue]="null" disabled>Select Ease Type</option>
315+
<option *ngFor="let type of easeTypes" [ngValue]="type">{{type}}</option>
316+
</select>
317+
</div>
318+
<div class="form-group mb-3">
319+
<label for="toastHideEaseType">Hide Ease Type</label>
320+
<select class="form-control"
321+
name="hideEaseType"
322+
id="toastHideEaseType"
323+
[(ngModel)]="toastr.toastrConfig.hideEasing">
324+
<option [ngValue]="null" disabled>Select Hide Ease Type</option>
325+
<option *ngFor="let type of easeTypes" [ngValue]="type">{{type}}</option>
326+
</select>
327+
</div>
284328
</div>
285329
<div class="col-md-3">
286330
<div class="row">

src/app/home/home.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class HomeComponent {
5858
inlinePositionIndex = 0;
5959
@ViewChildren(ToastContainerDirective) inlineContainers!: QueryList<ToastContainerDirective>;
6060

61+
easeTypes = [ "ease", "ease-in", "ease-out", "ease-in-out", "linear", "step-start", "step-end" ];
6162

6263
constructor(public toastr: ToastrService, private renderer: Renderer2) {
6364
this.options = this.toastr.toastrConfig;

src/lib/toastr/toast.component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { ToastrService } from './toastr.service';
1919
@Component({
2020
selector: '[toast-component]',
2121
template: `
22-
<button *ngIf="options.closeButton" (click)="remove()" class="toast-close-button" aria-label="Close">
22+
<button *ngIf="options.closeButton && options.closeHtml" (click)="remove()"
23+
class="toast-close-button" aria-label="Close" aria-hidden="true" [innerHTML]="options.closeHtml">
24+
</button>
25+
<button *ngIf="options.closeButton && !options.closeHtml" (click)="remove()" class="toast-close-button" aria-label="Close">
2326
<span aria-hidden="true">&times;</span>
2427
</button>
2528
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
@@ -47,7 +50,7 @@ import { ToastrService } from './toastr.service';
4750
),
4851
transition(
4952
'active => removed',
50-
animate('{{ easeTime }}ms {{ easing }}')
53+
animate('{{ hideEaseTime }}ms {{ hideEasing }}')
5154
)
5255
])
5356
],
@@ -69,7 +72,9 @@ export class Toast implements OnDestroy {
6972
value: 'inactive',
7073
params: {
7174
easeTime: this.toastPackage.config.easeTime,
72-
easing: 'ease-in'
75+
hideEaseTime: this.toastPackage.config.hideEaseTime,
76+
easing: this.toastPackage.config.easing,
77+
hideEasing: this.toastPackage.config.hideEasing
7378
}
7479
};
7580

@@ -183,7 +188,7 @@ export class Toast implements OnDestroy {
183188
this.state = { ...this.state, value: 'removed' };
184189
this.outsideTimeout(
185190
() => this.toastrService.remove(this.toastPackage.toastId),
186-
+this.toastPackage.config.easeTime
191+
+this.toastPackage.config.hideEaseTime
187192
);
188193
}
189194
@HostListener('click')

src/lib/toastr/toastr-config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export interface IndividualConfig {
4848
* default: false
4949
*/
5050
enableHtml: boolean;
51+
/**
52+
* html for the close button (possibly unsafe)
53+
* default: undefined
54+
*/
55+
closeHtml: string | undefined;
5156
/**
5257
* css class on toast component
5358
* default: ngx-toastr
@@ -73,11 +78,21 @@ export interface IndividualConfig {
7378
* default: ease-in
7479
*/
7580
easing: string;
81+
/**
82+
* animation hide easing on toast
83+
* default: ease-out
84+
*/
85+
hideEasing: string;
7686
/**
7787
* animation ease time on toast
7888
* default: 300
7989
*/
8090
easeTime: string | number;
91+
/**
92+
* animation hide ease time on toast
93+
* default: 300
94+
*/
95+
hideEaseTime: string | number;
8196
/**
8297
* clicking on toast dismisses it
8398
* default: true
@@ -220,13 +235,16 @@ export const DefaultNoComponentGlobalConfig: GlobalConfig = {
220235
timeOut: 5000,
221236
extendedTimeOut: 1000,
222237
enableHtml: false,
238+
closeHtml: undefined,
223239
progressBar: false,
224240
toastClass: 'ngx-toastr',
225241
positionClass: 'toast-top-right',
226242
titleClass: 'toast-title',
227243
messageClass: 'toast-message',
228244
easing: 'ease-in',
245+
hideEasing: 'ease-out',
229246
easeTime: 300,
247+
hideEaseTime: 300,
230248
tapToDismiss: true,
231249
onActivateTick: false,
232250
progressAnimation: 'decreasing',

0 commit comments

Comments
 (0)