feat: add notification stack component and integrate into AppShell
This commit is contained in:
1 parent
c4b40a9c36
commit
c5450a72d6
7 files changed
+521
-9
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { NavItem } from '../types';
|
||||
import Header from './Header.svelte';
|
||||
import NotificationStack from './NotificationStack.svelte';
|
||||
import PageHeader from './PageHeader.svelte';
|
||||
|
||||
let {
|
||||
@@ -54,6 +55,8 @@
|
||||
</script>
|
||||
|
||||
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
|
||||
<NotificationStack />
|
||||
|
||||
<Header
|
||||
aboutHref={aboutHref ?? navItems.find((item) => item.label.toLowerCase() === 'about')?.href ?? '/about'}
|
||||
{brand}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<script lang="ts">
|
||||
import { CircleAlert, CircleCheck, Info, OctagonAlert, X } from '@lucide/svelte';
|
||||
import { fly } from 'svelte/transition';
|
||||
import { notifications } from '../notifications.svelte';
|
||||
import type { NotificationVariant } from '../notifications.svelte';
|
||||
|
||||
const icons: Record<NotificationVariant, typeof Info> = {
|
||||
success: CircleCheck,
|
||||
error: OctagonAlert,
|
||||
warning: CircleAlert,
|
||||
info: Info
|
||||
};
|
||||
</script>
|
||||
|
||||
<div aria-live="polite" class="sc-notification-stack" role="status">
|
||||
{#each notifications.entries as entry (entry.id)}
|
||||
{@const Icon = icons[entry.variant]}
|
||||
<div class="sc-notification" data-variant={entry.variant} transition:fly={{ y: -12, duration: 180 }}>
|
||||
<Icon aria-hidden="true" class="sc-notification-icon" size={18} />
|
||||
<p class="sc-notification-message">{entry.message}</p>
|
||||
<button
|
||||
aria-label="Dismiss notification"
|
||||
class="sc-notification-close"
|
||||
type="button"
|
||||
onclick={() => notifications.dismiss(entry.id)}
|
||||
>
|
||||
<X aria-hidden="true" size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
Reference in new issue
Block a user