Portal/rsconcept/frontend/src/components/input/text-area.tsx

70 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-02-22 14:03:13 +03:00
import { type Editor, type ErrorProcessing, type Titled } from '../props';
2025-04-12 21:47:46 +03:00
import { cn } from '../utils';
2025-02-12 21:36:03 +03:00
2025-03-12 11:54:32 +03:00
import { ErrorField } from './error-field';
2025-03-12 12:12:45 +03:00
import { Label } from './label';
2024-06-07 20:17:03 +03:00
2025-03-13 23:20:52 +03:00
interface TextAreaProps extends Editor, ErrorProcessing, Titled, React.ComponentProps<'textarea'> {
2025-02-22 14:03:13 +03:00
/** Indicates that the input should be transparent. */
transparent?: boolean;
/** Indicates that padding should be minimal. */
2024-06-07 20:17:03 +03:00
dense?: boolean;
/** Disable resize when content overflows. */
2024-06-07 20:17:03 +03:00
noResize?: boolean;
/** Disable resize to fit content. */
2024-08-28 22:38:34 +03:00
fitContent?: boolean;
2024-06-07 20:17:03 +03:00
}
/**
* Displays a customizable textarea with a label.
*/
2025-02-07 10:53:49 +03:00
export function TextArea({
2024-06-07 20:17:03 +03:00
id,
label,
2025-02-22 14:03:13 +03:00
transparent,
2024-06-07 20:17:03 +03:00
dense,
noBorder,
noOutline,
noResize,
className,
2024-08-28 22:38:34 +03:00
fitContent,
2025-04-12 21:47:46 +03:00
disabled,
2025-02-04 23:33:35 +03:00
error,
2024-06-07 20:17:03 +03:00
...restProps
}: TextAreaProps) {
return (
<div
2025-04-12 21:47:46 +03:00
className={cn(
2025-03-13 01:14:47 +03:00
'w-full', //
dense ? 'flex grow items-center gap-3' : 'flex flex-col',
2024-06-07 20:17:03 +03:00
dense && className
)}
>
<Label text={label} htmlFor={id} />
<textarea
id={id}
2025-04-12 21:47:46 +03:00
className={cn(
2025-05-29 15:38:39 +03:00
'min-h-0',
2024-06-07 20:17:03 +03:00
'px-3 py-2',
'leading-tight',
'overflow-x-hidden overflow-y-auto',
2025-03-13 01:14:47 +03:00
!noBorder && 'border',
fitContent && 'field-sizing-content',
noResize && 'resize-none',
2025-04-12 21:47:46 +03:00
transparent || disabled ? 'bg-transparent' : 'bg-input',
2025-03-20 18:24:07 +03:00
!noOutline && 'focus-outline',
2025-03-13 01:14:47 +03:00
dense && 'grow max-w-full',
!dense && !!label && 'mt-2',
2024-06-07 20:17:03 +03:00
!dense && className
)}
2025-04-12 21:47:46 +03:00
disabled={disabled}
2024-06-07 20:17:03 +03:00
{...restProps}
/>
2025-02-04 23:33:35 +03:00
<ErrorField className='mt-1' error={error} />
2024-06-07 20:17:03 +03:00
</div>
);
}