import React from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; import uid from 'uuid/v4'; import faker from 'faker/locale/en_US'; import classNames from 'classnames'; import { Card, CardHeader, CardTitle, Media, Avatar, AvatarAddOn } from './../../../../components'; import { randomAvatar, randomArray } from './../../../../utilities'; import { reorder, move } from './utilities'; import classes from './common.scss'; // Utility Functions //========================================================= const generateItem = () => ({ id: uid(), type: 'single', name: `${faker.name.firstName()} ${faker.name.lastName()}`, title: faker.name.jobType(), avatarUrl: randomAvatar(), status: randomArray(['success', 'warning', 'danger']) }); const getListClass = (isDraggedOver) => classNames(classes['list'], { [classes['list--drag-over']]: isDraggedOver }); const getItemClass = (isDragging) => classNames(classes['list-group-item'], { [classes['list-group-item--dragging']]: isDragging }); // Draggable List Component //========================================================= const VerticalList = React.memo((props) => { return ( {(provided, snapshot) => (
{props.items.map((item, index) => ( {(provided, draggableSnapshot) => (
, ]} /> { item.name }

{ item.title }

)}
))}
)}
); }); VerticalList.propTypes = { items: PropTypes.array, listId: PropTypes.string, title: PropTypes.string } // Draggable Column Component //========================================================= class Column extends React.Component { static propTypes = { children: PropTypes.node, id: PropTypes.string, index: PropTypes.number, title: PropTypes.string } render() { const { children, id, index, title } = this.props; return ( {(provided) => (
{ title } { children }
)}
) } } // Demo Component //========================================================= const initialState = { listAItems: _.times(_.random(2, 4), generateItem), listBItems: _.times(_.random(3, 8), generateItem), listCItems: _.times(_.random(3, 8), generateItem), lists: [ { id: 'listA', title: 'All Candidates' }, { id: 'listB', title: 'Candidates Interview' }, { id: 'listC', title: 'Candidates Testing' } ] }; export class MultipleVerticalLists extends React.Component { static propTypes = { className: PropTypes.string } state = _.clone(initialState); constructor (props) { super(props); this.onDragEnd = this.onDragEnd.bind(this); } onDragEnd(result) { const { source, destination } = result; // Swap column positions if (source.droppableId === 'board') { if (destination.droppableId !== 'board') { return; } const lists = reorder( this.state.lists, source.index, destination.index ); this.setState({ lists }); return; } // dropped outside the list if (!destination) { return; } // Handle List Items if (source.droppableId === destination.droppableId) { const items = reorder( this.state[`${source.droppableId}Items`], source.index, destination.index ); this.setState({ [`${source.droppableId}Items`]: items }); } else { const result = move( this.state[`${source.droppableId}Items`], this.state[`${destination.droppableId}Items`], source, destination ); this.setState(_.mapKeys(result, (val, key) => `${key}Items`)); } } recoverInitialState() { this.setState(initialState); } render() { const { className } = this.props; const { lists } = this.state; return (
{(provided) => (
{_.map(lists, (list, index) => ( ))}
)}
) } }