qq-button.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use client";
  2. import { useState } from "react";
  3. /**
  4. * QQ's "start a chat" links (wpa.qq.com/msgrd, tencent://) fail with "无法发起
  5. * 临时会话" for accounts that don't accept stranger messages. So instead of
  6. * opening anything, this shows the number and copies it on click.
  7. */
  8. export function QqButton({ qq }: { qq: string }) {
  9. const [copied, setCopied] = useState(false);
  10. return (
  11. <button
  12. aria-label={`QQ ${qq}`}
  13. className="lg relative inline-flex h-10 items-center gap-2 rounded-full px-3.5 transition-[scale,translate] duration-300 ease-out @max-[270px]/hero:h-9 @max-[270px]/hero:px-3"
  14. data-cursor={`QQ ${qq}`}
  15. type="button"
  16. onClick={() => {
  17. navigator.clipboard?.writeText(qq).catch(() => {});
  18. setCopied(true);
  19. window.setTimeout(() => setCopied(false), 1600);
  20. }}
  21. >
  22. <span aria-hidden className="lg-caustic" />
  23. <svg
  24. aria-hidden
  25. className="size-4 shrink-0"
  26. fill="currentColor"
  27. viewBox="0 0 24 24"
  28. >
  29. <path d="M21.395 15.035a40 40 0 0 0-.803-2.264l-1.079-2.695c.001-.032.014-.562.014-.836C19.526 4.632 17.351 0 12 0S4.474 4.632 4.474 9.241c0 .274.013.804.014.836l-1.08 2.695a39 39 0 0 0-.802 2.264c-1.021 3.283-.69 4.643-.438 4.673.54.065 2.103-2.472 2.103-2.472 0 1.469.756 3.387 2.394 4.771-.612.188-1.363.479-1.845.835-.434.32-.379.646-.301.778.343.578 5.883.369 7.482.189 1.6.18 7.14.389 7.483-.189.078-.132.132-.458-.301-.778-.483-.356-1.233-.646-1.846-.836 1.637-1.384 2.393-3.302 2.393-4.771 0 0 1.563 2.537 2.103 2.472.251-.03.581-1.39-.438-4.673" />
  30. </svg>
  31. <span className="text-[13px] font-medium tracking-tight tabular-nums">
  32. {qq}
  33. </span>
  34. <span
  35. aria-hidden
  36. className="pointer-events-none absolute -top-9 left-1/2 -translate-x-1/2 rounded-full bg-ink px-2.5 py-1 text-[11px] font-medium whitespace-nowrap text-bg opacity-0 transition-opacity duration-200 data-[on]:opacity-100"
  37. data-on={copied ? "" : undefined}
  38. >
  39. QQ 号已复制
  40. </span>
  41. </button>
  42. );
  43. }