Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(show-notification): support inlineLink #1483

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,20 @@ describe("showNotification", () => {

await expect(promise).resolves.toEqual(undefined);
});

test("inline link", async () => {
act(() => {
showNotification({
message: "Normal",
placement: "topRight",
inlineLink: { text: "查看详情", href: "https://example.com" },
});
});

expect(document.querySelectorAll("eo-link").length).toBe(1);
expect(document.querySelector("eo-link")?.innerHTML).toBe("查看详情");
expect(document.querySelector("eo-link")?.getAttribute("href")).toBe(
"https://example.com"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
hideKeyframeAnimationOptions,
} from "./constants";
import styles from "./notification.module.css";
import { pick } from "lodash";

initializeI18n(NS, locales);

Expand All @@ -37,6 +38,12 @@ export interface NotificationOptions {
message?: string | null;
/** HTML 格式的通知内容,该内容会被 dom-purify sanitize */
htmlMessage?: string;
inlineLink?: {
text: string;
url?: string;
href?: string;
target?: Target;
};
/** 允许手动关闭消息提示 */
closable?: boolean;
/** 自定义图标 */
Expand Down Expand Up @@ -150,6 +157,7 @@ function NotificationComponent({
cancelText,
showConfirm = false,
showCancel = false,
inlineLink,
onOk,
onCancel,
onHide,
Expand Down Expand Up @@ -240,7 +248,17 @@ function NotificationComponent({
dangerouslySetInnerHTML={{ __html: sanitize(htmlMessage) }}
/>
) : message ? (
<div className={styles.message}>{message}</div>
<div className={styles.message}>
{message}
{inlineLink && (
<WrappedLink
{...pick(inlineLink, "url", "href", "target")}
style={{ marginLeft: "0.5em" }}
>
{inlineLink.text}
</WrappedLink>
)}
</div>
) : null}
{(showConfirm || showCancel) && (
<div className={styles.operateWrapper}>
Expand Down
Loading