UNPKG

@trail-ui/react

Version:
72 lines (69 loc) 2.36 kB
import { _ModalCloseButton } from "./chunk-HJBQYCHB.mjs"; import { ModalContent } from "./chunk-4F3E6TCQ.mjs"; import { ModalHeader } from "./chunk-XXNXU5A5.mjs"; import { _Modal } from "./chunk-66DN4CGG.mjs"; import { _Button } from "./chunk-VGPOEUEE.mjs"; // src/offline-toast/offline-toast.tsx import { useEffect, useState } from "react"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; function OfflineWarning() { const [isOffline, setIsOffline] = useState(false); function handleRetry() { if (navigator.onLine) { setIsOffline(false); } else { alert("Still offline, please check your connection"); } } useEffect(() => { function handleOffline() { setIsOffline(true); } function handleOnline() { setIsOffline(false); } window.addEventListener("offline", handleOffline); window.addEventListener("online", handleOnline); return () => { window.removeEventListener("offline", handleOffline); window.removeEventListener("online", handleOnline); }; }, []); return isOffline ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx( _Modal, { backdrop: "opaque", className: "w-[480px] overflow-auto rounded border border-neutral-200", size: "xl", placement: "center", isOpen: isOffline, onOpenChange: () => setIsOffline(!isOffline), children: /* @__PURE__ */ jsxs(ModalContent, { "aria-labelledby": "offline-modal-header", children: [ /* @__PURE__ */ jsx( ModalHeader, { id: "offline-modal-header", className: "flex items-center justify-between border-b border-b-neutral-200 bg-neutral-100 px-10 py-4 pr-16 text-xl font-medium text-neutral-950", children: "Network Error" } ), /* @__PURE__ */ jsx(_ModalCloseButton, {}), /* @__PURE__ */ jsx("p", { className: "px-10 py-4 text-lg font-normal text-neutral-700", children: "You are offline, kindly check your internet connection." }), /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end border-t border-t-neutral-200 bg-neutral-100 px-12 py-4", children: /* @__PURE__ */ jsx(_Button, { appearance: "primary", onPress: handleRetry, children: "Retry" }) }) ] }) } ) }) : null; } export { OfflineWarning };