Skip to content

Commit 63bc2fb

Browse files
committed
fix: Rewrite drag-n-drop functionality to track cards moved from one lane to another
With react-dnd, it was difficult to add placeholders and also find the exact position when a card was dropped from one lane to another. Now using react-beautiful-dnd to handle all drag-n-drop features #44
1 parent 66d233e commit 63bc2fb

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

src/components/Lane.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ class Lane extends Component {
5959
})
6060
}
6161

62-
laneDidMount = node => {
62+
laneDidMount = (node, dragReference) => {
6363
if (node) {
6464
node.addEventListener('scroll', this.handleScroll)
65+
dragReference(node)
6566
}
6667
}
6768

@@ -204,20 +205,20 @@ class Lane extends Component {
204205
const isDropDisabled = !droppable
205206
return (
206207
<Droppable droppableId={id} type="card" index={index} isDropDisabled={isDropDisabled}>
207-
{(dropProvided, dropSnapshot) => (
208-
<ScrollableLane innerRef={this.laneDidMount}>
209-
<Section
210-
{...otherProps}
211-
key={id}
212-
onClick={() => onLaneClick && onLaneClick(id)}
213-
innerRef={dropProvided.innerRef}
214-
{...dropProvided.draggableProps}>
215-
{this.renderHeader()}
216-
{this.renderDragContainer()}
217-
{loading && <Loader />}
218-
</Section>
219-
</ScrollableLane>
220-
)}
208+
{(dropProvided, dropSnapshot) => {
209+
const isDraggingOver = dropSnapshot.isDraggingOver
210+
return <Section
211+
{...otherProps}
212+
key={id}
213+
onClick={() => onLaneClick && onLaneClick(id)}
214+
innerRef={ref => this.laneDidMount(ref, dropProvided.innerRef)}
215+
isDraggingOver={isDraggingOver}
216+
{...dropProvided.draggableProps}>
217+
{this.renderHeader()}
218+
{this.renderDragContainer()}
219+
{loading && <Loader/>}
220+
</Section>
221+
}}
221222
</Droppable>
222223
)
223224
}

src/styles/Base.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@ export const BoardDiv = styled.div`
2626
height: 100vh;
2727
`
2828

29-
export const ScrollableLane = styled.div`
30-
height: auto;
31-
max-height: 95%;
32-
overflow-y: auto;
33-
min-width: 250px;
34-
`
35-
3629
export const Section = styled.section`
3730
background-color: #e3e3e3;
3831
border-radius: 3px;
3932
margin: 5px 5px;
33+
position: relative;
4034
padding: 10px;
41-
35+
min-width: 250px;
36+
height: auto;
37+
padding-bottom: ${props => (props.isDraggingOver ? '130px' : '30px')};
38+
max-height: 95%;
39+
overflow-y: auto;
4240
`
4341

4442
export const Header = styled.header`
@@ -68,8 +66,9 @@ export const CardWrapper = styled.article`
6866
border-radius: 3px;
6967
margin: 10px 0px;
7068
border-bottom: 1px solid #ccc;
69+
background-color: #fff;
7170
position: relative;
72-
padding: 6px 8px;
71+
padding: 10px;
7372
cursor: pointer;
7473
transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
7574
max-width: 250px;
@@ -131,11 +130,11 @@ export const AddCardLink = styled.a`
131130
border-radius: 0 0 3px 3px;
132131
color: #838c91;
133132
display: block;
134-
flex: 0 0 auto;
135133
padding: 5px 2px;
136-
position: relative;
134+
position: absolute;
137135
text-decoration: none;
138136
cursor: pointer;
137+
bottom: 3px;
139138
140139
&:hover {
141140
//background-color: #cdd2d4;

stories/DragDrop.story.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import Board from '../src'
66

77
const data = require('./data.json')
88

9-
storiesOf('Advanced Features', module).add(
10-
'Drag-n-Drop',
9+
storiesOf('Drag-n-Drop', module).add(
10+
'Basic',
1111
withInfo('A demonstration of onDragStart and onDragEnd hooks')(() => {
1212
const handleDragStart = (cardId, laneId) => {
1313
console.log('drag started')

stories/RestrictedLanes.story.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import Board from '../src'
66

77
const data = require('./drag-drop.json')
88

9-
storiesOf('Advanced Features', module).add(
10-
'Restrict Drag-n-Drop',
11-
withInfo('Use droppable property to pervent some lanes from being droppable')(() => {
9+
storiesOf('Drag-n-Drop', module).add(
10+
'Restrict lanes',
11+
withInfo('Use droppable property to prevent some lanes from being droppable')(() => {
1212
return (
1313
<Board
1414
data={data}

stories/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"id": "WIP",
36-
"title": "Work In Progress (Not Droppable)",
36+
"title": "Work In Progress",
3737
"label": "10/20",
3838
"cards": [
3939
{

0 commit comments

Comments
 (0)