Skip to content

Commit

Permalink
add onRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
amonks committed Feb 6, 2017
1 parent b65f945 commit 908038b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class Demo extends React.Component {
}
}

Item ({value, index, onChange, decorateHandle}) {
Item ({value, index, onChange, onRemove, decorateHandle}) {
return (
<div>
{decorateHandle(<span>+ </span>)}
<span onClick={onRemove}>X</span>
{decorateHandle(<span>+</span>)}
<input
onChange={e => {
const val = e.target.value
Expand Down
3 changes: 2 additions & 1 deletion demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class Demo extends React.Component {
}
}

Item ({value, index, onChange, decorateHandle}) {
Item ({value, index, onRemove, onChange, decorateHandle}) {
return (
<div>
<span onClick={onRemove}>X</span>
{decorateHandle(<span>+ </span>)}
<input
onChange={e => {
Expand Down
5 changes: 5 additions & 0 deletions src/SortableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class SortableContainer extends React.Component {
key={key}
id={key}
index={index}
onRemove={() => {
const index = R.findIndex(i => i.key === key, collection)
const newCollection = R.remove(index, 1, collection)
onChange(newCollection)
}}
onChange={value => {
const index = R.findIndex(i => i.key === key, collection)
const newCollection = R.adjust(R.assoc('value', value), index, collection)
Expand Down
4 changes: 2 additions & 2 deletions src/SortableItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class SortableItem extends React.Component {
}

render () {
const { Component, isDragging, value, onChange, index, connectDragSource } = this.props
const { Component, isDragging, value, onChange, onRemove, index, connectDragSource } = this.props
const opacity = isDragging ? 0 : 1

console.log('render SortableItem')

return this.decorateSortableItemElement(
<div style={{opacity}}>
<Component value={value} onChange={onChange} index={index} decorateHandle={connectDragSource} />
<Component value={value} onRemove={onRemove} onChange={onChange} index={index} decorateHandle={connectDragSource} />
</div>
)
}
Expand Down

0 comments on commit 908038b

Please sign in to comment.