Skip to content

Commit aef00ae

Browse files
committed
🎨 Migrate to pheralb/toast
1 parent 4f164bc commit aef00ae

File tree

5 files changed

+76
-55
lines changed

5 files changed

+76
-55
lines changed

website/app/components/card/copyIcon.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, type FC, type SVGProps } from "react";
22

33
import axios from "axios";
4-
import { toast } from "sonner";
4+
import { toast } from "@pheralb/toast";
55
import { Symbols } from "@react-symbols/icons";
66
import { CodeIcon, CopyIcon, LoaderIcon, XIcon } from "lucide-react";
77

@@ -26,8 +26,8 @@ const CopyIconActions = ({ itemName, isFolder, ItemIcon }: CopyIconProps) => {
2626
const handleCopyFromLibrary = async () => {
2727
const code = `<${itemName} />`;
2828
await clipboard(code);
29-
toast.success("Copied to clipboard", {
30-
description: code,
29+
toast.success({
30+
text: "Copied library import",
3131
icon: <ItemIcon width={24} height={24} />,
3232
});
3333
setIsOpen(false);
@@ -41,8 +41,8 @@ const CopyIconActions = ({ itemName, isFolder, ItemIcon }: CopyIconProps) => {
4141
: `${appConfig.shadcnCommand} ${appConfig.registryUrl}folders/${itemNameLower}.json`;
4242

4343
await clipboard(makeCommand);
44-
toast.success("Copied to clipboard", {
45-
description: makeCommand,
44+
toast.success({
45+
text: "Copied shadcn/ui command",
4646
icon: <ItemIcon width={24} height={24} />,
4747
});
4848
setIsOpen(false);
@@ -70,16 +70,16 @@ const CopyIconActions = ({ itemName, isFolder, ItemIcon }: CopyIconProps) => {
7070
content = content.replace(/\r\n/g, "\n");
7171

7272
await clipboard(content);
73-
toast.success("Copied to clipboard", {
74-
description: itemName,
73+
toast.success({
74+
text: "Copied source code",
7575
icon: <ItemIcon width={24} height={24} />,
7676
});
7777
setLoading(false);
7878
setIsOpen(false);
7979
} catch (error) {
8080
console.error("⚠️ Error fetching or copying source code: ", error);
81-
toast.error("Failed to copy source code. Please try again.", {
82-
closeButton: true,
81+
toast.error({
82+
text: "Failed to copy source code. Please try again.",
8383
});
8484
setLoading(false);
8585
}

website/app/components/installCommand.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
type SVGProps,
55
useState,
66
} from "react";
7-
import { toast } from "sonner";
8-
import JSConfetti from "js-confetti";
7+
import { toast } from "@pheralb/toast";
98
import { Bun, NPM, PNPM, Yarn } from "@react-symbols/icons";
109

1110
import { globals } from "@/globals";
@@ -58,16 +57,14 @@ const InstallCommand = (props: iInstallCommandProps) => {
5857
const [selectedInstallCommand, setSelectedInstallCommand] =
5958
useState<iInstallCommands>(installCommands[0]);
6059

61-
const handleCopy = async (text: string, icon: ReactNode) => {
62-
const jsConfetti = new JSConfetti();
63-
jsConfetti.addConfetti({
64-
confettiColors: ["#2563EB", "#0D9488", "#22D3EE", "#C084FC"],
65-
confettiRadius: 3,
66-
confettiNumber: 50,
67-
});
60+
const handleCopy = async (
61+
text: string,
62+
packageManager: string,
63+
icon: ReactNode,
64+
) => {
6865
await clipboard(text);
69-
toast.success("Copied to clipboard", {
70-
description: text,
66+
toast.success({
67+
text: `Copied ${packageManager} command`,
7168
icon: icon,
7269
});
7370
};
@@ -77,7 +74,7 @@ const InstallCommand = (props: iInstallCommandProps) => {
7774
className={cn(
7875
buttonVariants({
7976
variant: "outline",
80-
className: "active:scale-100",
77+
className: "cursor-default active:scale-100",
8178
}),
8279
"select-all space-x-3 rounded-3xl text-zinc-600 hover:bg-transparent dark:text-zinc-400 dark:hover:bg-transparent dark:hover:text-white",
8380
props.className,
@@ -104,7 +101,11 @@ const InstallCommand = (props: iInstallCommandProps) => {
104101
onSelect={() => {
105102
setSelectedInstallCommand(item);
106103
const fullCommand = `${item.command} ${globals.npmPackageName}`;
107-
handleCopy(fullCommand, <item.icon width={24} height={24} />);
104+
handleCopy(
105+
fullCommand,
106+
item.package,
107+
<item.icon width={20} height={20} />,
108+
);
108109
}}
109110
>
110111
<item.icon width={16} height={16} />

website/app/providers/sonner.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

website/app/providers/toaster.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { cn } from "@/utils";
2+
3+
import {
4+
Toaster,
5+
type ToastTheme,
6+
type ToasterProperties,
7+
} from "@pheralb/toast";
8+
import { XIcon } from "lucide-react";
9+
10+
import { useTheme } from "remix-themes";
11+
12+
const CustomToaster = (props: ToasterProperties) => {
13+
const [theme] = useTheme();
14+
return (
15+
<Toaster
16+
theme={theme as ToastTheme}
17+
position="bottom-center"
18+
toastOptions={{
19+
headless: true,
20+
classNames: {
21+
toast: cn(
22+
"font-sans text-sm font-medium z-50 rounded-lg shadow-md relative flex items-center",
23+
"border border-zinc-200 dark:border-zinc-800",
24+
"bg-zinc-100 dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100",
25+
),
26+
container: "flex items-center py-4 space-x-2 px-4 w-full group",
27+
content: "flex flex-col space-y-0.5 mr-2 max-w-[calc(100%-2rem)]",
28+
actions: {
29+
container: "flex flex-col px-3",
30+
actionBtn: cn(
31+
"bg-zinc-200 dark:bg-zinc-700 text-zinc-900 dark:text-zinc-100 hover:bg-zinc-300 dark:hover:bg-zinc-600",
32+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-zinc-500 dark:focus-visible:ring-zinc-400",
33+
"px-2 py-1 text-[12px] font-medium rounded-md transition duration-200 ease-in-out",
34+
),
35+
closeBtn: cn(
36+
"bg-zinc-200 dark:bg-zinc-800",
37+
"text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100",
38+
"border border-zinc-300 dark:border-zinc-600 hover:border-zinc-500 dark:hover:border-zinc-300",
39+
"absolute items-center flex justify-center -top-2 -left-2 transition-colors p-0.5 rounded-full focus:outline-none",
40+
),
41+
},
42+
icon: "flex-shrink-0 mr-2",
43+
},
44+
defaultCloseContent: <XIcon size={12} />,
45+
}}
46+
{...props}
47+
/>
48+
);
49+
};
50+
51+
export default CustomToaster;

website/app/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Navbar from "@/components/navbar";
2727
import Settings from "@/components/settings";
2828

2929
// Providers:
30-
import { Toaster } from "@/providers/sonner";
30+
import CustomToaster from "@/providers/toaster";
3131

3232
// Theme:
3333
import {
@@ -164,7 +164,7 @@ function App() {
164164
<Navbar />
165165
<Outlet />
166166
<Footer />
167-
<Toaster />
167+
<CustomToaster />
168168
<ScrollRestoration />
169169
<Scripts />
170170
</body>

0 commit comments

Comments
 (0)