-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Adding drag and drop functionality to elemental
- Loading branch information
Showing
17 changed files
with
356 additions
and
32 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
client/src/components/ElementEditor/DragPositionIndicator.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { PureComponent } from 'react'; | ||
|
||
// eslint-disable-next-line react/prefer-stateless-function | ||
class DragPositionIndicator extends PureComponent { | ||
render() { | ||
return ( | ||
<div className="elemental-editor-drag-indicator"> | ||
<div className="elemental-editor-drag-indicator__ball" /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default DragPositionIndicator; |
15 changes: 15 additions & 0 deletions
15
client/src/components/ElementEditor/DragPositionIndicator.scss
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.elemental-editor-drag-indicator { | ||
height: 3px; | ||
margin: -2px 0 -1px 0; | ||
background-color: $info; | ||
|
||
&__ball { | ||
position: relative; | ||
height: 7px; | ||
width: 7px; | ||
top: -2px; | ||
left: -3px; | ||
border-radius: 3.5px; | ||
background-color: $info; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import Header from 'components/ElementEditor/Header'; | ||
import { DragLayer } from 'react-dnd'; | ||
import { elementType } from 'types/elementType'; | ||
|
||
// eslint-disable-next-line react/prefer-stateless-function | ||
class ElementDragPreview extends Component { | ||
render() { | ||
const { isDragging, element, currentOffset } = this.props; | ||
|
||
if (!isDragging || !currentOffset) { | ||
return null; | ||
} | ||
|
||
const { x, y } = currentOffset; | ||
|
||
const thing = element || { | ||
ID: 2, | ||
Title: 'Something blah', | ||
Version: 5, | ||
IsLiveVersion: true, | ||
IsPublished: true, | ||
BlockSchema: { iconClass: 'font-icon-block-form' }, | ||
}; | ||
|
||
const transform = `translate(${x}px, ${y}px)`; | ||
const style = { | ||
transform, | ||
WebkitTransform: transform, | ||
}; | ||
|
||
return ( | ||
<div className="element-editor-drag-preview" style={style}> | ||
<Header | ||
id={thing.ID} | ||
title={thing.Title} | ||
version={thing.Version} | ||
isLiveVersion={thing.IsLiveVersion} | ||
isPublished={thing.IsPublished} | ||
fontIcon={thing.BlockSchema.iconClass} | ||
simple | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ElementDragPreview.propTypes = { | ||
element: elementType, | ||
isDragging: PropTypes.bool, | ||
currentOffset: PropTypes.shape({ | ||
x: PropTypes.number.isRequired, | ||
y: PropTypes.number.isRequired, | ||
}), | ||
}; | ||
|
||
export default DragLayer(monitor => ({ | ||
element: monitor.getItem(), | ||
currentOffset: monitor.getSourceClientOffset(), | ||
isDragging: monitor.isDragging(), | ||
}))(ElementDragPreview); |
11 changes: 11 additions & 0 deletions
11
client/src/components/ElementEditor/ElementDragPreview.scss
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.element-editor-drag-preview { | ||
top: 0; | ||
left: 0; | ||
position: fixed; | ||
pointer-events: none; | ||
z-index: 100; // Higher than CMS tree view | ||
background-color: $white; | ||
border: 1px solid $border-color; | ||
padding: $spacer-sm $panel-padding-x; | ||
box-shadow: $z-depth-1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.element-editor { | ||
&--dragging { | ||
cursor: grabbing; | ||
} | ||
} |
Oops, something went wrong.