UNPKG

wix-style-react

Version:
49 lines 2.67 kB
import React, { Component } from 'react'; import classNames from 'classnames'; import Item from './Item'; import { getDepth } from './utils'; class Container extends Component { render() { const { items, parentPosition, childrenProperty, childrenStyle, renderAction, treeDepth, isParentLastItem = true, isRenderDraggingChildren, topLevel, theme, } = this.props; let containerClass; if (theme) { containerClass = (topLevel && theme.topContainer) || theme.container; } const classes = classNames('nestable-container', { 'nestable-top-container': topLevel, }, containerClass); return (React.createElement("div", { className: classes, style: topLevel ? {} : childrenStyle }, items.map((item, i) => { const position = parentPosition.concat([i]); const children = item[childrenProperty] && item[childrenProperty].map(child => { if (item.lockDropArea || item.isParentLocked) { child.isParentLocked = true; child.draggable = false; } return child; }); const hasChildren = children && children.length; const isLastItem = items.length - 1 === i; const actionButton = renderAction({ siblings: items, item, veryLastItem: isLastItem && isParentLastItem, depth: treeDepth, }); const veryLastItem = isLastItem && isParentLastItem && (!hasChildren || item.isCollapsed) && !actionButton; return (React.createElement(Item, { id: item.id, key: item.id, item: item, index: i, isVeryLastItem: veryLastItem, siblings: items, isRenderDraggingChildren: isRenderDraggingChildren, position: position, depth: getDepth(item, childrenProperty), theme: theme }, !item.isCollapsed && (React.createElement("div", null, hasChildren ? (React.createElement(WrappedContainer, { isParentLastItem: isLastItem && isParentLastItem && !actionButton, items: children, renderAction: renderAction, isRenderDraggingChildren: isRenderDraggingChildren, parentPosition: position, childrenProperty: childrenProperty, childrenStyle: childrenStyle, theme: theme, treeDepth: treeDepth + 1 })) : null, actionButton)))); }))); } } class WrappedContainer extends React.PureComponent { render() { return React.createElement(Container, { ...this.props }); } } export default WrappedContainer; //# sourceMappingURL=Container.js.map