import React, { useMemo, useRef, FC, FocusEvent, useContext } from 'react' import { Popover } from '../popover' import { Input } from '../input' import { List } from '../list' import _ from 'lodash' import { pinYinFilter } from '@gm-common/tool' import SVGCloseCircle from '../../svg/close-circle.svg' import classNames from 'classnames' import { ConfigContext, ConfigProvider } from '../config_provider' interface DataItem { text: string } export interface RecommendInputProps { data?: DataItem[] onChange?(value: string): void value?: string disabled?: boolean listHeight?: string className?: string placeholder?: string } const RecommendInput: FC = ({ onChange, value, data = [], listHeight = '180px', disabled, className, ...rest }) => { const popoverRef = useRef(null) const config = useContext(ConfigContext) // 构造list需要的数据结构 const _data = useMemo(() => { return _.map(data, (item: DataItem) => { return { ...item, value: item.text, } }) }, [data]) const searchData = useMemo(() => { return pinYinFilter(_data, value, (item: DataItem) => item.text) }, [value, _data]) const handleChange = (event: FocusEvent) => { const changeVal = event.target.value onChange(changeVal) } const handleSelect = (selected: string) => { // 选择后隐藏 popoverRef.current!.apiDoSetActive(false) onChange(selected) } const handleClear = () => { onChange('') } return ( 0 ? ( ) : ( <> // 需要element ) } disabled={disabled} >
) } export default RecommendInput