Exam generation rework, batch user tables, fastapi endpoint switch
This commit is contained in:
53
src/components/Low/AutoExpandingTextarea.tsx
Executable file
53
src/components/Low/AutoExpandingTextarea.tsx
Executable file
@@ -0,0 +1,53 @@
|
||||
import React, { useEffect, useRef, ChangeEvent } from 'react';
|
||||
|
||||
interface Props {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
className?: string;
|
||||
placeholder?: string;
|
||||
onBlur?: () => void;
|
||||
}
|
||||
|
||||
const AutoExpandingTextArea: React.FC<Props> = ({
|
||||
value,
|
||||
className = 'w-full cursor-text px-7 py-8 input border-2 border-mti-gray-platinum bg-white rounded-3xl',
|
||||
placeholder = "Enter text here...",
|
||||
onChange,
|
||||
onBlur,
|
||||
}) => {
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
const adjustHeight = () => {
|
||||
const textarea = textareaRef.current;
|
||||
if (textarea) {
|
||||
textarea.style.height = 'auto';
|
||||
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
adjustHeight();
|
||||
const timer = setTimeout(adjustHeight, 100);
|
||||
return () => clearTimeout(timer);
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
onChange(e.target.value);
|
||||
adjustHeight();
|
||||
};
|
||||
|
||||
return (
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
className={className}
|
||||
placeholder={placeholder}
|
||||
style={{ overflow: 'hidden', resize: 'none' }}
|
||||
onBlur={onBlur}
|
||||
autoFocus
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default AutoExpandingTextArea;
|
||||
Reference in New Issue
Block a user