| 1 | "use client"; |
| 2 | |
| 3 | import { useTheme } from "next-themes"; |
| 4 | import { useSyncExternalStore } |
| 5 | import { Toaster as |
| 6 | import { |
| 7 | CircleCheckIcon, |
| 8 | InfoIcon, |
| 9 | TriangleAlertIcon, |
| 10 | OctagonXIcon, |
| 11 | Loader2Icon, |
| 12 | } from "lucide-react"; |
| 13 | |
| 14 | import { getAppTheme } |
| 15 | |
| 16 | function subscribeToCustomTheme(onChange |
| 17 | const onStorage = |
| 18 | if (e.key |
| 19 | }; |
| 20 | window.addEventListener("storage |
| 21 | window.addEventListener("ghost-custom-theme-changed |
| 22 | return () => |
| 23 | window.removeEventListener("storage |
| 24 | window.removeEventListener("ghost-custom-theme-changed |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | function getCustomThemeBase(): " |
| 29 | try { |
| 30 | const raw = |
| 31 | if (raw) { |
| 32 | const parsed = |
| 33 | return parsed.base |
| 34 | } |
| 35 | } catch { |
| 36 | /* keep default */ |
| 37 | } |
| 38 | return "dark"; |
| 39 | } |
| 40 | |
| 41 | const Toaster = ( |
| 42 | const { theme, |
| 43 | const customBase = |
| 44 | subscribeToCustomTheme, |
| 45 | getCustomThemeBase, |
| 46 | () => "dark" |
| 47 | ); |
| 48 | |
| 49 | const resolved = |
| 50 | let sonnerTheme: |
| 51 | if (resolved === |
| 52 | else if (resolved |
| 53 | else if (resolved) |
| 54 | |
| 55 | return ( |
| 56 | <Sonner |
| 57 | theme={sonnerTheme} |
| 58 | className="toaster group" |
| 59 | icons={{ |
| 60 | success: <CircleCheckIcon className |
| 61 | info: <InfoIcon className |
| 62 | warning: <TriangleAlertIcon className |
| 63 | error: <OctagonXIcon className |
| 64 | loading: <Loader2Icon className |
| 65 | }} |
| 66 | style={ |
| 67 | { |
| 68 | "--normal-bg": "var(--popover)", |
| 69 | "--normal-text": "var(--popover-foreground)", |
| 70 | "--normal-border": "var(--border)", |
| 71 | "--border-radius": "var(--radius)", |
| 72 | } as React. |
| 73 | } |
| 74 | toastOptions={{ |
| 75 | classNames: { |
| 76 | toast: "cn-toast", |
| 77 | }, |
| 78 | }} |
| 79 | {...props} |
| 80 | /> |
| 81 | ); |
| 82 | }; |
| 83 | |
| 84 | export { Toaster }; |