2025-03-27 04:35:41 +07:00
|
|
|
import {
|
|
|
|
|
DetailedHTMLProps,
|
|
|
|
|
FC,
|
|
|
|
|
InputHTMLAttributes,
|
|
|
|
|
ReactElement,
|
|
|
|
|
} from 'react';
|
|
|
|
|
import { Input } from '../../atoms';
|
2025-03-27 05:25:02 +07:00
|
|
|
import { cn } from '@imphnen-frontend-service/utils';
|
2025-03-27 04:35:41 +07:00
|
|
|
|
|
|
|
|
type TInputType = 'text' | 'email';
|
|
|
|
|
type TInputSize = 'sm' | 'md' | 'lg';
|
|
|
|
|
|
|
|
|
|
type TInputFormProps = Omit<
|
|
|
|
|
DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>,
|
|
|
|
|
'size' | 'type'
|
|
|
|
|
> & {
|
|
|
|
|
label: string;
|
|
|
|
|
type?: TInputType;
|
|
|
|
|
size?: TInputSize;
|
|
|
|
|
error?: string;
|
2025-03-27 05:25:02 +07:00
|
|
|
helperText?: string;
|
|
|
|
|
htmlFor?: string;
|
2025-03-27 04:35:41 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const InputForm: FC<TInputFormProps> = ({
|
|
|
|
|
label,
|
|
|
|
|
placeholder,
|
|
|
|
|
type = 'text',
|
|
|
|
|
size = 'md',
|
|
|
|
|
error,
|
2025-03-27 05:25:02 +07:00
|
|
|
helperText,
|
|
|
|
|
htmlFor,
|
|
|
|
|
className,
|
2025-03-27 04:35:41 +07:00
|
|
|
...rest
|
|
|
|
|
}): ReactElement => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex gap-[8px] flex-col">
|
2025-03-27 05:25:02 +07:00
|
|
|
<label htmlFor={htmlFor} className="self-start text-p3 font-medium">
|
|
|
|
|
{label}
|
|
|
|
|
</label>
|
2025-03-27 04:35:41 +07:00
|
|
|
<Input
|
2025-03-27 05:25:02 +07:00
|
|
|
{...(htmlFor && { id: htmlFor })}
|
2025-03-27 04:35:41 +07:00
|
|
|
placeholder={placeholder}
|
|
|
|
|
type={type}
|
|
|
|
|
size={size}
|
2025-03-27 05:25:02 +07:00
|
|
|
className={cn(
|
|
|
|
|
error &&
|
|
|
|
|
'border-danger-500 hover:border-danger-500 focus:outline-danger-500',
|
|
|
|
|
className
|
|
|
|
|
)}
|
2025-03-27 04:35:41 +07:00
|
|
|
{...rest}
|
|
|
|
|
/>
|
2025-03-27 05:25:02 +07:00
|
|
|
{error ? (
|
|
|
|
|
<p className="text-danger-500 text-xs mt-1">{error}</p>
|
|
|
|
|
) : (
|
|
|
|
|
helperText && (
|
|
|
|
|
<p className="text-neutral-500 text-xs mt-1">{helperText}</p>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2025-03-27 04:35:41 +07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputForm;
|