Allow client notifications to be stacked
This commit is contained in:
parent
5db7a80dcd
commit
6e9ece3cd7
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<div class="notifications">
|
<div class="notifications">
|
||||||
{#if $notificationStore}
|
{#if $notificationStore}
|
||||||
{#key $notificationStore.id}
|
{#each $notificationStore as { type, icon, message, id, dismissable } (id)}
|
||||||
<div
|
<div
|
||||||
in:fly={{
|
in:fly={{
|
||||||
duration: 300,
|
duration: 300,
|
||||||
|
@ -16,14 +16,14 @@
|
||||||
out:fly={{ y: -20, duration: 150 }}
|
out:fly={{ y: -20, duration: 150 }}
|
||||||
>
|
>
|
||||||
<Notification
|
<Notification
|
||||||
type={$notificationStore.type}
|
{type}
|
||||||
message={$notificationStore.message}
|
{message}
|
||||||
icon={$notificationStore.icon}
|
{icon}
|
||||||
dismissable={$notificationStore.dismissable}
|
{dismissable}
|
||||||
on:dismiss={notificationStore.actions.dismiss}
|
on:dismiss={() => notificationStore.actions.dismiss(id)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/key}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@
|
||||||
.notifications {
|
.notifications {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
|
bottom: 40px;
|
||||||
|
width: 25%;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
@ -39,7 +41,8 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: center;
|
align-items: end;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
gap: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -8,9 +8,10 @@ const createNotificationStore = () => {
|
||||||
let timeout
|
let timeout
|
||||||
let block = false
|
let block = false
|
||||||
|
|
||||||
const store = writable(null, () => {
|
const store = writable([], () => {
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
|
store.set([])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,15 +38,17 @@ const createNotificationStore = () => {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
store.update(state => {
|
||||||
store.set({
|
return [...state,
|
||||||
|
{
|
||||||
id: generate(),
|
id: generate(),
|
||||||
type,
|
type,
|
||||||
message,
|
message,
|
||||||
icon,
|
icon,
|
||||||
dismissable: !autoDismiss,
|
dismissable: !autoDismiss,
|
||||||
delay: get(store) != null,
|
delay: get(store) != null,
|
||||||
})
|
}
|
||||||
|
]})
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
if (autoDismiss) {
|
if (autoDismiss) {
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
|
@ -54,9 +57,11 @@ const createNotificationStore = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dismiss = () => {
|
const dismiss = id => {
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
store.set(null)
|
store.update(state => {
|
||||||
|
return state.filter(n => n.id !== id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue