使用通知组件,你可以显示看起来像推送(或本地)系统通知的必要消息。
包含以下组件
通知
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
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 | function(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>