forked from frontend-collective/react-sortable-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display droppable placeholder element when tree is empty
BREAKING CHANGES: Trees that are empty now display a placeholder element in their place instead of being simply empty.
- Loading branch information
Showing
7 changed files
with
169 additions
and
2 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
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,24 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from './placeholder-renderer-default.scss'; | ||
|
||
const PlaceholderRendererDefault = ({ isOver, canDrop }) => | ||
<div | ||
className={ | ||
styles.placeholder + | ||
(canDrop ? ` ${styles.placeholderLandingPad}` : '') + | ||
(canDrop && !isOver ? ` ${styles.placeholderCancelPad}` : '') | ||
} | ||
/>; | ||
|
||
PlaceholderRendererDefault.defaultProps = { | ||
isOver: false, | ||
canDrop: false, | ||
}; | ||
|
||
PlaceholderRendererDefault.propTypes = { | ||
isOver: PropTypes.bool, | ||
canDrop: PropTypes.bool, | ||
}; | ||
|
||
export default PlaceholderRendererDefault; |
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,51 @@ | ||
.placeholder { | ||
position: relative; | ||
height: 68px; | ||
max-width: 300px; | ||
padding: 10px; | ||
|
||
&, | ||
& > * { | ||
box-sizing: border-box; | ||
} | ||
|
||
&::before { | ||
border: 3px dashed #d9d9d9; | ||
content: ''; | ||
position: absolute; | ||
top: 5px; | ||
right: 5px; | ||
bottom: 5px; | ||
left: 5px; | ||
z-index: -1; | ||
} | ||
} | ||
|
||
/** | ||
* The outline of where the element will go if dropped, displayed while dragging | ||
*/ | ||
.placeholderLandingPad { | ||
border: none !important; | ||
box-shadow: none !important; | ||
outline: none !important; | ||
|
||
* { | ||
opacity: 0 !important; | ||
} | ||
|
||
&::before { | ||
background-color: lightblue; | ||
border-color: white; | ||
} | ||
} | ||
|
||
/** | ||
* Alternate appearance of the landing pad when the dragged location is invalid | ||
*/ | ||
.placeholderCancelPad { | ||
@extend .placeholderLandingPad; | ||
|
||
&::before { | ||
background-color: #e6a8ad; | ||
} | ||
} |
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,38 @@ | ||
import React, { Children, cloneElement } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const TreePlaceholder = ({ | ||
children, | ||
connectDropTarget, | ||
treeId, | ||
drop, | ||
...otherProps | ||
}) => | ||
connectDropTarget( | ||
<div> | ||
{Children.map(children, child => | ||
cloneElement(child, { | ||
...otherProps, | ||
}) | ||
)} | ||
</div> | ||
); | ||
|
||
TreePlaceholder.defaultProps = { | ||
canDrop: false, | ||
draggedNode: null, | ||
}; | ||
|
||
TreePlaceholder.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
|
||
// Drop target | ||
connectDropTarget: PropTypes.func.isRequired, | ||
isOver: PropTypes.bool.isRequired, | ||
canDrop: PropTypes.bool, | ||
draggedNode: PropTypes.shape({}), | ||
treeId: PropTypes.string.isRequired, | ||
drop: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default TreePlaceholder; |
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