Skip to content

Commit 9534e8a

Browse files
committed
refactor(toasts): removed animejs
1 parent 339a3c8 commit 9534e8a

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

src/toasts.ts

+34-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import anim from "animejs";
2-
31
import { BaseOptions } from "./component";
42

53
export interface ToastOptions extends BaseOptions {
@@ -207,36 +205,32 @@ export class Toast {
207205
const toast = this.options.toastId
208206
? document.getElementById(this.options.toastId)
209207
: document.createElement('div');
210-
//const toast = document.createElement('div');
211208
toast.classList.add('toast');
212209
toast.setAttribute('role', 'alert');
213210
toast.setAttribute('aria-live', 'assertive');
214211
toast.setAttribute('aria-atomic', 'true');
215-
216212
// Add custom classes onto toast
217213
if (this.options.classes.length > 0) {
218214
toast.classList.add(...this.options.classes.split(' '));
219215
}
220-
221-
// Set text content
222-
if (this.message)
223-
toast.innerText = this.message;
224-
225-
// Append toast
216+
if (this.message) toast.innerText = this.message;
226217
Toast._container.appendChild(toast);
227218
return toast;
228219
}
229220

230221
_animateIn() {
231222
// Animate toast in
232-
this.el.style.display = ""
233-
anim({
234-
targets: this.el,
235-
top: 0,
236-
opacity: 1,
237-
duration: this.options.inDuration,
238-
easing: 'easeOutCubic'
239-
});
223+
this.el.style.display = "";
224+
this.el.style.opacity = '0';
225+
// easeOutCubic
226+
this.el.style.transition = `
227+
top ${this.options.inDuration}ms ease,
228+
opacity ${this.options.inDuration}ms ease
229+
`;
230+
setTimeout(() => {
231+
this.el.style.top = '0';
232+
this.el.style.opacity = '1';
233+
}, 1);
240234
}
241235

242236
/**
@@ -271,27 +265,30 @@ export class Toast {
271265
this.el.style.opacity = '0';
272266
}
273267

274-
anim({
275-
targets: this.el,
276-
opacity: 0,
277-
marginTop: -40,
278-
duration: this.options.outDuration,
279-
easing: 'easeOutExpo',
280-
complete: () => {
281-
// Call the optional callback
282-
if (typeof this.options.completeCallback === 'function') {
283-
this.options.completeCallback();
284-
}
285-
// Remove toast from DOM
286-
if (!this.options.toastId) {
287-
this.el.remove();
288-
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
289-
if (Toast._toasts.length === 0) {
290-
Toast._removeContainer();
291-
}
268+
// easeOutExpo
269+
this.el.style.transition = `
270+
margin ${this.options.outDuration}ms ease,
271+
opacity ${this.options.outDuration}ms ease`;
272+
273+
setTimeout(() => {
274+
this.el.style.opacity = '0';
275+
this.el.style.marginTop = '-40px';
276+
}, 1);
277+
278+
setTimeout(() => {
279+
// Call the optional callback
280+
if (typeof this.options.completeCallback === 'function') {
281+
this.options.completeCallback();
282+
}
283+
// Remove toast from DOM
284+
if (!this.options.toastId) {
285+
this.el.remove();
286+
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
287+
if (Toast._toasts.length === 0) {
288+
Toast._removeContainer();
292289
}
293290
}
294-
});
291+
}, this.options.outDuration);
295292
}
296293

297294
static {

0 commit comments

Comments
 (0)