🔥 隆重推出我們的全新專案 t0ggles - 您終極的專案管理工具! 🔥

通知 React 組件

使用通知組件,您可以顯示看起來像推播(或本地)系統通知的必要訊息。

通知組件

包含以下組件

  • 通知

通知 Props

名稱類型預設值描述
buttonReactNode

通知按鈕內容

colorsobject

包含 Tailwind CSS 色彩類別的物件

colors.bgIosstring'bg-white dark:bg-[#1e1e1e]'

iOS 主題中的通知背景顏色

colors.bgMaterialstring'bg-md-light-surface-5 dark:bg-md-dark-surface-5'

Material 主題中的通知背景顏色

colors.deleteIconIosstring'fill-stone-400 active:fill-stone-200 dark:fill-stone-500 dark:active:fill-stone-700'

IOS 主題中的通知刪除圖示顏色

colors.deleteIconMdstring'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant'

Material 主題中的通知刪除圖示顏色

colors.subtitleIosstring'text-black dark:text-white'

IOS 主題中的通知副標題顏色

colors.textMaterialstring'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant'

Material 主題中的通知文字顏色

colors.titleIosstring'text-black dark:text-white'

IOS 主題中的通知標題顏色

colors.titleRightIosstring'text-opacity-45 text-black dark:text-white dark:text-opacity-45'

IOS 主題中的通知右側文字顏色

colors.titleRightMdstring'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 主題中的通知右側文字顏色

componentstring'div'

組件的 HTML 元素

iconReactNode

通知圖示 HTML 佈局或圖片

openedbooleanundefined

允許開啟/關閉通知並設定其初始狀態

subtitleReactNode

通知「副標題」區域的內容

textReactNode

通知「文字」區域的內容

titleReactNode

通知「標題」區域的內容

titleRightTextReactNode

通知「右側標題文字」區域的內容

translucentbooleantrue

在 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.