2019-10-17 15:18:35 +02:00
|
|
|
/* eslint-disable react/display-name */
|
|
|
|
import React, { forwardRef } from 'react';
|
2019-10-15 18:32:19 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-10-17 15:52:02 +02:00
|
|
|
import { useDraggedField } from '../../contexts/DraggedField';
|
2019-10-16 16:53:53 +02:00
|
|
|
import GrabIcon from '../../icons/GrabIcon';
|
2019-10-17 15:52:02 +02:00
|
|
|
import PencilIcon from '../../icons/PencilIcon';
|
2019-10-16 16:53:53 +02:00
|
|
|
import RemoveIcon from '../../icons/RemoveIcon';
|
2019-10-17 15:18:35 +02:00
|
|
|
|
2019-10-15 18:32:19 +02:00
|
|
|
import Wrapper from './Wrapper';
|
|
|
|
|
2019-10-17 15:18:35 +02:00
|
|
|
const DraggedField = forwardRef(
|
|
|
|
({ count, isDragging, name, onClick, onRemove }, ref) => {
|
|
|
|
const opacity = isDragging ? 0.2 : 1;
|
2019-10-17 15:52:02 +02:00
|
|
|
const { selectedItem } = useDraggedField();
|
|
|
|
const isSelected = selectedItem === name;
|
2019-10-17 15:18:35 +02:00
|
|
|
|
|
|
|
return (
|
2019-10-17 15:52:02 +02:00
|
|
|
<Wrapper count={count} isSelected={isSelected}>
|
2019-10-17 15:18:35 +02:00
|
|
|
<div className="sub_wrapper" style={{ opacity }}>
|
|
|
|
<div className="grab" ref={ref}>
|
|
|
|
<GrabIcon style={{ marginRight: 10, cursor: 'move' }} />
|
|
|
|
</div>
|
|
|
|
<div className="name" onClick={() => onClick(name)}>
|
|
|
|
{name}
|
|
|
|
</div>
|
|
|
|
<div className="remove" onClick={onRemove}>
|
2019-10-17 15:52:02 +02:00
|
|
|
{isSelected ? <PencilIcon /> : <RemoveIcon />}
|
2019-10-17 15:18:35 +02:00
|
|
|
</div>
|
2019-10-16 16:53:53 +02:00
|
|
|
</div>
|
2019-10-17 15:18:35 +02:00
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2019-10-15 18:32:19 +02:00
|
|
|
|
2019-10-16 19:59:00 +02:00
|
|
|
DraggedField.defaultProps = {
|
|
|
|
count: 1,
|
2019-10-17 15:18:35 +02:00
|
|
|
isDragging: false,
|
2019-10-16 19:59:00 +02:00
|
|
|
};
|
|
|
|
|
2019-10-15 18:32:19 +02:00
|
|
|
DraggedField.propTypes = {
|
2019-10-16 19:59:00 +02:00
|
|
|
count: PropTypes.number,
|
2019-10-17 15:18:35 +02:00
|
|
|
isDragging: PropTypes.bool,
|
2019-10-15 18:32:19 +02:00
|
|
|
name: PropTypes.string.isRequired,
|
2019-10-17 10:45:37 +02:00
|
|
|
onClick: PropTypes.func.isRequired,
|
2019-10-16 16:53:53 +02:00
|
|
|
onRemove: PropTypes.func.isRequired,
|
2019-10-15 18:32:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DraggedField;
|