diff --git a/resources/ts/Components/CopyText.tsx b/resources/ts/Components/CopyText.tsx index e0caf07e7..0f7bf37ba 100644 --- a/resources/ts/Components/CopyText.tsx +++ b/resources/ts/Components/CopyText.tsx @@ -1,20 +1,22 @@ -import type { ReactNode } from "react"; import React, { useRef, useState } from "react"; import { Tooltip } from "./Tooltip"; import { ButtonIconCopy } from "./ButtonIconCopy"; import { useTranslation } from "react-i18next"; +import { faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons"; +import { ButtonIcon } from "./ButtonIcon"; -type Props = { children: ReactNode }; +type Props = { text: string; secret?: boolean }; -export const CopyText = ({ children }: Props) => { +export const CopyText = ({ text, secret }: Props) => { const { t } = useTranslation(); const codeFieldRef = useRef(null); const [isVisible, setIsVisible] = useState(false); + const [isSecretVisible, setIsSecretVisible] = useState(false); - const handleCopyToClipboard = () => { - navigator.clipboard.writeText(codeFieldRef.current?.innerText ?? ""); + const handleCopyToClipboard = (text: string) => { + navigator.clipboard.writeText(text ?? ""); setIsVisible(true); const timeoutId = setTimeout(() => { setIsVisible(false); @@ -25,20 +27,25 @@ export const CopyText = ({ children }: Props) => { return (
- {children} + {!secret || isSecretVisible ? text : "*".repeat(text?.length ?? 36)} - + handleCopyToClipboard(text)} + className="text-publiq-orange" /> + {secret && ( + { + setIsSecretVisible((prev) => !prev); + }} + /> + )}
);