2024-06-24 12:08:21 +05:30
|
|
|
import { FormControl, FormLabel, Input, Textarea } from '@chakra-ui/react';
|
|
|
|
|
import React from 'react'
|
|
|
|
|
import { Controller } from 'react-hook-form';
|
|
|
|
|
import { TiWarning } from 'react-icons/ti';
|
|
|
|
|
|
|
|
|
|
const FormField = ({
|
|
|
|
|
label,
|
|
|
|
|
control,
|
|
|
|
|
name,
|
|
|
|
|
type = "text",
|
|
|
|
|
errors,
|
|
|
|
|
isRequired,
|
2024-06-25 19:16:55 +05:30
|
|
|
arabic,
|
2024-06-24 12:08:21 +05:30
|
|
|
...props
|
|
|
|
|
}) => (
|
|
|
|
|
// <FormControl isInvalid={errors[name]}>
|
|
|
|
|
// <FormControl isRequired={isRequired}>
|
|
|
|
|
<FormControl >
|
2024-06-25 19:16:55 +05:30
|
|
|
<FormLabel textAlign={arabic ? "right" : "left"} fontSize={"sm"}>{label}</FormLabel>
|
2024-06-24 12:08:21 +05:30
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name={name}
|
|
|
|
|
defaultValue=""
|
|
|
|
|
render={({ field }) => {
|
|
|
|
|
return type === "textarea" ? (
|
|
|
|
|
<Textarea
|
|
|
|
|
focusBorderColor="forestGreen.400"
|
|
|
|
|
size={"sm"}
|
|
|
|
|
{...field}
|
|
|
|
|
{...props}
|
2024-06-25 20:35:03 +05:30
|
|
|
placeholder={label}
|
2024-06-25 19:16:55 +05:30
|
|
|
textAlign={arabic ? "right" : "left"}
|
2024-06-24 12:08:21 +05:30
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Input
|
|
|
|
|
focusBorderColor="forestGreen.300"
|
|
|
|
|
size={"sm"}
|
|
|
|
|
type={type}
|
|
|
|
|
{...field}
|
|
|
|
|
{...props}
|
2024-06-25 20:35:03 +05:30
|
|
|
placeholder={label}
|
2024-06-25 19:16:55 +05:30
|
|
|
textAlign={arabic ? "right" : "left"}
|
2024-06-24 12:08:21 +05:30
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{errors[name] && (
|
|
|
|
|
<span className="text-danger web-text-small fw-bold ps-2 d-flex align-items-center gap-1 mt-1">
|
|
|
|
|
<TiWarning className="fw-bold fs-5 " /> {errors[name].message}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</FormControl>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default FormField
|