UNPKG

@particle-network/auth-core-modal

Version:

Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.

116 lines (113 loc) 5.87 kB
"use client"; import { useAuthCoreModal } from "./chunk-BJTDO4LQ.js"; // src/context/hooks/useMessage.ts import { useCallback, useEffect, useMemo } from "react"; var useMessage = () => { const { authCoreModal } = useAuthCoreModal(); const rootModalContainer = useMemo(() => authCoreModal.rootModalContainer, [authCoreModal]); const createMessage = useCallback( (type, content = "") => { var _a; const mainContainer = document.createElement("div"); mainContainer.className = "ant-message-notice"; const noticeContent = document.createElement("div"); noticeContent.className = "ant-message-notice-content"; const customContent = document.createElement("div"); customContent.className = "ant-message-custom-content"; const iconSpan = document.createElement("span"); iconSpan.setAttribute("role", "img"); iconSpan.setAttribute("aria-label", "check-circle"); iconSpan.className = "anticon anticon-check-circle"; const svgIcon = document.createElement("svg"); const successIcon = '<svg viewBox="64 64 896 896" focusable="false" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg>'; const errorIcon = '<svg viewBox="64 64 896 896" focusable="false" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 01-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"></path></svg>'; const infoIcon = '<svg viewBox="64 64 896 896" focusable="false" data-icon="info-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm32 664c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V456c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v272zm-32-344a48.01 48.01 0 010-96 48.01 48.01 0 010 96z"></path></svg>'; const wranIcon = '<svg viewBox="64 64 896 896" focusable="false" data-icon="exclamation-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm-32 232c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v272c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V296zm32 440a48.01 48.01 0 010-96 48.01 48.01 0 010 96z"></path></svg>'; if (type === "success" /* success */) { customContent.className += " ant-message-success"; svgIcon.innerHTML = successIcon; } else if (type === "error" /* error */) { customContent.className += " ant-message-error"; svgIcon.innerHTML = errorIcon; } else if (type === "info" /* info */) { customContent.className += " ant-message-info"; svgIcon.innerHTML = infoIcon; } else if (type === "warning" /* warning */) { customContent.className += " ant-message-warning"; svgIcon.innerHTML = wranIcon; } const textSpan = document.createElement("span"); textSpan.textContent = content; iconSpan.appendChild(svgIcon); customContent.appendChild(iconSpan); customContent.appendChild(textSpan); noticeContent.appendChild(customContent); mainContainer.appendChild(noticeContent); (_a = rootModalContainer == null ? void 0 : rootModalContainer.querySelector(".ant-message")) == null ? void 0 : _a.appendChild(mainContainer); return mainContainer; }, [rootModalContainer] ); const error = useCallback( (content) => { const el = createMessage("error" /* error */, content); setTimeout(() => { var _a; (_a = rootModalContainer == null ? void 0 : rootModalContainer.querySelector(".ant-message")) == null ? void 0 : _a.removeChild(el); }, 2e3); }, [createMessage] ); const info = useCallback( (content) => { const el = createMessage("info" /* info */, content); setTimeout(() => { var _a; (_a = rootModalContainer == null ? void 0 : rootModalContainer.querySelector(".ant-message")) == null ? void 0 : _a.removeChild(el); }, 2e3); }, [createMessage] ); const success = useCallback( (content) => { const el = createMessage("success" /* success */, content); setTimeout(() => { var _a; (_a = rootModalContainer == null ? void 0 : rootModalContainer.querySelector(".ant-message")) == null ? void 0 : _a.removeChild(el); }, 2e3); }, [createMessage] ); const warning = useCallback( (content) => { const el = createMessage("warning" /* warning */, content); setTimeout(() => { var _a; (_a = rootModalContainer == null ? void 0 : rootModalContainer.querySelector(".ant-message")) == null ? void 0 : _a.removeChild(el); }, 2e3); }, [createMessage] ); useEffect(() => { if (rootModalContainer) { if (rootModalContainer.querySelector(".ant-message")) return; const messageContainer = document.createElement("div"); messageContainer.className = "ant-message"; rootModalContainer.appendChild(messageContainer); } }, [rootModalContainer]); return { error, info, success, warning }; }; var useMessage_default = useMessage; export { useMessage_default }; //# sourceMappingURL=chunk-KDYMIS2J.js.map