Portal/rsconcept/frontend/src/components/ui/TextArea.tsx

71 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
import { CProps } from '../props';
import Label from './Label';
export interface TextAreaProps extends CProps.Editor, CProps.Colors, CProps.TextArea {
/** 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.
*/
2024-06-07 20:17:03 +03:00
function TextArea({
id,
label,
required,
rows,
dense,
noBorder,
noOutline,
noResize,
className,
2024-08-28 22:38:34 +03:00
fitContent,
2024-06-07 20:17:03 +03:00
colors = 'clr-input',
...restProps
}: TextAreaProps) {
return (
<div
className={clsx(
2024-08-12 16:51:24 +03:00
'w-full',
2024-06-07 20:17:03 +03:00
{
2024-08-09 20:57:03 +03:00
'flex flex-col gap-2': !dense,
2024-07-21 15:17:36 +03:00
'flex flex-grow items-center gap-3': dense
2024-06-07 20:17:03 +03:00
},
dense && className
)}
>
<Label text={label} htmlFor={id} />
<textarea
id={id}
className={clsx(
'px-3 py-2',
'leading-tight',
'overflow-x-hidden overflow-y-auto',
{
2024-08-28 22:38:34 +03:00
'cc-fit-content': fitContent,
2024-06-07 20:17:03 +03:00
'resize-none': noResize,
'border': !noBorder,
'flex-grow max-w-full': dense,
'clr-outline': !noOutline
},
colors,
!dense && className
)}
rows={rows}
required={required}
{...restProps}
/>
</div>
);
}
export default TextArea;