// fallow-ignore-file unused-export import { Eye, EyeOff } from "lucide-react"; import type * as React from "react"; import { useMemo, useState } from "react"; import { cn } from "~/client/lib/utils"; import { Button } from "./button"; import { Input } from "./input"; export const isStoredSecretValue = (value?: string): boolean => { if (typeof value !== "string" || value.length === 0) { return false; } return value.startsWith("env://") || value.startsWith("file://") || value.startsWith("encv1:"); }; type SecretInputProps = Omit, "type">; export const SecretInput = ({ className, value, ...props }: SecretInputProps) => { const [revealed, setRevealed] = useState(false); const showAsPlaintext = useMemo(() => { if (typeof value !== "string") { return false; } return isStoredSecretValue(value); }, [value]); const type = useMemo(() => { if (showAsPlaintext) { return "text"; } return revealed ? "text" : "password"; }, [showAsPlaintext, revealed]); return (
{!showAsPlaintext && ( )}
); };