import React, { useCallback, useRef, useState } from 'react'; import type { ChatTriggerBarProps } from '../../types'; import micAiIcon from '../../assets/mic-ai.png'; import { TriggerBarSendIcon } from '../icons/TriggerBarSendIcon'; import styles from './index.module.less'; export const ChatTriggerBar: React.FC = ({ onOpenAssistant, onSubmitText, placeholder = '查找点位、资源、事件', className, }) => { const [value, setValue] = useState(''); const inputRef = useRef(null); const hasText = value.trim().length > 0; const handleSubmit = useCallback(() => { const text = value.trim(); if (!text) return; onSubmitText?.(text); setValue(''); }, [value, onSubmitText]); const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { e.preventDefault(); handleSubmit(); } }; const handleRightButtonClick = useCallback( (e: React.MouseEvent) => { e.stopPropagation(); if (hasText) { handleSubmit(); } else { onOpenAssistant?.(); } }, [hasText, handleSubmit, onOpenAssistant], ); return (
inputRef.current?.focus()}> setValue(e.target.value)} onKeyDown={handleKeyDown} placeholder={placeholder} enterKeyHint="search" autoComplete="off" autoCorrect="off" autoCapitalize="off" />
); }; /* ---------- 内联 SVG ---------- */ const SearchIcon = () => ( );