import React from "react"; import { Button, Form, InputGroup } from "react-bootstrap"; import { Icon } from "src/components/Shared"; interface IStringListInputProps { value: string[]; setValue: (value: string[]) => void; defaultNewValue?: string; className?: string; errors?: string; } export const StringListInput: React.FC = (props) => { function valueChanged(idx: number, value: string) { const newValues = props.value.map((v, i) => { const ret = idx !== i ? v : value; return ret; }); props.setValue(newValues); } function removeValue(idx: number) { const newValues = props.value.filter((_v, i) => i !== idx); props.setValue(newValues); } function addValue() { const newValues = props.value.concat(props.defaultNewValue ?? ""); props.setValue(newValues); } return ( <>
{props.value && props.value.length > 0 && ( {props.value && props.value.map((v, i) => ( // eslint-disable-next-line react/no-array-index-key ) => valueChanged(i, e.currentTarget.value) } /> ))} )}
{props.errors}
); };