feat: implement new alerts

This commit is contained in:
Arman
2022-06-10 10:53:15 +02:00
parent 1e572bb20f
commit 25de2b42eb
3 changed files with 49 additions and 12 deletions
+45 -8
View File
@@ -3,17 +3,54 @@
import type { Notification } from '../stores/notifications';
export let type: Notification['type'] = 'info';
export let title: Notification['title'];
let icon: string;
switch (type) {
case 'success':
icon = 'check-circle';
break;
case 'warning':
icon = 'exclamation';
break;
case 'error':
icon = 'exclamation-circle';
break;
case 'info':
icon = 'info';
break;
default:
icon = '';
break;
}
const dispatch = createEventDispatcher();
</script>
<li class="toaster-item">
<div class={`toaster-message is-${type}`}>
<button class="x-button" on:click={() => dispatch('dismiss')}>
<span class="icon-cancel" aria-hidden="true" />
</button>
<span class="text">
<slot />
</span>
<li class={`alert-sticky is-${type}`}>
<button class="x-button" aria-label="close alert" on:click={() => dispatch('dismiss')}>
<span class="icon-x" aria-hidden="true" />
</button>
<div class="alert-sticky-image">
<span class={`icon-${icon}`} aria-hidden="true" />
</div>
<div class="alert-sticky-content">
{#if title}
<h4 class="alert-sticky-title">{title}</h4>
{/if}
<p><slot /></p>
</div>
<!--
<div class="buttons u-flex">
<button class="button is-text is-small">
<span class="text">Action 1</span>
</button>
<button class="button is-text is-small">
<span class="text">Action 2</span>
</button>
</div>
-->
</li>
+3 -4
View File
@@ -9,6 +9,7 @@
{#each $notifications as notification (notification.id)}
<Notification
type={notification.type}
title={notification.title}
on:dismiss={() => dismissNotification(notification.id)}>
{notification.message}
</Notification>
@@ -20,10 +21,8 @@
<style lang="scss">
section {
position: fixed;
bottom: 0;
left: 0;
right: 0;
top: calc(var(--main-header-height) + 24px);
right: 24px;
z-index: 1000;
margin-bottom: 0.5rem;
}
</style>
+1
View File
@@ -6,6 +6,7 @@ export type Notification = {
dismissible?: boolean;
timeout?: number;
message: string;
title?: string;
};
let counter = 0;