Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor: improve sonner toast

Marc Seitzee84c6b6077d
diff --git a/components/ui/sonner.tsx b/components/ui/sonner.tsx
new file mode 100644
index 00000000..549cf841
--- /dev/null
+++ b/components/ui/sonner.tsx
@@ -0,0 +1,31 @@
+"use client";
+
+import { useTheme } from "next-themes";
+import { Toaster as Sonner } from "sonner";
+
+type ToasterProps = React.ComponentProps<typeof Sonner>;
+
+const Toaster = ({ ...props }: ToasterProps) => {
+ const { theme = "system" } = useTheme();
+
+ return (
+ <Sonner
+ theme={theme as ToasterProps["theme"]}
+ className="toaster group"
+ toastOptions={{
+ classNames: {
+ toast:
+ "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
+ description: "group-[.toast]:text-muted-foreground",
+ actionButton:
+ "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
+ cancelButton:
+ "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
+ },
+ }}
+ {...props}
+ />
+ );
+};
+
+export { Toaster };
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 7a8d2b44..b7c1d5aa 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -3,7 +3,7 @@ import type { AppProps } from "next/app";
import { Inter } from "next/font/google";
import type { Session } from "next-auth";
import { SessionProvider } from "next-auth/react";
-import { Toaster } from "sonner";
+import { Toaster } from "@/components/ui/sonner";
import Head from "next/head";
import { Analytics } from "@vercel/analytics/react";
import PlausibleProvider from "next-plausible";
@@ -65,7 +65,7 @@ export default function App({
enabled={process.env.NEXT_PUBLIC_VERCEL_ENV === "production"}
>
<main className={inter.className}>
- <Toaster closeButton richColors theme={"system"} />
+ <Toaster closeButton richColors />
<TeamProvider>
<Component {...pageProps} />
</TeamProvider>