diff --git a/app/components/contract-template/CompactSearchBox.tsx b/app/components/contract-template/CompactSearchBox.tsx new file mode 100644 index 0000000..633b568 --- /dev/null +++ b/app/components/contract-template/CompactSearchBox.tsx @@ -0,0 +1,151 @@ +import { useState, useRef } from 'react'; + +interface CompactSearchBoxProps { + onSearch: (query: string) => void; + initialQuery?: string; + searchTime?: string; +} + +export function CompactSearchBox({ + onSearch, + initialQuery = '', + searchTime = '搜索用时 0.3秒' +}: CompactSearchBoxProps) { + const [searchQuery, setSearchQuery] = useState(initialQuery); + const textareaRef = useRef(null); + + const handleSearchInputChange = (e: React.ChangeEvent) => { + const value = e.target.value; + setSearchQuery(value); + + // 自动调整高度 + if (textareaRef.current) { + textareaRef.current.style.height = 'auto'; + textareaRef.current.style.height = Math.max(60, textareaRef.current.scrollHeight) + 'px'; + } + }; + + const handleSearch = () => { + if (searchQuery.trim()) { + onSearch(searchQuery); + } + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { + e.preventDefault(); + handleSearch(); + } + }; + + return ( +
+
+
+
+