// Adapted from Mantine PasswordInput (MIT). See THIRD_PARTY_NOTICES.md. import { useId, useState, type ComponentProps, type CSSProperties, } from "react"; export interface PasswordInputProps extends Omit< ComponentProps<"input">, "type" | "onChange" | "className" | "style" > { label: string; description?: string; error?: string; visible?: boolean; defaultVisible?: boolean; onVisibilityChange?: (visible: boolean) => void; onChange?: (value: string) => void; className?: string; style?: CSSProperties; inputClassName?: string; inputStyle?: CSSProperties; } export function PasswordInput({ label, description, error, id, visible, defaultVisible = false, onVisibilityChange, onChange, className = "", style, inputClassName = "", inputStyle, disabled, "aria-describedby": describedBy, ...props }: PasswordInputProps) { const generatedId = useId(); const inputId = id ?? generatedId; const [internalVisible, setInternalVisible] = useState(defaultVisible); const isVisible = visible ?? internalVisible; const hint = error ?? description; const hintId = `${inputId}-hint`; const setVisible = (next: boolean) => { if (visible === undefined) setInternalVisible(next); onVisibilityChange?.(next); }; return (
{hint}
)}