You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

54 lines
1.4 KiB

import './BlacklistForm.scss';
import AddButton from '../ui/AddButton';
import DeleteButton from '../ui/DeleteButton';
import React from 'react';
import PropTypes from 'prop-types';
class BlacklistForm extends React.Component {
render() {
return <div className='form-blacklist-form'>
{
this.props.value.map((url, index) => {
return <div key={index} className='form-blacklist-form-row'>
<input data-index={index} type='text' name='url'
className='column-url' value={url}
onChange={this.bindValue.bind(this)} />
<DeleteButton data-index={index} name='delete'
onClick={this.bindValue.bind(this)} />
</div>;
})
}
<AddButton name='add' style={{ float: 'right' }}
onClick={this.bindValue.bind(this)} />
</div>;
}
bindValue(e) {
let name = e.target.name;
let index = e.target.getAttribute('data-index');
let next = this.props.value ? this.props.value.slice() : [];
if (name === 'url') {
next[index] = e.target.value;
} else if (name === 'add') {
next.push('');
} else if (name === 'delete') {
next.splice(index, 1);
}
this.props.onChange(next);
}
}
BlacklistForm.propTypes = {
value: PropTypes.arrayOf(PropTypes.string),
onChange: PropTypes.func,
};
BlacklistForm.defaultProps = {
value: [],
onChange: () => {},
};
export default BlacklistForm;