import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/solid'; import { useState } from 'react'; import type { ChangeEventHandler, FocusEventHandler, ReactNode, Ref } from 'react'; import type { ComponentSize } from './types'; import { Button } from './Button'; type InputKind = 'text' | 'password' | 'email'; type Layout = 'stacked' | 'inline'; type InputFieldProps = { label?: string; placeholder?: string; type: InputKind; size?: ComponentSize; layout?: Layout; value: string; name?: string; onChange?: ChangeEventHandler; onBlur?: FocusEventHandler; inputRef?: Ref; disabled?: boolean; required?: boolean; error?: string; rightIcon?: ReactNode; className?: string; inputClassName?: string; }; export function InputField({ label, placeholder = '', type, size = 'md', layout = 'stacked', value, name, onChange, onBlur, inputRef, disabled = false, required = false, error, rightIcon, className = '', inputClassName = '', }: Readonly) { const [showPassword, setShowPassword] = useState(false); const containerSizeClass = { sm: 'max-w-xs', md: 'max-w-sm', lg: 'max-w-md', full: 'max-w-none', }[size]; const inputSizeClass = { sm: 'h-8 !text-xs', md: 'h-10 text-sm', lg: 'h-12 text-sm', full: 'h-10 text-sm', }[size]; const wrapperClass = layout === 'inline' ? 'inline-flex w-auto items-center gap-2' : 'block w-full gap-1'; const labelClass = layout === 'inline' ? 'text-xs ui-body-secondary' : ''; const isPasswordType = type === 'password'; const resolvedType: InputKind = isPasswordType && showPassword ? 'text' : type; const hasTrailingIcon = isPasswordType || Boolean(rightIcon); const inputWrapperClass = layout === 'inline' ? 'relative' : 'relative mt-1'; return ( ); }