🔥 新しいプロジェクトのご紹介 t0ggles - 究極のプロジェクト管理ツール! 🔥

Notification React コンポーネント

Notification コンポーネントを使用すると、プッシュ(またはローカル)システム通知のように見える必要なメッセージを表示できます。

Notification コンポーネント

以下のようなコンポーネントが含まれています

  • 通知

Notification プロパティ

名前デフォルト説明
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.