import React, { useState } from 'react'; import { Form, Input, Button, Space } from 'antd'; import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { TextInput, Grid, Col } from "@tremor/react"; import { TrashIcon } from "@heroicons/react/outline"; interface KeyValueInputProps { value?: Record; onChange?: (value: Record) => void; } const KeyValueInput: React.FC = ({ value = {}, onChange }) => { const [pairs, setPairs] = useState<[string, string][]>(Object.entries(value)); const handleAdd = () => { setPairs([...pairs, ['', '']]); }; const handleRemove = (index: number) => { const newPairs = pairs.filter((_, i) => i !== index); setPairs(newPairs); onChange?.(Object.fromEntries(newPairs)); }; const handleChange = (index: number, key: string, val: string) => { const newPairs = [...pairs]; newPairs[index] = [key, val]; setPairs(newPairs); onChange?.(Object.fromEntries(newPairs)); }; return (
{pairs.map(([key, val], index) => ( handleChange(index, e.target.value, val)} /> handleChange(index, key, e.target.value)} /> handleRemove(index)} /> ))}
); }; export default KeyValueInput;