Skip to content

Commit 331618c

Browse files
committed
Added a couple of new options:
1. HTML for the close button 2. Options for selection the type of ease (one for showing and one for hiding) 3. Options to configure the ease time (in and out)
1 parent f2c4c42 commit 331618c

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="toastHideEasingTime">
298+
<strong>Hide Easing Time</strong>
299+
</label>
300+
<input
301+
type="text"
302+
[(ngModel)]="toastr.toastrConfig.hideEasingTime"
303+
(ngModelChange)="fixNumber('hideEasingTime')"
304+
class="form-control"
305+
id="toastHideEasingTime"
306+
/>
307+
</div>
308+
<div class="form-group mb-3">
309+
<label for="toastShowEasingType">Ease Type</label>
310+
<select class="form-control"
311+
name="easeType"
312+
id="toastShowEasingType"
313+
[(ngModel)]="toastr.toastrConfig.easing">
314+
<option [ngValue]="null" disabled>Select Easing 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="toastHideEasingType">Hide Easing Type</label>
320+
<select class="form-control"
321+
name="hideEasingType"
322+
id="toastHideEasingType"
323+
[(ngModel)]="toastr.toastrConfig.hideEasing">
324+
<option [ngValue]="null" disabled>Select Hide Easing 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('{{ hideEasingTime }}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+
hideEasingTime: this.toastPackage.config.hideEasingTime,
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.hideEasingTime
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+
hideEasingTime: 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+
hideEasingTime: 300,
230248
tapToDismiss: true,
231249
onActivateTick: false,
232250
progressAnimation: 'decreasing',

0 commit comments

Comments
 (0)