import { useState } from 'react'; import { Eye, EyeOff } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { CopyButton } from './CopyButton'; const MASK = '••••••••••••'; /** * The one way to show a value someone will copy: commands, IPs, URLs, * connection strings, tokens, passwords. * * * * * * `secret` hides the value until the eye is pressed; copying works either way, * so a secret never has to be shown to be used. Use the bare CopyButton only * when the copied text is not on screen (a "Copy command" action). */ export default function CopyField({ value, label, secret = false, multiline = false, className, onCopy, }) { const { t } = useTranslation(); const [revealed, setRevealed] = useState(false); const text = value == null ? '' : String(value); const hidden = secret && !revealed; return (
{label && {label}}
{multiline ?
{hidden ? MASK : text}
: {hidden ? MASK : text}} {secret && ( )}
); }