跳到主要内容

show-notification

<basic.show-notification>provider

显示通知消息。

默认情况下,当通知框以任何形式关闭时,将触发 callback.success

如果同时设置 showConfirm: trueshowCancel: true,则只有 confirm 按钮按下时触发 callback.success,其他原因引起的通知框关闭,都将触发 callback.error

Examples

Types

Playground

voice play

Playground

Placement

Playground

Icon and title

Playground

Closable

Playground

Operations

Playground

Usage in pro-code

import { unwrapProvider } from "@next-core/utils/general";
import type { showNotification as _showNotification } from "@next-bricks/basic/data-providers/show-notification/show-notification";

// Use `unwrapProvider` to get the original function of a provider
const showNotification = unwrapProvider<typeof _showNotification>(
"basic.show-notification"
);

function MyComponent() {
const handleClick = useCallback(() => {
showNotification({
type: "success",
message: "Done!",
});
}, []);
return <button onClick={handleClick} />;
}

Definition

Parameters

#NameDescriptionType
1options

选项

NotificationOptions

Returns

Promise<void>

Type references

NotificationOptions

NameDescriptionTypeDefaultRequired
type

通知类型

"success" | "error" | "warn" | "info"
duration

默认三秒后自动关闭

number
placement

弹出位置,默认居中

"center" | "topRight"
title

通知标题

string | null
message

通知内容

string | null
htmlMessage

HTML 格式的通知内容,该内容会被 dom-purify sanitize

string
inlineLink{ text: string; url?: string; href?: string; target?: Target }
closable

允许手动关闭消息提示

boolean
icon

自定义图标

GeneralIconProps & { style?: React.CSSProperties }
styleType

样式类型,默认圆角样式

"circleAngle" | "rectAngle"
confirmText

确认文本

string
confirmLink

确认链接选项

LinkOptions
cancelText

取消文本

string
showConfirm

展示确认按钮

boolean
showCancel

展示取消按钮

boolean
voiceContent

语音播报的内容

string
voiceOptions

语音播报配置

SpeechNotificationsOptions

LinkOptions

NameDescriptionTypeDefaultRequired
urlstring
hrefstring
targetTarget