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'> {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Put the cursor into the input on mount. */
|
2022-03-21 11:09:01 -07:00
|
|
|
autoFocus?: boolean,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** The initial text in the input. */
|
2022-03-21 11:09:01 -07:00
|
|
|
defaultValue?: string,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Internal input name. */
|
2022-03-21 11:09:01 -07:00
|
|
|
name?: string,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Renders the textarea as a code editor. */
|
2022-03-21 11:09:01 -07:00
|
|
|
isCodeEditor?: boolean,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Text to display before a value is entered. */
|
2022-03-21 11:09:01 -07:00
|
|
|
placeholder?: string,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Text in the textarea. */
|
2022-03-21 11:09:01 -07:00
|
|
|
value?: string,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Whether the device should autocomplete text in this textarea. */
|
2022-04-29 12:12:52 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -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-07-22 10:30:16 -07:00
|
|
|
'bg-white dark:bg-transparent shadow-sm block w-full sm:text-sm rounded-md text-gray-900 dark:text-gray-100 placeholder:text-gray-600 dark:placeholder:text-gray-600 border-gray-400 dark:border-gray-800 dark:ring-1 dark:ring-gray-800 focus:ring-primary-500 focus:border-primary-500 dark:focus:ring-primary-500 dark:focus:border-primary-500':
|
|
|
|
true,
|
2022-03-21 11:09:01 -07:00
|
|
|
'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;
|