@krowdy-ui/views
Version:
React components that implement Google's Material Design.
183 lines (175 loc) • 6.1 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import XDate from 'xdate';
import useStyles from './node-content-renderer-style';
import { Typography, Tooltip, makeStyles, IconButton } from '@krowdy-ui/core';
import { Lock as LockIcon } from '@material-ui/icons';
function isDescendant(older, younger) {
return !!older.children && typeof older.children !== 'function' && older.children.some(child => child === younger || isDescendant(child, younger));
}
function cutValue(value, size) {
return value.length > size ? value.slice(0, size) + '...' : value;
}
const Value = ({
label,
size,
dots
}) => {
const classes = useContentStyles();
if (label.length <= size || !dots) return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Typography, {
className: classes.value,
component: "span",
variant: "caption"
}, label));else return /*#__PURE__*/React.createElement(Tooltip, {
title: label
}, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Typography, {
className: classes.value,
component: "span",
variant: "caption"
}, cutValue(label, size))));
};
const Label = ({
value,
dots,
size
}) => {
const classes = useContentStyles();
if (value.length <= size || !dots) return /*#__PURE__*/React.createElement(Typography, {
className: classes.label,
component: "span",
variant: "body1"
}, value);else return /*#__PURE__*/React.createElement(Tooltip, {
title: value
}, /*#__PURE__*/React.createElement(Typography, {
className: classes.label,
component: "span",
variant: "body1"
}, cutValue(value, size)));
};
const Span = ({
value,
dots,
size
}) => {
const classes = useContentStyles();
if (value.length <= size || !dots) return /*#__PURE__*/React.createElement(Typography, {
className: classes.span,
component: "span",
variant: "body1"
}, value);else return /*#__PURE__*/React.createElement(Tooltip, {
title: value
}, /*#__PURE__*/React.createElement(Typography, {
className: classes.span,
component: "span",
variant: "body1"
}, cutValue(value, size)));
};
const useContentStyles = makeStyles(theme => ({
label: {
color: theme.palette.primary[900],
fontSize: 12
},
span: {
color: theme.palette.grey[600],
fontSize: 10,
marginLeft: theme.spacing(0.5)
},
value: {
color: theme.palette.grey[800],
fontSize: 10,
lineHeight: '16px'
}
}));
function FileThemeNodeContentRenderer(props) {
const {
connectDragPreview,
connectDragSource,
isDragging,
dots,
canDrop,
node,
draggedNode,
buttons,
className,
didDrop
} = props;
const classes = useStyles();
const isDraggedDescendant = draggedNode && isDescendant(draggedNode, node);
const isLandingPadActive = !didDrop && isDragging;
const nodeContent = /*#__PURE__*/React.createElement("div", {
className: classes.nodeContent
}, connectDragPreview( /*#__PURE__*/React.createElement("div", {
className: classes.rowWrapper
}, connectDragSource( /*#__PURE__*/React.createElement("div", {
className: classes.containerCard
}, node.type === 'list' && node.operator === '$nin' && /*#__PURE__*/React.createElement(IconButton, {
size: "small"
}, /*#__PURE__*/React.createElement(LockIcon, {
className: classes.lockIcon,
fontSize: "small"
})), /*#__PURE__*/React.createElement("div", {
className: classes.row + (isLandingPadActive ? ` ${classes.rowLandingPad}` : '') + (isLandingPadActive && !canDrop ? ` ${classes.rowCancelPad}` : '') + (className ? ` ${className}` : ''),
style: {
opacity: isDraggedDescendant ? 0.5 : 1
}
}, /*#__PURE__*/React.createElement("div", {
className: classes.rowPanelLeft
}, /*#__PURE__*/React.createElement("div", {
className: classes.rowContentTitle
}, /*#__PURE__*/React.createElement(Label, {
dots: dots,
size: 15,
value: node.label
}), /*#__PURE__*/React.createElement(Span, {
color: "info",
dots: dots,
size: 20,
value: node.operatorLabel,
variant: "info1"
})), node.value ? /*#__PURE__*/React.createElement("div", null, Array.isArray(node.value) ? node.value.map((value, indexValue) => {
const label = node.type === 'date' ? new XDate(value.label || value).toString('dd/MM/yyyy') : value.label || value;
return /*#__PURE__*/React.createElement(Value, {
dots: dots,
key: `chip-${1 + indexValue}`,
label: label,
size: 10
});
}) : /*#__PURE__*/React.createElement(Value, {
dots: dots,
label: node.type === 'date' ? new XDate(node.value).toString('dd/MM/yyyy') : node.value,
size: 10
})) : null), /*#__PURE__*/React.createElement("div", {
className: classes.rowPanelRight
}, buttons)))))));
return nodeContent;
}
process.env.NODE_ENV !== "production" ? FileThemeNodeContentRenderer.propTypes = {
buttons: PropTypes.node,
canDrag: PropTypes.bool,
canDrop: PropTypes.bool,
className: PropTypes.string,
connectDragPreview: PropTypes.func.isRequired,
connectDragSource: PropTypes.func.isRequired,
didDrop: PropTypes.bool.isRequired,
draggedNode: PropTypes.shape({}),
isDragging: PropTypes.bool.isRequired,
isOver: PropTypes.bool.isRequired,
isSearchFocus: PropTypes.bool,
isSearchMatch: PropTypes.bool,
label: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
listIndex: PropTypes.number.isRequired,
lowerSiblingCounts: PropTypes.arrayOf(PropTypes.number).isRequired,
node: PropTypes.shape({}).isRequired,
parentNode: PropTypes.shape({}),
path: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])).isRequired,
rowDirection: PropTypes.string.isRequired,
scaffoldBlockPxWidth: PropTypes.number.isRequired,
style: PropTypes.shape({}),
swapDepth: PropTypes.number,
swapFrom: PropTypes.number,
swapLength: PropTypes.number,
toggleChildrenVisibility: PropTypes.func,
treeId: PropTypes.string.isRequired,
treeIndex: PropTypes.number.isRequired
} : void 0;
export default FileThemeNodeContentRenderer;