2020-05-14 21:31:48 -04:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
import { useDrop } from 'react-dnd';
|
|
|
|
|
|
2020-05-14 22:01:34 -04:00
|
|
|
// NOTE: If we found a way to make `useDrop` conditional,
|
|
|
|
|
// Or we provided a HOC of this component, we could provide
|
|
|
|
|
// this UI without the DragAndDropContext dependency.
|
2020-05-18 17:21:57 +02:00
|
|
|
function ViewportPane({
|
|
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
isActive,
|
|
|
|
|
onDrop,
|
|
|
|
|
acceptDropsFor,
|
|
|
|
|
}) {
|
2020-05-18 23:40:28 +02:00
|
|
|
/*const [{ isHovered, isHighlighted }, drop] = useDrop({
|
2020-05-18 17:21:57 +02:00
|
|
|
accept: acceptDropsFor,
|
2020-05-14 21:31:48 -04:00
|
|
|
// TODO: pass in as prop?
|
2020-05-18 17:21:57 +02:00
|
|
|
drop: (droppedItem, monitor) => {
|
2020-05-14 21:31:48 -04:00
|
|
|
const canDrop = monitor.canDrop();
|
|
|
|
|
const isOver = monitor.isOver();
|
|
|
|
|
|
|
|
|
|
if (canDrop && isOver && onDrop) {
|
2020-05-18 17:21:57 +02:00
|
|
|
onDrop(droppedItem);
|
2020-05-14 21:31:48 -04:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Monitor, and collect props; returned as values by `useDrop`
|
|
|
|
|
collect: monitor => ({
|
|
|
|
|
isHighlighted: monitor.canDrop(),
|
|
|
|
|
isHovered: monitor.isOver(),
|
|
|
|
|
}),
|
2020-05-18 23:40:28 +02:00
|
|
|
});*/
|
2020-05-14 21:31:48 -04:00
|
|
|
|
2020-05-18 23:40:28 +02:00
|
|
|
// ref={drop}
|
2020-05-14 21:31:48 -04:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={classnames(
|
|
|
|
|
'rounded-lg hover:border-primary-light transition duration-300 outline-none overflow-hidden',
|
|
|
|
|
{
|
2020-05-14 22:55:17 -04:00
|
|
|
'border-2 border-primary-light m-0': isActive,
|
2020-05-14 21:31:48 -04:00
|
|
|
'border border-secondary-light': !isActive,
|
2020-05-14 22:25:01 -04:00
|
|
|
},
|
|
|
|
|
className
|
2020-05-14 21:31:48 -04:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewportPane.propTypes = {
|
|
|
|
|
/** The ViewportComp */
|
|
|
|
|
children: PropTypes.node.isRequired,
|
2020-05-14 22:25:01 -04:00
|
|
|
/** Classes to append to container */
|
|
|
|
|
className: PropTypes.string,
|
2020-05-14 21:31:48 -04:00
|
|
|
/** Bool to show active styling */
|
|
|
|
|
isActive: PropTypes.bool.isRequired,
|
2020-05-18 17:21:57 +02:00
|
|
|
/** Indicates drag items we should accept for drops */
|
|
|
|
|
acceptDropsFor: PropTypes.string.isRequired,
|
2020-05-14 21:31:48 -04:00
|
|
|
/** Function that handles drop events */
|
|
|
|
|
onDrop: PropTypes.func.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ViewportPane;
|