ui: Add onclick event to Toaster

This commit is contained in:
nemunaire 2023-01-11 19:25:48 +01:00
parent 616804e18f
commit fae1df434e
2 changed files with 9 additions and 3 deletions

View File

@ -1,7 +1,6 @@
<script lang="ts">
import {
Toast,
ToastBody,
ToastHeader,
} from 'sveltestrap';
@ -14,9 +13,13 @@
<ToastHeader toggle={() => toast.dismiss()} icon={toast.getColor()}>
{#if toast.title}{toast.title}{:else}happyDomain{/if}
</ToastHeader>
<ToastBody>
<div
class="toast-body"
style={toast.onclick?"cursor: pointer":""}
on:click={() => { if (toast.onclick) toast.onclick(); }}
>
{toast.message}
</ToastBody>
</div>
</Toast>
{/each}
</div>

View File

@ -7,6 +7,7 @@ export interface NewToast {
title?: string,
message?: string,
timeout?: number | undefined
onclick?: () => void
}
export class Toast implements NewToast {
@ -17,11 +18,13 @@ export class Toast implements NewToast {
timeout: number | undefined = undefined;
timeoutInterval: ReturnType<typeof setTimeout> | undefined = undefined;
dismissFunc: (id: string) => void;
onclick: () => void;
constructor(obj: NewToast, dismiss: (id: string) => void) {
if (obj.type !== undefined) this.type = obj.type;
if (obj.title !== undefined) this.title = obj.title;
if (obj.message !== undefined) this.message = obj.message;
if (obj.onclick !== undefined) this.onclick = obj.onclick;
this.timeout = obj.timeout;
this.dismissFunc = dismiss;