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