import React, { useMemo } from 'react'; import type { Key } from 'react'; import { Select, Input } from 'antd'; import type { SelectProps, InputProps } from 'antd'; export interface TypeListConfig { key: T; text: string; } export interface TypeInputValue { type: T; data: string; } export interface TypeInputProps { typeList?: TypeListConfig[]; value?: TypeInputValue; onChange?: (value: TypeInputValue) => void; selectProps?: SelectProps; inputProps?: InputProps; needData?: boolean; } export function TypeInput(props: TypeInputProps) { const typeList = useMemo(() => props.typeList || [], [props.typeList]); const needData = useMemo(() => { if (typeof props.needData !== 'boolean') return true; return props.needData; }, [props.needData]); const value = useMemo( () => props.value || { type: needData && typeList.length ? typeList[0].key : '', data: '' }, [needData, props.value, typeList] ); return (
{ props.onChange && props.onChange({ type: value.type, data: e.target.value }); }} />
); }