Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions assets/js/live_toast/live_toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type DismissTimer = {
cancel: () => void
}

type ToastElement = HTMLElement & {
order: number
targetDestination: string
}

export type ClientToastOptions = {
duration?: number | 'infinity'
metadata?: Record<string, unknown>
Expand All @@ -82,11 +87,8 @@ type ClientToastRequest = {

const dismissTimers = new WeakMap<object, DismissTimer>()

declare global {
interface HTMLElement {
order: number
targetDestination: string
}
function asToastElement(el: HTMLElement): ToastElement {
return el as ToastElement
}

export function addToast(
Expand All @@ -109,9 +111,9 @@ function doAnimations(
maxItems: number,
elToRemove?: HTMLElement
) {
const ts = []
const ts: ToastElement[] = []
let toasts = Array.from(
document.querySelectorAll<HTMLElement>(
document.querySelectorAll<ToastElement>(
'#toast-group [phx-hook="LiveToast"]'
)
)
Expand Down Expand Up @@ -226,7 +228,8 @@ function toastGroupTarget(el: HTMLElement) {
}

async function animateOut(this: ViewHook) {
const val = (this.el.order - 2) * 100 + (this.el.order - 2) * gap
const toast = asToastElement(this.el)
const val = (toast.order - 2) * 100 + (toast.order - 2) * gap

let direction = ''

Expand Down Expand Up @@ -390,7 +393,8 @@ export function createLiveToastHook(duration = 6000, maxItems = 3) {
}

// animate to targetDestination in 0ms
const keyframes = { y: [this.el.targetDestination] }
const toast = asToastElement(this.el)
const keyframes = { y: [toast.targetDestination] }
animate(this.el, keyframes, { duration: 0 })
},
mounted(this: ViewHook) {
Expand Down
2 changes: 0 additions & 2 deletions assets/test/live_toast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ function mountToast(duration: number | 'Infinity' = 1000, countdown = false) {
get: () => document.body
})

el.order = 1
el.targetDestination = '0px'
el.matches = ((selector: string) => {
if (selector === ':hover') return hovered
if (selector === ':focus-within') return focused
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defmodule LiveToast.MixProject do
defp files do
~w"""
assets/js
assets/index.d.ts
priv
lib/live_toast.ex
lib/live_toast/components.ex
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"description": "Phoenix Hook for LiveToast",
"license": "MIT",
"private": true,
"types": "./assets/index.d.ts",
"module": "./priv/static/live_toast.esm.js",
"main": "./priv/static/live_toast.cjs.js",
"exports": {
"types": "./assets/index.d.ts",
"import": "./priv/static/live_toast.esm.js",
"require": "./priv/static/live_toast.cjs.js"
},
Expand All @@ -20,6 +22,7 @@
"LICENSE.md",
"package.json",
"priv/static/*",
"assets/index.d.ts",
"assets/js/live_toast/*"
]
}
9 changes: 7 additions & 2 deletions priv/static/live_toast.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/live_toast.cjs.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions priv/static/live_toast.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/live_toast.esm.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions priv/static/live_toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ var LiveMotion = (() => {
var remainingSelector = "[data-live-toast-remaining]";
var lastTS = [];
var dismissTimers = new WeakMap();
function asToastElement(el) {
return el;
}
function addToast(kind, message, options = {}) {
var _a;
(_a = document.getElementById("toast-group")) == null ? void 0 : _a.dispatchEvent(new CustomEvent(clientToastEvent, {
Expand Down Expand Up @@ -894,7 +897,8 @@ var LiveMotion = (() => {
}
function animateOut() {
return __async(this, null, function* () {
const val = (this.el.order - 2) * 100 + (this.el.order - 2) * gap;
const toast = asToastElement(this.el);
const val = (toast.order - 2) * 100 + (toast.order - 2) * gap;
let direction = "";
if (this.el.dataset.corner === "bottom_left" || this.el.dataset.corner === "bottom_center" || this.el.dataset.corner === "bottom_right") {
direction = "-";
Expand Down Expand Up @@ -1013,7 +1017,8 @@ var LiveMotion = (() => {
if (this.el.dataset.liveToastGroup === "true") {
return;
}
const keyframes = { y: [this.el.targetDestination] };
const toast = asToastElement(this.el);
const keyframes = { y: [toast.targetDestination] };
animate2(this.el, keyframes, { duration: 0 });
},
mounted() {
Expand Down
Loading
Loading