🔥 了解我们的新项目 t0ggles - 你终极的项目管理工具! 🔥

通知 Svelte 组件

使用通知组件,你可以显示看起来像推送(或本地)系统通知的必要消息。

通知组件

包含以下组件

  • 通知

通知属性

名称类型默认描述
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 主题中使通知背景半透明(使用 backdrop-filter: blur

onClosefunction(e)

关闭元素的点击处理程序

通知插槽

名称描述
button

通知按钮内容

icon

通知图标 HTML 布局或图像

subtitle

通知“副标题”区域的内容

text

通知“文本”区域的内容

title

通知“标题”区域的内容

titlerighttext

通知“标题右侧文本”区域的内容

示例

Notification.svelte
<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" />
<Notification
opened={notificationFull}
title="Konsta UI"
titleRightText="now"
subtitle="This is a subtitle"
text="This is a simple notification message"
>
<DemoIcon slot="icon" />
</Notification>
<Notification
opened={notificationWithButton}
title="Konsta UI"
subtitle="Notification with close button"
text="Click (x) button to close me"
button
onClose={() => (notificationWithButton = false)}
>
<DemoIcon slot="icon" />
</Notification>
<Notification
opened={notificationCloseOnClick}
title="Konsta UI"
titleRightText="now"
subtitle="Notification with close on click"
text="Click me to close"
onClick={() => (notificationCloseOnClick = false)}
>
<DemoIcon slot="icon" />
</Notification>
<Notification
opened={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 to
show some useful messages to user and request basic actions.
</p>
<p>
<Button onClick={() => openNotification(() => (notificationFull = true))}>
Full layout notification
</Button>
</p>
<p>
<Button
onClick={() => openNotification(() => (notificationWithButton = true))}
>
With Close Button
</Button>
</p>
<p>
<Button
onClick={() =>
openNotification(() => (notificationCloseOnClick = true))}
>
Click to Close
</Button>
</p>
<p>
<Button
onClick={() =>
openNotification(() => (notificationCallbackOnClose = true))}
>
Callback on Close
</Button>
</p>
</Block>
</Page>
代码许可证 MIT.
2022 © Konsta UI 由 nolimits4web.