diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-30 13:05:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-30 13:05:06 +0900 |
commit | 457d954e08923b4accd28a919c72d0b61db1bb98 (patch) | |
tree | 9d198f7c7d37893621d4e2a27749070a435854cd /src/settings/components/form/BlacklistForm.jsx | |
parent | 3d9a251ce293885cda57cd3eebd111f6181132f0 (diff) | |
parent | 037ee5fd40af0117a1eb8d362b4ae97429499f16 (diff) |
Merge pull request #576 from ueokande/move-to-react
Move to React
Diffstat (limited to 'src/settings/components/form/BlacklistForm.jsx')
-rw-r--r-- | src/settings/components/form/BlacklistForm.jsx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/settings/components/form/BlacklistForm.jsx b/src/settings/components/form/BlacklistForm.jsx new file mode 100644 index 0000000..c470758 --- /dev/null +++ b/src/settings/components/form/BlacklistForm.jsx @@ -0,0 +1,63 @@ +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)} + onBlur={this.props.onBlur} + /> + <DeleteButton data-index={index} name='delete' + onClick={this.bindValue.bind(this)} + onBlur={this.props.onBlur} + /> + </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); + if (name === 'delete') { + this.props.onBlur(); + } + } +} + +BlacklistForm.propTypes = { + value: PropTypes.arrayOf(PropTypes.string), + onChange: PropTypes.func, + onBlur: PropTypes.func, +}; + +BlacklistForm.defaultProps = { + value: [], + onChange: () => {}, + onBlur: () => {}, +}; + +export default BlacklistForm; |