bigbuffet-rw/app/soapbox/components/ui/textarea/textarea.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import classNames from 'classnames';
import React from 'react';
2022-07-11 09:34:14 -07:00
interface ITextarea extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'maxLength' | 'onChange' | 'required' | 'disabled' | 'rows' | 'readOnly'> {
/** Put the cursor into the input on mount. */
2022-03-21 11:09:01 -07:00
autoFocus?: boolean,
/** The initial text in the input. */
2022-03-21 11:09:01 -07:00
defaultValue?: string,
/** Internal input name. */
2022-03-21 11:09:01 -07:00
name?: string,
/** Renders the textarea as a code editor. */
2022-03-21 11:09:01 -07:00
isCodeEditor?: boolean,
/** Text to display before a value is entered. */
2022-03-21 11:09:01 -07:00
placeholder?: string,
/** Text in the textarea. */
2022-03-21 11:09:01 -07:00
value?: string,
/** Whether the device should autocomplete text in this textarea. */
autoComplete?: string,
2022-05-05 15:45:32 -07:00
/** Whether to display the textarea in red. */
hasError?: boolean,
2022-03-21 11:09:01 -07:00
}
/** Textarea with custom styles. */
2022-03-21 11:09:01 -07:00
const Textarea = React.forwardRef(
2022-05-05 15:45:32 -07:00
({ isCodeEditor = false, hasError = false, ...props }: ITextarea, ref: React.ForwardedRef<HTMLTextAreaElement>) => {
2022-03-21 11:09:01 -07:00
return (
<textarea
{...props}
ref={ref}
className={classNames({
2022-03-23 17:18:37 -07:00
'dark:bg-slate-800 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-600 rounded-md':
2022-03-21 11:09:01 -07:00
true,
'font-mono': isCodeEditor,
2022-05-05 15:45:32 -07:00
'text-red-600 border-red-600': hasError,
2022-03-21 11:09:01 -07:00
})}
/>
);
},
);
export default Textarea;