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

42 lines
1.6 KiB
TypeScript
Raw Normal View History

import classNames from 'clsx';
2022-03-21 11:09:01 -07:00
import React from 'react';
interface ITextarea extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'maxLength' | 'onChange' | 'onKeyDown' | 'onPaste' | '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({
'bg-white dark:bg-gray-900 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;