refac
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import { createEventDispatcher, onMount } from 'svelte';
|
import { createEventDispatcher, onMount } from 'svelte';
|
||||||
|
import XMark from '$lib/components/icons/XMark.svelte';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
let startX = 0,
|
let startX = 0,
|
||||||
startY = 0;
|
startY = 0;
|
||||||
let moved = false;
|
let moved = false;
|
||||||
|
let closeButtonElement: HTMLButtonElement;
|
||||||
const DRAG_THRESHOLD_PX = 6;
|
const DRAG_THRESHOLD_PX = 6;
|
||||||
|
|
||||||
const clickHandler = () => {
|
const clickHandler = () => {
|
||||||
@@ -22,6 +24,10 @@
|
|||||||
dispatch('closeToast');
|
dispatch('closeToast');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const closeHandler = () => {
|
||||||
|
dispatch('closeToast');
|
||||||
|
};
|
||||||
|
|
||||||
function onPointerDown(e: PointerEvent) {
|
function onPointerDown(e: PointerEvent) {
|
||||||
startX = e.clientX;
|
startX = e.clientX;
|
||||||
startY = e.clientY;
|
startY = e.clientY;
|
||||||
@@ -43,6 +49,11 @@
|
|||||||
// Release capture if taken
|
// Release capture if taken
|
||||||
(e.currentTarget as HTMLElement).releasePointerCapture?.(e.pointerId);
|
(e.currentTarget as HTMLElement).releasePointerCapture?.(e.pointerId);
|
||||||
|
|
||||||
|
// Skip if clicking the close button
|
||||||
|
if (closeButtonElement && (e.target === closeButtonElement || closeButtonElement.contains(e.target as Node))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Only treat as a click if there wasn't a drag
|
// Only treat as a click if there wasn't a drag
|
||||||
if (!moved) {
|
if (!moved) {
|
||||||
clickHandler();
|
clickHandler();
|
||||||
@@ -71,7 +82,7 @@
|
|||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
<div
|
<div
|
||||||
class="flex gap-2.5 text-left min-w-[var(--width)] w-full dark:bg-gray-850 dark:text-white bg-white text-black border border-gray-100 dark:border-gray-800 rounded-3xl px-4 py-3.5 cursor-pointer select-none"
|
class="group relative flex gap-2.5 text-left min-w-[var(--width)] w-full dark:bg-gray-850 dark:text-white bg-white text-black border border-gray-100 dark:border-gray-800 rounded-3xl px-4 py-3.5 cursor-pointer select-none"
|
||||||
on:dragstart|preventDefault
|
on:dragstart|preventDefault
|
||||||
on:pointerdown={onPointerDown}
|
on:pointerdown={onPointerDown}
|
||||||
on:pointermove={onPointerMove}
|
on:pointermove={onPointerMove}
|
||||||
@@ -84,6 +95,16 @@
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<!-- Close button (visible on hover) -->
|
||||||
|
<button
|
||||||
|
bind:this={closeButtonElement}
|
||||||
|
class="absolute -top-0.5 -left-0.5 p-0.5 rounded-full opacity-0 group-hover:opacity-100 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-opacity z-10"
|
||||||
|
on:click|stopPropagation={closeHandler}
|
||||||
|
aria-label="Dismiss notification"
|
||||||
|
>
|
||||||
|
<XMark className="size-3" />
|
||||||
|
</button>
|
||||||
|
|
||||||
<div class="shrink-0 self-top -translate-y-0.5">
|
<div class="shrink-0 self-top -translate-y-0.5">
|
||||||
<img src="{WEBUI_BASE_URL}/static/favicon.png" alt="favicon" class="size-6 rounded-full" />
|
<img src="{WEBUI_BASE_URL}/static/favicon.png" alt="favicon" class="size-6 rounded-full" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user