import IconFont from '@/components/icon-font'; import hotkeys from '@/config/hotkeys'; import { useIntl } from '@umijs/max'; import { Input } from 'antd'; import React, { useRef } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import styled from 'styled-components'; import { modelSourceMap, modelSourceValueMap } from '../config'; const SearchInputWrapper = styled.div` position: relative; width: 100%; `; const Holder = styled.div` pointer-events: none; position: absolute; top: 13px; left: 34px; color: var(--ant-color-text-quaternary); font-size: var(--font-size-small); z-index: 10; kbd { border: 1px solid var(--ant-color-border); border-radius: 3px; padding: 0 2px; } `; const SearchInput: React.FC<{ modelSource: string; onChange: (e: any) => void; onSearch: (e: any) => void; }> = (props) => { const { onSearch, onChange, modelSource } = props; const intl = useIntl(); const inputRef = useRef(null); const [isFocused, setIsFocused] = React.useState(false); const [value, setValue] = React.useState(''); useHotkeys(hotkeys.FOCUS, (e: any) => { e.preventDefault(); inputRef.current?.focus?.(); }); const handleOnChange = (e: any) => { setValue(e.target.value); onChange(e); }; return ( { setIsFocused(true); e.stopPropagation(); }} onBlur={(e) => { setIsFocused(false); e.stopPropagation(); }} allowClear prefix={ } > {!value && !isFocused && ( )} ); }; export default SearchInput;