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

通知 React 组件

使用通知组件,你可以显示类似于推送(或本地)系统通知的必要消息。

通知组件

以下组件已包含在内

  • 通知

通知属性

名称类型默认值描述
按钮ReactNode

通知按钮内容

颜色对象

包含 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 主题中的通知右侧文本颜色

组件字符串'div'

组件的 HTML 元素

图标ReactNode

通知图标 HTML 布局或图像

已打开布尔值未定义

允许打开/关闭通知并设置其初始状态

副标题ReactNode

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

文本ReactNode

通知“文本”区域的内容

标题ReactNode

通知“标题”区域的内容

titleRightTextReactNode

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

半透明布尔值真的

在 iOS 主题中使通知背景半透明(使用 backdrop-filter: blur

onClosefunction(e)

单击关闭元素的处理程序

示例

Notification.jsx
import React, { useState, useEffect } from 'react';
import {
Page,
Navbar,
NavbarBackLink,
Block,
Notification,
Button,
Dialog,
DialogButton,
} from 'konsta/react';
import DemoIcon from '../components/DemoIcon';
export default function NotificationPage() {
const [notificationFull, setNotificationFull] = useState(false);
const [notificationWithButton, setNotificationWithButton] = useState(false);
const [notificationCloseOnClick, setNotificationCloseOnClick] =
useState(false);
const [notificationCallbackOnClose, setNotificationCallbackOnClose] =
useState(false);
const [alertOpened, setAlertOpened] = useState(false);
const openNotification = (setter) => {
setNotificationFull(false);
setNotificationWithButton(false);
setNotificationCloseOnClick(false);
setNotificationCallbackOnClose(false);
setter(true);
};
useEffect(() => {
let timer;
if (notificationFull) {
timer = setTimeout(() => {
setNotificationFull(false);
}, 3000);
}
return () => clearTimeout(timer);
}, [notificationFull]);
return (
<Page>
<Navbar
title="Notification"
/>
<Notification
opened={notificationFull}
icon={<DemoIcon />}
title="Konsta UI"
titleRightText="now"
subtitle="This is a subtitle"
text="This is a simple notification message"
/>
<Notification
opened={notificationWithButton}
icon={<DemoIcon />}
title="Konsta UI"
button
onClick={() => setNotificationWithButton(false)}
subtitle="Notification with close button"
text="Click (x) button to close me"
/>
<Notification
opened={notificationCloseOnClick}
icon={<DemoIcon />}
title="Konsta UI"
titleRightText="now"
subtitle="Notification with close on click"
text="Click me to close"
onClick={() => setNotificationCloseOnClick(false)}
/>
<Notification
opened={notificationCallbackOnClose}
icon={<DemoIcon />}
title="Konsta UI"
titleRightText="now"
subtitle="Notification with close on click"
text="Click me to close"
onClick={() => {
setNotificationCallbackOnClose(false);
setAlertOpened(true);
}}
/>
<Dialog
opened={alertOpened}
onBackdropClick={() => setAlertOpened(false)}
title="Konsta UI"
content="Notification closed"
buttons={
<DialogButton onClick={() => setAlertOpened(false)}>Ok</DialogButton>
}
/>
<Block strongIos outlineIos className="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(setNotificationFull)}>
Full layout notification
</Button>
</p>
<p>
<Button onClick={() => openNotification(setNotificationWithButton)}>
With Close Button
</Button>
</p>
<p>
<Button onClick={() => openNotification(setNotificationCloseOnClick)}>
Click to Close
</Button>
</p>
<p>
<Button
onClick={() => openNotification(setNotificationCallbackOnClose)}
>
Callback on Close
</Button>
</p>
</Block>
</Page>
);
}
代码许可证 MIT.
2022 © Konsta UI by nolimits4web.