import React from 'react'; import { Button } from 'react-bootstrap'; import { VariableError } from '../VariableError'; import type { IVariable, IVariableError, IVariableInputBuilder, IVariableProps, IVariableState, } from './variableInput.service'; import { VariableInputService } from './variableInput.service'; class ListInput extends React.Component { public render() { return (
{this.createInputFields()}
); } private createInputFields(): JSX.Element[] { return this.props.variable.value.map((v: string, i: number) => { return (
{!this.props.variable.hideErrors && }
); }); } private findErrorsForInput(inputKey: number): IVariableError[] { return this.props.variable.errors ? this.props.variable.errors.filter((e) => e.key === inputKey) : []; } private extractValue(i: number) { return (e: React.ChangeEvent) => { const list = this.props.variable.value.slice(); list[i] = e.target.value; this.props.onChange({ value: list, type: this.props.variable.type, name: this.props.variable.name }); }; } private handleDeleteValue(i: number): void { const list = this.props.variable.value.slice(); list.splice(i, 1); this.props.onChange({ value: list, type: this.props.variable.type, name: this.props.variable.name }); } private handleAddValue = (): void => { const list = this.props.variable.value.slice().concat(['']); this.props.onChange({ value: list, type: this.props.variable.type, name: this.props.variable.name }); }; } export class ListInputBuilder implements IVariableInputBuilder { public handles(type: string): boolean { return type === 'list'; } public getInput(variable: IVariable, onChange: (values: IVariable) => void) { return ; } } VariableInputService.addInput(new ListInputBuilder());