index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import CustomButton from "@/components/CustomButton";
  2. import useReffer from "@/hooks/useReffer";
  3. import { copyText } from "@/utils/methods";
  4. import { Toast } from "antd-mobile";
  5. import clsx from "clsx";
  6. import { useLocale } from "next-intl";
  7. import React from "react";
  8. interface Props {
  9. text?: string;
  10. className?: string;
  11. }
  12. const ShareText: React.FC<Props> = ({ text, className }) => {
  13. const locale = useLocale();
  14. const url = useReffer({ locale });
  15. // ${decodeURIComponent(url)}
  16. const localText = React.useMemo(() => {
  17. return `${text?.replace(/{%}/g, decodeURIComponent(url))}`;
  18. }, [text, url]);
  19. return (
  20. <div
  21. className={clsx(
  22. "mt-[.1rem] !h-auto w-full !flex-col overflow-hidden !rounded-[var(--borderRadius)] border border-[var(--primary-button)] bg-[#fff] px-[8px] py-[8px]",
  23. className
  24. )}
  25. >
  26. <div className="h-[80px] overflow-x-hidden whitespace-pre-wrap break-all py-[10px] pl-[8px] text-center text-[12px] leading-[20px]">
  27. {localText}
  28. </div>
  29. <CustomButton
  30. className="!h-[37px] !w-[100%] !text-[.12rem]"
  31. onClick={() => {
  32. copyText(`${localText}${decodeURIComponent(url)}`);
  33. Toast.show({ icon: "success", content: "Copiado com sucesso" });
  34. }}
  35. >
  36. Copiar
  37. </CustomButton>
  38. </div>
  39. );
  40. };
  41. export default ShareText;