ldc-groupe/resources/ts/back/Components/Inputs/SimpleTextarea.tsx
2026-02-11 09:15:45 +01:00

71 lines
2.1 KiB
TypeScript

// * Packages
import { usePage } from "@inertiajs/react";
// * Components shadcn
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
// * Other
import InputError from "@/back/Components/InputError";
import WordCounter from "@/back/Components/WordCounter";
import useTrans from "@/hooks/use-translations";
import { cn } from "@/lib/utils";
type SimpleTextareaProps = {
className?: string;
name: string;
label: string;
value?: string;
id?: string;
placeholder?: string;
wordCounter?: boolean;
required?: boolean;
disabled?: boolean;
parentErrors?: Record<string, string> | null;
// eslint-disable-next-line no-unused-vars
setData: (name: string, value: string) => void;
};
export default function SimpleTextarea({
className,
name,
label,
value = "",
id = name,
placeholder = "back.enter_text_here",
wordCounter = true,
required = true,
disabled = false,
parentErrors = null,
setData,
}: SimpleTextareaProps) {
const { errors } = usePage().props;
const localErrors = parentErrors ?? errors;
return (
<div
className={cn(
"flex flex-col w-full justify-between items-start gap-1.5",
className,
)}
>
<Label htmlFor={name}>{label + (required ? " *" : "")}</Label>
{wordCounter && <WordCounter value={value} />}
<div className="flex w-full">
<Textarea
id={id}
name={name}
placeholder={useTrans(placeholder)}
defaultValue={value}
onChange={(e) => {
setData(name, e.target.value);
}}
required={required}
disabled={disabled}
className={cn("w-full", {
"border-destructive/50": localErrors[name],
})}
/>
</div>
<InputError message={localErrors[name]} />
</div>
);
}