show-notification
<basic.show-notification>
provider显示通知消息。
默认情况下,当通知框以任何形式关闭时,将触发 callback.success
。
如果同时设置 showConfirm: true
和 showCancel: true
,则只有 confirm 按钮按下时触发 callback.success
,其他原因引起的通知框关闭,都将触发 callback.error
。
Examples
Types
Placement
Icon and title
Closable
Operations
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
# | Name | Description | Type |
---|---|---|---|
1 | options | 选项 | NotificationOptions |
Returns
Promise<void>
Type references
NotificationOptions
Name | Type | Required | Description |
---|---|---|---|
type | "success" | "error" | "warn" | "info" | 通知类型 | |
duration | number | 默认三秒后自动关闭 | |
placement | "center" | "topRight" | 弹出位置,默认居中 | |
title | string | null | 通知标题 | |
message | string | null | 通知内容 | |
htmlMessage | string | HTML 格式的通知内容,该内容会被 dom-purify sanitize | |
closable | boolean | 允许手动关闭消息提示 | |
icon | GeneralIconProps & { style?: React.CSSProperties } | 自定义图标 | |
styleType | "circleAngle" | "rectAngle" | 样式类型,默认圆角样式 | |
confirmText | string | 确认文本 | |
confirmLink | LinkOptions | 确认链接选项 | |
cancelText | string | 取消文本 | |
showConfirm | boolean | 展示确认按钮 | |
showCancel | boolean | 展示取消按钮 |
LinkOptions
Name | Type | Required | Description |
---|---|---|---|
url | string | ||
href | string | ||
target | Target |