Rocky_Mountain_Vending/components/forms/form-textarea.tsx

47 lines
1.6 KiB
TypeScript

"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
export interface FormTextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
label?: string
error?: string
helperText?: string
}
const FormTextarea = React.forwardRef<HTMLTextAreaElement, FormTextareaProps>(
({ className, label, error, helperText, id, ...props }, ref) => {
const generatedId = React.useId()
const textareaId = id || generatedId
return (
<div className="space-y-2">
{label ? (
<label htmlFor={textareaId} className="text-sm font-semibold leading-none text-foreground">
{label}
</label>
) : null}
<div className="relative">
<textarea
id={textareaId}
data-slot="textarea"
className={cn(
"min-h-[136px] w-full rounded-xl border border-border/70 bg-background/85 px-4 py-3 text-base text-foreground shadow-sm transition outline-none",
"placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground",
"focus:border-primary focus:ring-4 focus:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
error ? "border-destructive focus:ring-destructive/10" : "",
className,
)}
ref={ref}
{...props}
/>
</div>
{error ? <p className="text-sm text-destructive">{error}</p> : null}
{helperText && !error ? <p className="text-sm text-muted-foreground">{helperText}</p> : null}
</div>
)
},
)
FormTextarea.displayName = "FormTextarea"
export { FormTextarea }