Add handler for alerts

This commit is contained in:
Jon Staab
2025-03-20 09:38:57 -07:00
parent ad034b1641
commit 9eefd6600d
9 changed files with 123 additions and 45 deletions
+2 -2
View File
@@ -24,7 +24,7 @@
data-tip={title}>
{@render children?.()}
{#if !active && notification}
<div class="absolute right-2 top-2 h-2 w-2 rounded-full bg-primary"></div>
<div class="absolute right-1 top-1 h-2 w-2 rounded-full bg-primary"></div>
{/if}
</div>
</a>
@@ -37,7 +37,7 @@
data-tip={title}>
{@render children?.()}
{#if !active && notification}
<div class="absolute right-2 top-2 h-2 w-2 rounded-full bg-primary"></div>
<div class="absolute right-1 top-1 h-2 w-2 rounded-full bg-primary"></div>
{/if}
</div>
</Button>
+38 -1
View File
@@ -1,4 +1,4 @@
import {sleep} from "@welshman/lib"
import {sleep, last} from "@welshman/lib"
export {preventDefault, stopPropagation} from "svelte/legacy"
export const copyToClipboard = (text: string) => {
@@ -89,3 +89,40 @@ export const downloadText = (filename: string, text: string) => {
document.body.removeChild(a)
URL.revokeObjectURL(url)
}
export const isIntersecting = async (element: Element) =>
new Promise(resolve => {
const observer = new IntersectionObserver(xs => {
resolve(xs.some(x => x.isIntersecting))
observer.unobserve(element)
})
observer.observe(element)
})
export const scrollToEvent = async (id: string) => {
const element = document.querySelector(`[data-event="${id}"]`) as any
if (element) {
element.scrollIntoView({behavior: "smooth", block: "center"})
element.style = "filter: brightness(1.5); transition-property: all; transition-duration: 400ms;"
setTimeout(() => {
element.style = "transition-property: all; transition-duration: 300ms;"
}, 800)
setTimeout(() => {
element.style = ""
}, 800 + 400)
} else {
const lastElement = last(Array.from(document.querySelectorAll("[data-event]")))
if (lastElement && !isIntersecting(lastElement)) {
lastElement.scrollIntoView({behavior: "smooth", block: "center"})
}
await sleep(300)
scrollToEvent(id)
}
}