import React from 'react'; import { TextField, Box, Typography } from '@mui/material'; import { useFormContext, Controller } from 'react-hook-form'; import { type IFormLayoutType } from './index'; export interface TextFormFieldProps extends IFormLayoutType { name: string; label: string; placeholder?: string; defaultValue?: string; required?: boolean; disabled?: boolean; helperText?: string; type?: 'text' | 'email' | 'password' | 'url' | 'tel'; } export function TextFormField({ name, label, placeholder, defaultValue = '', required = false, disabled = false, layout = 'vertical', helperText, type = 'text', }: TextFormFieldProps) { const { control, formState: { errors } } = useFormContext(); const error = errors[name]; const isHorizontal = layout === 'horizontal'; const textField = ( ( )} /> ); if (isHorizontal) { return ( {label} {required && *} {textField} ); } return textField; }