File size: 1,513 Bytes
7f5876d
 
 
 
 
 
 
 
 
 
468851d
7f5876d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import classNames from "classnames";
import { CopyIcon } from "lucide-react";
import { useMemo, useState } from "react";
import { useCopyToClipboard, useUpdateEffect } from "react-use";

export const CopyToClipboard = ({ id }: { id: string }) => {
  const [state, copyToClipboard] = useCopyToClipboard();
  const [copied, setCopied] = useState(false);

  const url = useMemo(() => {
    return `https://enzostvs-hugger-lover.hf.space/${id}`;
  }, [id]);

  const handleCopy = () => {
    setCopied(true);
    copyToClipboard(url);
    setTimeout(() => {
      setCopied(false);
    }, 2000);
  };

  return (
    <div className="w-full mt-5">
      <p className="text-xs text-zinc-500">
        Share this link with your friends to see how much they love you! πŸ’Œ
      </p>
      <div
        className="bg-white mt-2 max-w-max rounded-md mr-2 border border-gray-200 text-sm px-3 py-2.5 relative ring-transparent text-zinc-600 hover:ring-blue-500/20 ring-[3px] flex items-center justify-center group"
        onClick={handleCopy}
      >
        <div
          className={classNames(
            "bg-black/80 text-xs text-white px-2 py-1 rounded-md absolute left-0 top-0 -translate-y-1/2 transition-all duration-200",
            {
              "opacity-0 !translate-y-0": !copied,
            }
          )}
        >
          Copied!
        </div>
        <CopyIcon className="w-4 h-4 text-zinc-400 mr-2 group-hover:text-blue-500" />
        <p className="flex-1">{url}</p>
      </div>
    </div>
  );
};