import React, { useState } from 'react'; import PropTypes from 'prop-types'; import AnimateHeight from 'react-animate-height'; import { Draggable } from 'react-beautiful-dnd'; import ActionPanel from './ActionPanel'; import SectionTitle from './SectionTitle'; import PositionPanel from './PositionPanel'; import Button from '../../elements/Button'; import { NegativeFieldGutterProvider } from '../FieldTypeGutter/context'; import FieldTypeGutter from '../FieldTypeGutter'; import RenderFields from '../RenderFields'; import './index.scss'; const baseClass = 'draggable-section'; const DraggableSection = (props) => { const { moveRow, addRow, removeRow, rowIndex, rowCount, parentPath, fieldSchema, label, blockType, fieldTypes, toggleRowCollapse, id, positionPanelVerticalAlignment, actionPanelVerticalAlignment, permissions, isOpen, readOnly, } = props; const [isHovered, setIsHovered] = useState(false); const classes = [ baseClass, isOpen ? 'is-open' : 'is-closed', isHovered && 'is-hovered', ].filter(Boolean).join(' '); return ( {(providedDrag) => (
setIsHovered(false)} onMouseOver={() => setIsHovered(true)} onFocus={() => setIsHovered(true)} {...providedDrag.draggableProps} >
{blockType === 'blocks' && (
)} ({ ...field, path: `${parentPath}.${rowIndex}${field.name ? `.${field.name}` : ''}`, }))} />
{!readOnly && ( )}
)}
); }; DraggableSection.defaultProps = { toggleRowCollapse: undefined, rowCount: null, initialData: undefined, label: '', blockType: '', isOpen: true, positionPanelVerticalAlignment: 'sticky', actionPanelVerticalAlignment: 'sticky', permissions: {}, readOnly: false, }; DraggableSection.propTypes = { moveRow: PropTypes.func.isRequired, addRow: PropTypes.func.isRequired, removeRow: PropTypes.func.isRequired, toggleRowCollapse: PropTypes.func, rowIndex: PropTypes.number.isRequired, parentPath: PropTypes.string.isRequired, label: PropTypes.string, fieldSchema: PropTypes.arrayOf(PropTypes.shape({})).isRequired, rowCount: PropTypes.number, initialData: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.shape({})]), isOpen: PropTypes.bool, blockType: PropTypes.string, fieldTypes: PropTypes.shape({}).isRequired, id: PropTypes.string.isRequired, positionPanelVerticalAlignment: PropTypes.oneOf(['top', 'center', 'sticky']), actionPanelVerticalAlignment: PropTypes.oneOf(['top', 'center', 'sticky']), permissions: PropTypes.shape({}), readOnly: PropTypes.bool, }; export default DraggableSection;