-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename files and add data as parameter
- Loading branch information
1 parent
4bbec52
commit ede832c
Showing
5 changed files
with
137 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useState } from 'react'; | ||
import { useDrag, useDrop } from 'react-dnd'; | ||
import './App.css'; | ||
|
||
const CardType = { TEXT: 'text', TEST: 'test' }; | ||
|
||
function KanbanCard({ text }) { | ||
return (<p>{text}</p>); | ||
} | ||
|
||
function KanbanRow({ | ||
text, rowId, handleDrop, | ||
}) { | ||
const [{ opacity }, drag] = useDrag(() => ({ | ||
type: CardType.TEXT, | ||
item: { rowId }, | ||
collect: (monitor) => ({ | ||
opacity: monitor.isDragging() ? 0.5 : 0.9, | ||
}), | ||
end(item, monitor) { | ||
const dropResult = monitor.getDropResult(); | ||
if (dropResult !== null) { | ||
handleDrop(item.rowId, dropResult.colId); | ||
} | ||
}, | ||
}), [rowId]); | ||
|
||
return ( | ||
<div ref={drag} className='content-row' style={{ opacity }}> | ||
<KanbanCard text={text}/> | ||
</div> | ||
); | ||
} | ||
|
||
function KanbanColumn(props) { | ||
const { | ||
colName, color, colId, | ||
} = props; | ||
const [{ canDrop, isOver }, drop] = useDrop(() => ({ | ||
accept: CardType.TEXT, | ||
drop: () => ({ colName, colId }), | ||
collect: (monitor) => ({ | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}), | ||
}), [colName, colId]); | ||
|
||
const isActive = canDrop && isOver; | ||
const droppingBox = isActive ? 'dropping-box' : ''; | ||
return ( | ||
<div ref={drop} className={`col bg-color-${color} ${droppingBox}`}> | ||
<div className='col-header'>{colName}</div> | ||
{props.children} | ||
</div> | ||
); | ||
} | ||
|
||
function moveCards(kanbanColumns, destColId, rowId) { | ||
const srcColumn = kanbanColumns | ||
.find((column) => column.data.map((data) => data.rowId).includes(rowId)); | ||
const destColumn = kanbanColumns.find((column) => column.colId === destColId); | ||
const rowIndexPosInSrcColumn = srcColumn.data.findIndex((row) => row.rowId === rowId); | ||
destColumn.data.push(srcColumn.data[rowIndexPosInSrcColumn]); | ||
srcColumn.data.splice(rowIndexPosInSrcColumn, 1); | ||
return [...kanbanColumns]; | ||
} | ||
|
||
function SimpleKanban({ initialKanbanColumns }) { | ||
const [kanbanColumns, setKanbanColumns] = useState(initialKanbanColumns); | ||
|
||
const handleDrop = (rowId, colId) => { | ||
setKanbanColumns((prevKanbanColumns) => moveCards(prevKanbanColumns, colId, rowId)); | ||
}; | ||
|
||
return ( | ||
<div className="container"> | ||
{ | ||
kanbanColumns && kanbanColumns.map((column) => ( | ||
<KanbanColumn | ||
key={column.colId} | ||
colName={column.colName} | ||
color={column.color} | ||
colId={column.colId} | ||
> | ||
{column.data.map( | ||
({ text, rowId }) => <KanbanRow | ||
key={rowId} | ||
text={text} | ||
rowId={rowId} | ||
handleDrop={handleDrop} | ||
/>, | ||
) | ||
} | ||
</KanbanColumn>)) | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
export default SimpleKanban; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters