import { useEffect, useRef } from 'react' import clsx from 'clsx' import { AnimatePresence, motion } from 'framer-motion' interface ProficientInputAreaProps { value: string isComposing: boolean inputLocked: boolean hasError: boolean onChange: (value: string) => void onCompositionStart: () => void onCompositionEnd: (value: string) => void showLockedHint?: boolean } export function ProficientInputArea({ value, isComposing, inputLocked, hasError, onChange, onCompositionStart, onCompositionEnd, showLockedHint = true, }: ProficientInputAreaProps) { const inputRef = useRef(null) useEffect(() => { if (inputLocked) return inputRef.current?.focus() }, [inputLocked, value]) return (
onChange(e.target.value)} onCompositionStart={onCompositionStart} onCompositionEnd={(e) => onCompositionEnd(e.currentTarget.value)} disabled={inputLocked} placeholder="输入当前分组中的一个完整条目" className={clsx( 'w-full rounded-xl border px-4 py-3 text-base md:text-lg', 'bg-white dark:bg-gray-800/80 text-gray-900 dark:text-gray-100', 'transition-all duration-200 focus:outline-none focus:ring-2', isComposing && 'border-gray-300 dark:border-gray-600 opacity-80', !isComposing && !hasError && 'border-gray-300 dark:border-gray-600 focus:ring-indigo-400 focus:border-indigo-400', !isComposing && hasError && 'border-red-400 focus:ring-red-400 focus:border-red-400', inputLocked && 'cursor-not-allowed opacity-60' )} autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck="false" /> {showLockedHint && inputLocked && ( 答案显示中,输入已锁定 )}
) }