File: //var/www/design.system/src/molecules/Inputs/Textarea/Textarea.tsx
import React, { forwardRef } from 'react';
import styles from './Textarea.module.scss';
import cn from 'classnames';
import Body from '../../../atoms/Typography/Body/Body.tsx';
interface ITextareaProps
extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChange'> {
value?: string;
placeholder?: string;
label?: string;
disabled?: boolean;
isError?: boolean;
onChange?: (value: string) => void;
className?: string;
}
/**
* Поддерживает все стандартные пропсы HTMLTextAreaElement.
*
* Полную документацию смотрите сайте: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement
*/
const Textarea = forwardRef<HTMLTextAreaElement, ITextareaProps>(
(
{ value, placeholder, label, disabled, isError, onChange, className, ...rest }: ITextareaProps,
ref
) => {
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange?.(e.target.value);
};
return (
<div
className={cn(
styles.root,
{
[styles.disabled]: disabled,
[styles.isError]: isError,
},
className
)}
>
{label && <Body className={styles.label}>{label}</Body>}
<textarea
ref={ref}
value={value}
placeholder={placeholder}
className={styles.textarea}
onChange={handleChange}
disabled={disabled}
{...rest}
/>
</div>
);
}
);
export default Textarea;