Uecko_ERP/packages/rdx-ui/src/components/form/TextAreaField.tsx

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-07-09 17:56:15 +00:00
// DatePickerField.tsx
import {
2025-10-14 17:57:02 +00:00
Field,
FieldDescription,
FieldError,
FieldLabel,
2025-07-09 17:56:15 +00:00
Textarea,
} from "@repo/shadcn-ui/components";
2025-10-14 17:57:02 +00:00
import { cn } from '@repo/shadcn-ui/lib/utils';
import { Control, Controller, FieldPath, FieldValues, useFormState } from "react-hook-form";
2025-10-02 16:30:46 +00:00
import { CommonInputProps } from "./types.js";
2025-07-09 17:56:15 +00:00
2025-10-02 16:30:46 +00:00
type TextAreaFieldProps<TFormValues extends FieldValues> = CommonInputProps & {
2025-07-09 17:56:15 +00:00
control: Control<TFormValues>;
name: FieldPath<TFormValues>;
2025-10-14 17:57:02 +00:00
2025-07-09 17:56:15 +00:00
label?: string;
description?: string;
2025-10-02 16:30:46 +00:00
2025-10-14 17:57:02 +00:00
orientation?: "vertical" | "horizontal" | "responsive",
inputClassName?: string;
2025-07-09 17:56:15 +00:00
};
export function TextAreaField<TFormValues extends FieldValues>({
control,
name,
label,
description,
required = false,
readOnly = false,
2025-10-02 16:30:46 +00:00
2025-10-14 17:57:02 +00:00
orientation = 'vertical',
2025-10-02 16:30:46 +00:00
2025-10-14 17:57:02 +00:00
className,
inputClassName,
...inputRest
}: TextAreaFieldProps<TFormValues>) {
const { isSubmitting, isValidating } = useFormState({ control, name });
const disabled = isSubmitting || inputRest.disabled;
2025-07-09 17:56:15 +00:00
return (
2025-10-14 17:57:02 +00:00
<Controller
2025-07-09 17:56:15 +00:00
control={control}
name={name}
2025-10-14 17:57:02 +00:00
render={({ field, fieldState }) => {
return (
<Field data-invalid={fieldState.invalid} orientation={orientation} className={className}>
{label && <FieldLabel className='text-xs text-muted-foreground text-nowrap' htmlFor={name}>{label}</FieldLabel>}
2025-10-12 10:43:06 +00:00
2025-10-14 17:57:02 +00:00
<Textarea
ref={field.ref}
id={name}
value={field.value ?? ""}
onChange={field.onChange}
onBlur={field.onBlur}
aria-invalid={fieldState.invalid}
aria-busy={isValidating}
{...inputRest}
disabled={disabled}
aria-disabled={disabled}
className={cn(inputClassName)}
2025-09-24 11:49:17 +00:00
/>
2025-07-09 17:56:15 +00:00
2025-10-02 16:30:46 +00:00
2025-10-14 17:57:02 +00:00
{false && <FieldDescription className='text-xs'>{description || "\u00A0"}</FieldDescription>}
<FieldError errors={[fieldState.error]} />
</Field>
);
}}
2025-07-09 17:56:15 +00:00
/>
);
}
2025-10-14 17:57:02 +00:00