Skip to content

Commit

Permalink
add toast
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Nov 18, 2024
1 parent af5e138 commit ee4f20b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 deletions.
70 changes: 46 additions & 24 deletions app/components/copy-text.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
"use client";

import { useState } from "react";
import toast, { Toaster } from "react-hot-toast";

export function CopyText({ text }: { text: string }) {
const [showCheckmark, setShowCheckmark] = useState(false);
const checkmark = (
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M11.35 3.836c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75 2.25 2.25 0 0 0-.1-.664m-5.8 0A2.251 2.251 0 0 1 13.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m8.9-4.414c.376.023.75.05 1.124.08 1.131.094 1.976 1.057 1.976 2.192V16.5A2.25 2.25 0 0 1 18 18.75h-2.25m-7.5-10.5H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V18.75m-7.5-10.5h6.375c.621 0 1.125.504 1.125 1.125v9.375m-8.25-3 1.5 1.5 3-3.75"
/>
);

const handleClick = async (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
navigator.clipboard.writeText(text);
setShowCheckmark(true);
setTimeout(() => setShowCheckmark(false), 1000);
toast.success(`Copied "${text}" to clipboard`);
};

return (
<button
className={`group inline align-text-bottom`}
onClick={async (event) => {
event.preventDefault();
navigator.clipboard.writeText(text);
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={`
group size-4 transition-colors
group-hover:text-slate-400
`}
<button
className={`group inline align-text-bottom`}
onClick={handleClick}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75"
/>
</svg>
</button>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={`
group size-4 transition-colors
group-hover:text-slate-400
`}
>
{showCheckmark ? (
checkmark
) : (
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M8.25 7.5V6.108c0-1.135.845-2.098 1.976-2.192.373-.03.748-.057 1.123-.08M15.75 18H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08M15.75 18.75v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5A3.375 3.375 0 0 0 6.375 7.5H5.25m11.9-3.664A2.251 2.251 0 0 0 15 2.25h-1.5a2.251 2.251 0 0 0-2.15 1.586m5.8 0c.065.21.1.433.1.664v.75h-6V4.5c0-.231.035-.454.1-.664M6.75 7.5H4.875c-.621 0-1.125.504-1.125 1.125v12c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V16.5a9 9 0 0 0-9-9Z"
/>
)}
</svg>
<Toaster />
</button>
);
}
33 changes: 29 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"next-auth": "^4.24.10",
"react": "^18",
"react-dom": "^18",
"react-hot-toast": "^2.4.1",
"sharp": "^0.33.5",
"tailwind-merge": "^2.5.4"
},
Expand Down

0 comments on commit ee4f20b

Please sign in to comment.