46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import React from 'react'
|
|
import clsx from 'clsx'
|
|
|
|
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
label?: string
|
|
error?: string
|
|
helperText?: string
|
|
}
|
|
|
|
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
({ label, error, helperText, className, id, rows = 3, ...props }, ref) => {
|
|
const textareaId =
|
|
id || (label ? `textarea-${label.replace(/\s+/g, '-').toLowerCase()}` : undefined)
|
|
|
|
return (
|
|
<div className="w-full">
|
|
{label && (
|
|
<label
|
|
htmlFor={textareaId}
|
|
className="block text-sm font-medium text-slate-700 mb-1.5"
|
|
>
|
|
{label}
|
|
</label>
|
|
)}
|
|
<textarea
|
|
ref={ref}
|
|
id={textareaId}
|
|
rows={rows}
|
|
className={clsx(
|
|
'w-full rounded-xl border bg-white px-3.5 py-2.5 text-sm text-slate-900 placeholder:text-slate-400 transition-colors focus:outline-none focus:ring-2',
|
|
error
|
|
? 'border-red-400 focus:border-red-500 focus:ring-red-500/20'
|
|
: 'border-slate-200 focus:border-[#C95C3C] focus:ring-[#C95C3C]/20',
|
|
props.disabled && 'bg-slate-50 text-slate-500 cursor-not-allowed',
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
{error && <p className="mt-1.5 text-xs text-red-600">{error}</p>}
|
|
{!error && helperText && <p className="mt-1.5 text-xs text-slate-500">{helperText}</p>}
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
Textarea.displayName = 'Textarea'
|