使用通知元件,您可以顯示看起來像推播(或本機)系統通知的必要訊息。
包含以下元件
通知
名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
colors | 物件 | 具有 Tailwind CSS 色彩類別的物件 | |
colors.bgIos | 字串 | 'bg-white dark:bg-[#1e1e1e]' | iOS 主題中的通知背景顏色 |
colors.bgMaterial | 字串 | 'bg-md-light-surface-5 dark:bg-md-dark-surface-5' | Material 主題中的通知背景顏色 |
colors.deleteIconIos | 字串 | 'fill-stone-400 active:fill-stone-200 dark:fill-stone-500 dark:active:fill-stone-700' | IOS 主題中的通知刪除圖示顏色 |
colors.deleteIconMd | 字串 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | Material 主題中的通知刪除圖示顏色 |
colors.subtitleIos | 字串 | 'text-black dark:text-white' | IOS 主題中的通知副標題顏色 |
colors.textMaterial | 字串 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | Material 主題中的通知文字顏色 |
colors.titleIos | 字串 | 'text-black dark:text-white' | IOS 主題中的通知標題顏色 |
colors.titleRightIos | 字串 | 'text-opacity-45 text-black dark:text-white dark:text-opacity-45' | IOS 主題中的通知右側文字顏色 |
colors.titleRightMd | 字串 | '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' | Material 主題中的通知右側文字顏色 |
opened | 布林值 | 未定義 | 允許開啟/關閉通知並設定其初始狀態 |
subtitle | 字串 | 通知「副標題」區域的內容 | |
text | 字串 | 通知「文字」區域的內容 | |
title | 字串 | 通知「標題」區域的內容 | |
titleRightText | 字串 | 通知「標題右側文字」區域的內容 | |
translucent | 布林值 | true | 使 iOS 主題中的通知背景半透明(具有 |
onClose | 函式(e) | 點擊關閉元素時的處理函式 |
名稱 | 描述 |
---|---|
button | 通知按鈕內容 |
icon | 通知圖示 HTML 佈局或影像 |
subtitle | 通知「副標題」區域的內容 |
text | 通知「文字」區域的內容 |
title | 通知「標題」區域的內容 |
titlerighttext | 通知「標題右側文字」區域的內容 |
<script>import {Page,Navbar,NavbarBackLink,Block,Notification,Button,Dialog,DialogButton,} from 'konsta/svelte';import DemoIcon from '../components/DemoIcon.svelte';let notificationFull = false;let notificationWithButton = false;let notificationCloseOnClick = false;let notificationCallbackOnClose = false;let alertOpened = false;const openNotification = (setter) => {notificationFull = false;notificationWithButton = false;notificationCloseOnClick = false;notificationCallbackOnClose = false;setter();if (notificationFull) {setTimeout(() => {notificationFull = false;}, 3000);}};</script><Page><Navbar title="Notification" /><Notificationopened={notificationFull}title="Konsta UI"titleRightText="now"subtitle="This is a subtitle"text="This is a simple notification message"><DemoIcon slot="icon" /></Notification><Notificationopened={notificationWithButton}title="Konsta UI"subtitle="Notification with close button"text="Click (x) button to close me"buttononClose={() => (notificationWithButton = false)}><DemoIcon slot="icon" /></Notification><Notificationopened={notificationCloseOnClick}title="Konsta UI"titleRightText="now"subtitle="Notification with close on click"text="Click me to close"onClick={() => (notificationCloseOnClick = false)}><DemoIcon slot="icon" /></Notification><Notificationopened={notificationCallbackOnClose}title="Konsta UI"titleRightText="now"subtitle="Notification with close on click"text="Click me to close"onClick={() => {notificationCallbackOnClose = false;alertOpened = true;}}><DemoIcon slot="icon" /></Notification><Dialog opened={alertOpened} onBackdropClick={() => (alertOpened = false)}><svelte:fragment slot="title">Konsta UI</svelte:fragment>Notification closed<svelte:fragment slot="buttons"><DialogButton onClick={() => (alertOpened = false)}>Ок</DialogButton></svelte:fragment></Dialog><Block strongIos outlineIos 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><Button onClick={() => openNotification(() => (notificationFull = true))}>Full layout notification</Button></p><p><ButtononClick={() => openNotification(() => (notificationWithButton = true))}>With Close Button</Button></p><p><ButtononClick={() =>openNotification(() => (notificationCloseOnClick = true))}>Click to Close</Button></p><p><ButtononClick={() =>openNotification(() => (notificationCallbackOnClose = true))}>Callback on Close</Button></p></Block></Page>