import RowTextarea from '@/components/seal-form/row-textarea'; import { MinusCircleOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Tooltip } from 'antd'; import React, { useRef } from 'react'; import '../style/input-list.less'; interface InputListProps { textList: { text: string; uid: number | string; name: string }[]; onChange?: ( textList: { text: string; uid: number | string; name: string }[] ) => void; } const InputList: React.FC = ({ textList, onChange }) => { const intl = useIntl(); const messageId = useRef(0); const setMessageId = () => { messageId.current = messageId.current + 1; }; const handleAdd = () => { setMessageId(); const dataList = [...textList]; dataList.push({ text: '', uid: messageId.current, name: `Text ${dataList.length + 1}` }); onChange?.(dataList); }; const handleDelete = (text: { text: string; uid: number | string }) => { const dataList = [...textList]; const index = dataList.findIndex((item) => item.uid === text.uid); dataList.splice(index, 1); onChange?.(dataList); }; const handleTextChange = ( value: string, text: { text: string; uid: number | string } ) => { const dataList = [...textList]; const index = dataList.findIndex((item) => item.uid === text.uid); dataList[index].text = value; onChange?.(dataList); }; return (
{textList.length === 0 && ( )} {textList.map((text, index) => { return (
handleTextChange(e.target.value, text)} >
{index === textList.length - 1 && ( )}
); })}
); }; export default React.memo(InputList);