-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9e0402
commit 4728667
Showing
20 changed files
with
882 additions
and
1,004 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 27 additions & 65 deletions
92
client/src/components/GalleryItem/GalleryItemDragLayer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,38 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragLayer } from 'react-dnd'; | ||
import Badge from 'components/Badge/Badge'; | ||
import GalleryItem from './GalleryItem'; | ||
|
||
class GalleryItemDragLayer extends Component { | ||
getOffset() { | ||
const { | ||
offset, | ||
dragged, | ||
} = this.props; | ||
return { | ||
transform: offset && `translate(${offset.x + dragged.x}px, ${offset.y + dragged.y}px)`, | ||
}; | ||
} | ||
function GalleryItemDragLayer(props) { | ||
const { draggingItems, draggingItemProps } = props; | ||
const selectionCount = draggingItems.length; | ||
const shadows = [ | ||
selectionCount > 1 | ||
? <div key="1" className="gallery-item__drag-shadow" /> | ||
: null, | ||
selectionCount > 2 | ||
? <div key="2" className="gallery-item__drag-shadow gallery-item__drag-shadow--second" /> | ||
: null, | ||
]; | ||
|
||
render() { | ||
if (!this.props.isDragging) { | ||
return null; | ||
} | ||
const { item } = this.props; | ||
if (!item.selected) { | ||
return null; | ||
} | ||
const selectionCount = item.selected.length; | ||
const shadows = [ | ||
selectionCount > 1 | ||
? <div key="1" className="gallery-item__drag-shadow" /> | ||
: null, | ||
selectionCount > 2 | ||
? <div key="2" className="gallery-item__drag-shadow gallery-item__drag-shadow--second" /> | ||
: null, | ||
]; | ||
|
||
return ( | ||
<div className="gallery-item__drag-layer"> | ||
<div className="gallery-item__drag-layer-item" style={this.getOffset()}> | ||
<div className="gallery-item__drag-layer-preview"> | ||
{shadows} | ||
<GalleryItem {...item.props} isDragging /> | ||
</div> | ||
{selectionCount > 1 | ||
? ( | ||
<Badge | ||
className="gallery-item__drag-layer-count" | ||
status="info" | ||
message={`${selectionCount}`} | ||
/> | ||
) | ||
: null | ||
} | ||
</div> | ||
return ( | ||
<div className="gallery-item__drag-layer"> | ||
<div className="gallery-item__drag-layer-preview"> | ||
{shadows} | ||
<GalleryItem {...draggingItemProps} isDragging /> | ||
{selectionCount > 1 && <Badge | ||
className="gallery-item__drag-layer-count" | ||
status="info" | ||
message={`${selectionCount}`} | ||
/>} | ||
</div> | ||
); | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
GalleryItemDragLayer.propTypes = { | ||
item: PropTypes.object, | ||
offset: PropTypes.shape({ | ||
x: PropTypes.number.isRequired, | ||
y: PropTypes.number.isRequired, | ||
}), | ||
isDragging: PropTypes.bool.isRequired, | ||
draggingItems: PropTypes.arrayOf(PropTypes.number).isRequired, | ||
draggingItemProps: PropTypes.object.isRequired, | ||
}; | ||
|
||
const collect = (monitor) => ({ | ||
item: monitor.getItem(), | ||
offset: monitor.getInitialClientOffset(), | ||
dragged: monitor.getDifferenceFromInitialOffset(), | ||
isDragging: monitor.isDragging(), | ||
}); | ||
|
||
// eslint-disable-next-line new-cap | ||
export default DragLayer(collect)(GalleryItemDragLayer); | ||
export default GalleryItemDragLayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.