With Notification component you can show required messages that looks like Push (or Local) system notifications.
There are following components included:
Notification
Name | Type | Default | Description |
---|---|---|---|
colors | object | Object with Tailwind CSS colors classes | |
colors.bgIos | string | 'bg-ios-light-glass dark:bg-ios-dark-glass' | Notifiaction bg color in iOS theme |
colors.bgMaterial | string | 'bg-md-light-surface-5 dark:bg-md-dark-surface-5' | Notification bg color in Material theme |
colors.deleteIconIos | string | 'fill-stone-400 active:fill-stone-200 dark:fill-stone-500 dark:active:fill-stone-700' | Notification Delete Icon color in IOS theme |
colors.deleteIconMd | string | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | Notification Delete Icon color in Material theme |
colors.subtitleIos | string | 'text-black dark:text-white' | Notification subtitle color in IOS theme |
colors.textMaterial | string | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | Notification text color in Material theme |
colors.titleIos | string | 'text-black dark:text-white' | Notification title color in IOS theme |
colors.titleRightIos | string | 'text-black/45 dark:text-white/45' | Notification right text color in IOS theme |
colors.titleRightMd | string | 'text-md-light-on-surface-variant before:bg-md-light-on-surface-variant dark:text-md-dark-on-surface-variant before:dark:bg-md-dark-on-surface-variant' | Notification right text color in Material theme |
onClose | function(e) | Click handler on to close element | |
opened | boolean | undefined | Allows to open/close Notification and set its initial state |
subtitle | string | Content of the notification "subtitle" area | |
text | string | Content of the notification "text" area | |
title | string | Content of the notification "title" area | |
titleRightText | string | Content of the notification "title right text" area |
Name | Description |
---|---|
button | Notification button content |
icon | Notification icon HTML layout or image |
subtitle | Content of the notification "subtitle" area |
text | Content of the notification "text" area |
title | Content of the notification "title" area |
titlerighttext | Content of the notification "title right text" area |
<script>import {Page,Navbar,NavbarBackLink,Block,Notification,Button,Dialog,DialogButton,} from 'konsta/svelte';import DemoIcon from '../components/DemoIcon.svelte';let notificationFull = $state(false);let notificationWithButton = $state(false);let notificationCloseOnClick = $state(false);let notificationCallbackOnClose = $state(false);let alertOpened = $state(false);const openNotification = (setter) => {notificationFull = false;notificationWithButton = false;notificationCloseOnClick = false;notificationCallbackOnClose = false;setter();if (notificationFull) {setTimeout(() => {notificationFull = false;}, 3000);}};</script><Page><Navbar title="Notification">{#snippet left()}{#if !isPreview}<NavbarBackLink onclick={() => history.back()} />{/if}{/snippet}</Navbar><Notificationopened={notificationFull}title="Konsta UI"titleRightText="now"subtitle="This is a subtitle"text="This is a simple notification message">{#snippet icon()}<DemoIcon />{/snippet}</Notification><Notificationopened={notificationWithButton}title="Konsta UI"subtitle="Notification with close button"text="Click (x) button to close me"buttononClose={() => (notificationWithButton = false)}>{#snippet icon()}<DemoIcon />{/snippet}</Notification><Notificationopened={notificationCloseOnClick}title="Konsta UI"titleRightText="now"subtitle="Notification with close on click"text="Click me to close"onclick={() => (notificationCloseOnClick = false)}>{#snippet icon()}<DemoIcon />{/snippet}</Notification><Notificationopened={notificationCallbackOnClose}title="Konsta UI"titleRightText="now"subtitle="Notification with close on click"text="Click me to close"onclick={() => {notificationCallbackOnClose = false;alertOpened = true;}}>{#snippet icon()}<DemoIcon />{/snippet}</Notification><Dialog opened={alertOpened} onBackdropClick={() => (alertOpened = false)}>{#snippet title()}Konsta UI{/snippet}Notification closed{#snippet buttons()}<DialogButton onclick={() => (alertOpened = false)}>Ок</DialogButton>{/snippet}</Dialog><Block strong inset class="space-y-4"><p>Konsta UI comes with simple Notifications component that allows you toshow some useful messages to user and request basic actions.</p><p><Buttonroundedonclick={() => openNotification(() => (notificationFull = true))}>Full layout notification</Button></p><p><Buttonroundedonclick={() => openNotification(() => (notificationWithButton = true))}>With Close Button</Button></p><p><Buttonroundedonclick={() =>openNotification(() => (notificationCloseOnClick = true))}>Click to Close</Button></p><p><Buttonroundedonclick={() =>openNotification(() => (notificationCallbackOnClose = true))}>Callback on Close</Button></p></Block></Page>