1
0
Fork 0
mirror of synced 2024-07-02 04:50:44 +12:00

Remove automatic dismissal of error notifications and instead allow only manual dismissal, and also enable pointer events so errors can be copied

This commit is contained in:
Andrew Kingston 2022-02-07 15:15:28 +00:00
parent 22a685aade
commit dd07f3516f
3 changed files with 54 additions and 13 deletions

View file

@ -1,7 +1,12 @@
<script>
import { createEventDispatcher } from "svelte"
export let type = "info"
export let icon = "Info"
export let message = ""
export let dismissable = false
const dispatch = createEventDispatcher()
</script>
<div class="spectrum-Toast spectrum-Toast--{type}">
@ -17,4 +22,28 @@
<div class="spectrum-Toast-body">
<div class="spectrum-Toast-content">{message || ""}</div>
</div>
{#if dismissable}
<div class="spectrum-Toast-buttons">
<button
class="spectrum-ClearButton spectrum-ClearButton--overBackground spectrum-ClearButton--sizeM"
on:click={() => dispatch("dismiss")}
>
<div class="spectrum-ClearButton-fill">
<svg
class="spectrum-ClearButton-icon spectrum-Icon spectrum-UIIcon-Cross100"
focusable="false"
aria-hidden="true"
>
<use xlink:href="#spectrum-css-icon-Cross100" />
</svg>
</div>
</button>
</div>
{/if}
</div>
<style>
.spectrum-Toast {
pointer-events: all;
}
</style>

View file

@ -1,7 +1,6 @@
<script>
import "@spectrum-css/toast/dist/index-vars.css"
import Portal from "svelte-portal"
import { flip } from "svelte/animate"
import { notifications } from "../Stores/notifications"
import Notification from "./Notification.svelte"
import { fly } from "svelte/transition"
@ -9,9 +8,15 @@
<Portal target=".modal-container">
<div class="notifications">
{#each $notifications as { type, icon, message, id } (id)}
<div animate:flip transition:fly={{ y: -30 }}>
<Notification {type} {icon} {message} />
{#each $notifications as { type, icon, message, id, dismissable } (id)}
<div transition:fly={{ y: -30 }}>
<Notification
{type}
{icon}
{message}
{dismissable}
on:dismiss={() => notifications.dismiss(id)}
/>
</div>
{/each}
</div>

View file

@ -20,20 +20,26 @@ export const createNotificationStore = () => {
setTimeout(() => (block = false), timeout)
}
const send = (message, type = "default", icon = "") => {
const send = (message, type = "default", icon = "", timeout = true) => {
if (block) {
return
}
let _id = id()
_notifications.update(state => {
return [...state, { id: _id, type, message, icon }]
return [...state, { id: _id, type, message, icon, dismissable: !timeout }]
})
if (timeout) {
const timeoutId = setTimeout(() => {
dismissNotification(_id)
}, NOTIFICATION_TIMEOUT)
timeoutIds.add(timeoutId)
}
}
const dismissNotification = id => {
_notifications.update(state => {
return state.filter(n => n.id !== id)
})
const timeoutId = setTimeout(() => {
_notifications.update(state => {
return state.filter(({ id }) => id !== _id)
})
}, NOTIFICATION_TIMEOUT)
timeoutIds.add(timeoutId)
}
const { subscribe } = _notifications
@ -42,10 +48,11 @@ export const createNotificationStore = () => {
subscribe,
send,
info: msg => send(msg, "info", "Info"),
error: msg => send(msg, "error", "Alert"),
error: msg => send(msg, "error", "Alert", false),
warning: msg => send(msg, "warning", "Alert"),
success: msg => send(msg, "success", "CheckmarkCircle"),
blockNotifications,
dismiss: dismissNotification,
}
}