Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 120 additions & 117 deletions src/node-renderer-default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropTypes } from 'react';
import React, { Component, PropTypes } from 'react';
import { getIEVersion } from './utils/browser-utils';
import baseStyles from './node-renderer-default.scss';
import { isDescendant } from './utils/tree-data-utils';
Expand All @@ -15,136 +15,139 @@ if (getIEVersion < 10) {
};
}

const NodeRendererDefault = ({
scaffoldBlockPxWidth,
toggleChildrenVisibility,
connectDragPreview,
connectDragSource,
isDragging,
isOver,
canDrop,
node,
draggedNode,
path,
treeIndex,
isSearchMatch,
isSearchFocus,
buttons,
className,
style = {},
startDrag: _startDrag,
endDrag: _endDrag,
...otherProps,
}) => {
let handle;
if (typeof node.children === 'function' && node.expanded) {
// Show a loading symbol on the handle when the children are expanded
// and yet still defined by a function (a callback to fetch the children)
handle = (
<div className={styles.loadingHandle}>
<div className={styles.loadingCircle}>
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
class NodeRendererDefault extends Component {
render() {
const {
scaffoldBlockPxWidth,
toggleChildrenVisibility,
connectDragPreview,
connectDragSource,
isDragging,
isOver,
canDrop,
node,
draggedNode,
path,
treeIndex,
isSearchMatch,
isSearchFocus,
buttons,
className,
style = {},
startDrag: _startDrag,
endDrag: _endDrag,
...otherProps,
} = this.props;
let handle;
if (typeof node.children === 'function' && node.expanded) {
// Show a loading symbol on the handle when the children are expanded
// and yet still defined by a function (a callback to fetch the children)
handle = (
<div className={styles.loadingHandle}>
<div className={styles.loadingCircle}>
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
<div className={styles.loadingCirclePoint} />
</div>
</div>
</div>
);
} else {
// Show the handle used to initiate a drag-and-drop
handle = connectDragSource((
<div className={styles.moveHandle} />
), { dropEffect: 'copy' });
}

const isDraggedDescendant = draggedNode && isDescendant(draggedNode, node);
);
} else {
// Show the handle used to initiate a drag-and-drop
handle = connectDragSource((
<div className={styles.moveHandle} />
), { dropEffect: 'copy' });
}

return (
<div
style={{ height: '100%' }}
{...otherProps}
>
{toggleChildrenVisibility && node.children && node.children.length > 0 && (
<div>
<button
aria-label={node.expanded ? 'Collapse' : 'Expand'}
className={node.expanded ? styles.collapseButton : styles.expandButton}
style={{ left: -0.5 * scaffoldBlockPxWidth }}
onClick={() => toggleChildrenVisibility({node, path, treeIndex})}
/>
const isDraggedDescendant = draggedNode && isDescendant(draggedNode, node);

{node.expanded && !isDragging &&
<div
style={{ width: scaffoldBlockPxWidth }}
className={styles.lineChildren}
return (
<div
style={{ height: '100%' }}
{...otherProps}
>
{toggleChildrenVisibility && node.children && node.children.length > 0 && (
<div>
<button
aria-label={node.expanded ? 'Collapse' : 'Expand'}
className={node.expanded ? styles.collapseButton : styles.expandButton}
style={{ left: -0.5 * scaffoldBlockPxWidth }}
onClick={() => toggleChildrenVisibility({node, path, treeIndex})}
/>
}
</div>
)}

<div className={styles.rowWrapper}>
{/* Set the row preview to be used during drag and drop */}
{connectDragPreview(
<div
className={styles.row +
(isDragging && isOver ? ` ${styles.rowLandingPad}` : '') +
(isDragging && !isOver && canDrop ? ` ${styles.rowCancelPad}` : '') +
(isSearchMatch ? ` ${styles.rowSearchMatch}` : '') +
(isSearchFocus ? ` ${styles.rowSearchFocus}` : '') +
(className ? ` ${className}` : '')
{node.expanded && !isDragging &&
<div
style={{ width: scaffoldBlockPxWidth }}
className={styles.lineChildren}
/>
}
style={{
opacity: isDraggedDescendant ? 0.5 : 1,
...style,
}}
>
{handle}
</div>
)}

<div className={styles.rowContents}>
<div className={styles.rowLabel}>
<span
className={styles.rowTitle +
(node.subtitle ? ` ${styles.rowTitleWithSubtitle}` : '')
}
>
{typeof node.title === 'function' ?
node.title({node, path, treeIndex }) :
node.title
}
</span>
<div className={styles.rowWrapper}>
{/* Set the row preview to be used during drag and drop */}
{connectDragPreview(
<div
className={styles.row +
(isDragging && isOver ? ` ${styles.rowLandingPad}` : '') +
(isDragging && !isOver && canDrop ? ` ${styles.rowCancelPad}` : '') +
(isSearchMatch ? ` ${styles.rowSearchMatch}` : '') +
(isSearchFocus ? ` ${styles.rowSearchFocus}` : '') +
(className ? ` ${className}` : '')
}
style={{
opacity: isDraggedDescendant ? 0.5 : 1,
...style,
}}
>
{handle}

{node.subtitle &&
<span className={styles.rowSubtitle}>
{typeof node.subtitle === 'function' ?
node.subtitle({node, path, treeIndex }) :
node.subtitle
<div className={styles.rowContents}>
<div className={styles.rowLabel}>
<span
className={styles.rowTitle +
(node.subtitle ? ` ${styles.rowTitleWithSubtitle}` : '')
}
>
{typeof node.title === 'function' ?
node.title({node, path, treeIndex }) :
node.title
}
</span>
}
</div>

<div className={styles.rowToolbar}>
{buttons && buttons.map((btn, index) => (
<div key={index} className={styles.toolbarButton}>
{btn}
</div>
))}
{node.subtitle &&
<span className={styles.rowSubtitle}>
{typeof node.subtitle === 'function' ?
node.subtitle({node, path, treeIndex }) :
node.subtitle
}
</span>
}
</div>

<div className={styles.rowToolbar}>
{buttons && buttons.map((btn, index) => (
<div key={index} className={styles.toolbarButton}>
{btn}
</div>
))}
</div>
</div>
</div>
</div>
)}
)}
</div>
</div>
</div>
);
};
);
}
}

NodeRendererDefault.propTypes = {
node: PropTypes.object.isRequired,
Expand Down
Loading