-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from santiment/feat/notifications-implementat…
…ion-using-svelte-5-san-webkit-next feat(notifications): added notifications
- Loading branch information
Showing
8 changed files
with
185 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default } from './InsightCard.svelte'; | ||
export { default } from './InsightCard.svelte' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher, type Snippet } from 'svelte' | ||
import Button from '$ui/core/Button/index.js' | ||
import Svg from '$ui/core/Svg/index.js' | ||
import { cn } from '$ui/utils/index.js' | ||
type Props = { | ||
icon: 'info' | 'checkmark-circle' | 'warning' | 'error' | ||
message: string | ||
content?: string | Snippet | ||
action?: { label: string; onClick: (event: MouseEvent) => void } | ||
class?: string | ||
} | ||
const { icon, message, content, action, class: className }: Props = $props() | ||
const dispatch = createEventDispatcher() | ||
const ICONS = { | ||
info: { class: 'fill-waterloo' }, | ||
'checkmark-circle': { class: 'fill-green' }, | ||
warning: { class: 'fill-orange', h: 14 }, | ||
error: { class: 'fill-red' }, | ||
} | ||
</script> | ||
|
||
<section | ||
role="alert" | ||
class={cn( | ||
'flex w-[460px] max-w-full gap-4 rounded-lg border bg-white pl-6 pr-2.5 pt-5 shadow', | ||
content && !action ? 'pb-6' : 'pb-5', | ||
className, | ||
)} | ||
> | ||
<figure class="flex h-6 w-4 center"> | ||
<Svg id={icon} {...ICONS[icon]} /> | ||
</figure> | ||
|
||
<div class="flex-1 items-start gap-2 column"> | ||
<h4 class="text-base font-medium text-rhino">{message}</h4> | ||
|
||
{#if content} | ||
<p class="text-base text-fiord"> | ||
{#if typeof content === 'function'} | ||
{@render content()} | ||
{:else} | ||
{content} | ||
{/if} | ||
</p> | ||
{/if} | ||
|
||
{#if action} | ||
<Button variant="fill" class="mt-1" onclick={action.onClick}> | ||
{action.label} | ||
</Button> | ||
{/if} | ||
</div> | ||
|
||
<Button | ||
aria-label="Close notification" | ||
icon="close" | ||
iconSize={10} | ||
class="-ml-2 -mt-2.5 flex size-5 rounded !fill-waterloo center hover:bg-porcelain xs:size-8" | ||
onclick={() => dispatch('closeToast')} | ||
/> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
<script lang="ts"> | ||
import { BROWSER } from 'esm-env' | ||
import { Toaster } from 'svelte-sonner' | ||
import { useDeviceCtx } from '$lib/ctx/device/index.svelte.js' | ||
const { device } = useDeviceCtx() | ||
</script> | ||
|
||
{#if BROWSER} | ||
<Toaster | ||
position="bottom-left" | ||
toastOptions={{ | ||
unstyled: true, | ||
classes: { | ||
toast: 'border rounded shadow bg-white row p-4 gap-2', | ||
title: 'text-black font-medium', | ||
description: 'text-waterloo', | ||
success: 'fill-green', | ||
}, | ||
}} | ||
position={device.$.isMobile ? 'top-center' : 'bottom-left'} | ||
toastOptions={{ unstyled: true }} | ||
></Toaster> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
import type { ComponentProps, ComponentType } from 'svelte' | ||
import { toast } from 'svelte-sonner' | ||
import Component from './Notification.svelte' | ||
|
||
export { default } from './Notifications.svelte' | ||
export { toast as notifcation } from 'svelte-sonner' | ||
|
||
type TOptions = Omit<ComponentProps<Component>, 'icon' | 'message'> & { duration?: number } | ||
type TIcon = ComponentProps<Component>['icon'] | ||
|
||
function createToast(icon: TIcon, message: string, { duration = 5000, ...options }: TOptions = {}) { | ||
return toast.custom(Component as unknown as ComponentType, { | ||
duration, | ||
componentProps: { ...options, icon, message }, | ||
}) | ||
} | ||
|
||
const createNotificationType = | ||
(icon: TIcon) => | ||
(...rest: [message: string, options?: TOptions]) => | ||
createToast(icon, ...rest) | ||
|
||
const notification: Record< | ||
'info' | 'error' | 'warning' | 'success', | ||
(message: string, options?: TOptions) => string | number | ||
> = { | ||
info: createNotificationType('info'), | ||
error: createNotificationType('error'), | ||
warning: createNotificationType('warning'), | ||
success: createNotificationType('checkmark-circle'), | ||
} | ||
|
||
export { notification } |
85 changes: 76 additions & 9 deletions
85
src/stories/Design System - Core UI/Notifications/index.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters