import React from 'react'; import { Alert, Button, Input, InputGroup, InputGroupAddon } from 'reactstrap'; export default class EditableStringList extends React.Component { constructor(props) { super(props); this.state = { teams: props.teams, groups: props.groups }; this.add = this.add.bind(this); this.remove = this.remove.bind(this); } add(text) { if (text === '' || this.props.teams.includes(text)) { return false; } this.props.teams.push(text); this.setState({teams: this.state.teams}); this.props.onTeamsChange(this.state.teams); return true; } remove(text) { let tmp = this.state.teams.filter(item => item !== text); this.setState({teams: tmp}); this.props.onTeamsChange(tmp); } render() { if ((typeof this.state.teams !== 'undefined') && this.state.teams.length > 0) { return (
{this.state.teams.map((text) => )}
); } else { return (
{this.props.teamPlaceholder}
); } } } class StringInput extends React.Component { constructor(props) { super(props); this.state = {value: ''}; this.handleChange = this.handleChange.bind(this); this.submit = this.submit.bind(this); } handleChange(event) { this.setState({value: event.target.value}); } render() { return ( { if (e.key === 'Enter') { this.submit(); return false; } }}/> ); } submit() { if (this.props.submit(this.state.value)) { this.setState({value: ''}); } } } class Item extends React.Component { constructor(props) { super(props); this.state = { visible: true }; this.onDismiss = this.onDismiss.bind(this); } onDismiss() { this.setState({visible: false}); this.props.removeItem(this.props.text); } render() { return ( {this.props.text} ); } }