| | |
| | | import { useEffect, useRef } from 'react' |
| | | import { forwardRef, useEffect, useRef } from 'react' |
| | | import cn from '@/utils/classnames' |
| | | import { sleep } from '@/utils' |
| | | |
| | |
| | | onKeyUp?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void |
| | | } |
| | | |
| | | const AutoHeightTextarea = ( |
| | | { |
| | | ref: outerRef, |
| | | value, |
| | | onChange, |
| | | placeholder, |
| | | className, |
| | | wrapperClassName, |
| | | minHeight = 36, |
| | | maxHeight = 96, |
| | | autoFocus, |
| | | controlFocus, |
| | | onKeyDown, |
| | | onKeyUp, |
| | | }: IProps & { |
| | | ref: React.RefObject<unknown>; |
| | | }, |
| | | const AutoHeightTextarea = forwardRef( |
| | | ( |
| | | { value, onChange, placeholder, className, wrapperClassName, minHeight = 36, maxHeight = 96, autoFocus, controlFocus, onKeyDown, onKeyUp }: IProps, |
| | | outerRef: any, |
| | | ) => { |
| | | // eslint-disable-next-line react-hooks/rules-of-hooks |
| | | const ref = outerRef || useRef<HTMLTextAreaElement>(null) |
| | |
| | | }, [controlFocus]) |
| | | |
| | | return ( |
| | | (<div className={`relative ${wrapperClassName}`}> |
| | | <div className={cn(className, 'invisible overflow-y-auto whitespace-pre-wrap break-all')} style={{ |
| | | <div className={`relative ${wrapperClassName}`}> |
| | | <div className={cn(className, 'invisible whitespace-pre-wrap break-all overflow-y-auto')} style={{ |
| | | minHeight, |
| | | maxHeight, |
| | | paddingRight: (value && value.trim().length > 10000) ? 140 : 130, |
| | |
| | | onKeyUp={onKeyUp} |
| | | value={value} |
| | | /> |
| | | </div>) |
| | | </div> |
| | | ) |
| | | } |
| | | }, |
| | | ) |
| | | |
| | | AutoHeightTextarea.displayName = 'AutoHeightTextarea' |
| | | |