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

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import classNames from 'classnames';
import React from 'react';
2022-04-12 06:49:41 -07:00
interface ITextarea extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'maxLength' | 'onChange' | 'required'> {
/** 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-03-21 11:09:01 -07:00
}
/** Textarea with custom styles. */
2022-03-21 11:09:01 -07:00
const Textarea = React.forwardRef(
({ isCodeEditor = false, ...props }: ITextarea, ref: React.ForwardedRef<HTMLTextAreaElement>) => {
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,
})}
/>
);
},
);
export default Textarea;