Skip to content

Commit 559db43

Browse files
committed
Fix the arrow so it points at the correct destination level
1 parent 36b8f7f commit 559db43

File tree

3 files changed

+58
-75
lines changed

3 files changed

+58
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sortable-tree",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Drag-and-drop sortable representation of hierarchical data",
55
"scripts": {
66
"build": "npm run lint && npm run test && npm run build:demo && npm run build:umd",

src/tree-node.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,33 @@ const TreeNode = ({
8181
/>
8282
);
8383

84-
if (treeIndex !== listIndex) {
85-
// This row has been shifted
84+
if (treeIndex !== listIndex && i === swapDepth) {
85+
// This row has been shifted, and is at the depth of
86+
// the line pointing to the new destination
8687
let highlightLineClass = '';
87-
if (i === swapDepth) {
88-
// This block is at the depth of the line pointing to the new destination
8988

90-
if (listIndex === swapFrom + swapLength - 1) {
91-
// This block is on the bottom (target) line
92-
highlightLineClass = styles.highlightBottomLeftCorner;
93-
} else if (treeIndex === swapFrom) {
94-
// This block is on the top (source) line
95-
highlightLineClass = styles.highlightTopLeftCorner;
96-
} else {
97-
// This block is between the bottom and top
98-
highlightLineClass = styles.highlightLineVertical;
99-
}
100-
} else if (i === swapDepth + 1 && listIndex === swapFrom + swapLength - 1) {
89+
if (listIndex === swapFrom + swapLength - 1) {
90+
// This block is on the bottom (target) line
10191
// This block points at the target block (where the row will go when released)
102-
highlightLineClass = styles.highlightArrow;
92+
highlightLineClass = styles.highlightBottomLeftCorner;
93+
} else if (treeIndex === swapFrom) {
94+
// This block is on the top (source) line
95+
highlightLineClass = styles.highlightTopLeftCorner;
96+
} else {
97+
// This block is between the bottom and top
98+
highlightLineClass = styles.highlightLineVertical;
10399
}
104100

105-
// Add the highlight line block if it met one of the conditions above
106-
if (highlightLineClass) {
107-
scaffold.push(
108-
<div
109-
key={`highlight_${i}`}
110-
style={{
111-
width: scaffoldBlockPxWidth,
112-
left: scaffoldBlockPxWidth * i,
113-
}}
114-
className={`${styles.absoluteLineBlock} ${highlightLineClass}`}
115-
/>
116-
);
117-
}
101+
scaffold.push(
102+
<div
103+
key={`highlight_${i}`}
104+
style={{
105+
width: scaffoldBlockPxWidth,
106+
left: scaffoldBlockPxWidth * i,
107+
}}
108+
className={`${styles.absoluteLineBlock} ${highlightLineClass}`}
109+
/>
110+
);
118111
}
119112
});
120113

src/tree-node.scss

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -104,47 +104,6 @@
104104
$highlight-color: #36C2F6;
105105
$highlight-line-size: 8px; // Make it an even number for clean rendering
106106

107-
%highlightLineBase {
108-
position: absolute;
109-
content: '';
110-
background-color: $highlight-color;
111-
z-index: 3;
112-
}
113-
114-
/**
115-
* +-----+
116-
* | |
117-
* | |
118-
* | |
119-
* ======>
120-
*/
121-
.highlightArrow {
122-
$arrow-size: 18px;
123-
z-index: 3;
124-
125-
&::before {
126-
content: '';
127-
position: absolute;
128-
border-bottom: solid $highlight-line-size $highlight-color;
129-
height: calc(100% - #{$highlight-line-size / 2});
130-
top: 0;
131-
right: $arrow-size;
132-
width: calc(100% - #{$arrow-size});
133-
}
134-
135-
&::after {
136-
content: '';
137-
position: absolute;
138-
height: 0;
139-
right: 0;
140-
top: 100%;
141-
margin-top: -1 * $arrow-size / 1.46 ;
142-
border-top: $arrow-size / 1.4 solid transparent;
143-
border-bottom: $arrow-size / 1.4 solid transparent;
144-
border-left: $arrow-size solid $highlight-color;
145-
}
146-
}
147-
148107
/**
149108
* +--+--+
150109
* | | |
@@ -153,8 +112,12 @@ $highlight-line-size: 8px; // Make it an even number for clean rendering
153112
* +--+--+
154113
*/
155114
.highlightLineVertical {
115+
z-index: 3;
116+
156117
&::before {
157-
@extend %highlightLineBase;
118+
position: absolute;
119+
content: '';
120+
background-color: $highlight-color;
158121
width: $highlight-line-size;
159122
margin-left: $highlight-line-size / -2;
160123
left: 50%;
@@ -183,7 +146,6 @@ $highlight-line-size: 8px; // Make it an even number for clean rendering
183146
}
184147

185148
&::after {
186-
z-index: 3;
187149
content: '';
188150
position: absolute;
189151
height: 0;
@@ -197,6 +159,13 @@ $highlight-line-size: 8px; // Make it an even number for clean rendering
197159
}
198160
}
199161

162+
/**
163+
* +-----+
164+
* | |
165+
* | +--+
166+
* | | |
167+
* +--+--+
168+
*/
200169
.highlightTopLeftCorner {
201170
&::before {
202171
z-index: 3;
@@ -212,16 +181,37 @@ $highlight-line-size: 8px; // Make it an even number for clean rendering
212181
}
213182
}
214183

184+
/**
185+
* +--+--+
186+
* | | |
187+
* | | |
188+
* | +->|
189+
* +-----+
190+
*/
215191
.highlightBottomLeftCorner {
192+
$arrow-size: 12px;
193+
z-index: 3;
194+
216195
&::before {
217-
z-index: 3;
218196
content: '';
219197
position: absolute;
220198
border-bottom: solid $highlight-line-size $highlight-color;
221199
border-left: solid $highlight-line-size $highlight-color;
222200
height: calc(100% - #{$highlight-line-size / 2});
223201
top: 0;
202+
right: $arrow-size;
203+
width: calc(50% - #{$arrow-size + ($highlight-line-size / 2)});
204+
}
205+
206+
&::after {
207+
content: '';
208+
position: absolute;
209+
height: 0;
224210
right: 0;
225-
width: calc(50% - #{$highlight-line-size / 2});
211+
top: 100%;
212+
margin-top: -1 * $arrow-size ;
213+
border-top: $arrow-size solid transparent;
214+
border-bottom: $arrow-size solid transparent;
215+
border-left: $arrow-size solid $highlight-color;
226216
}
227217
}

0 commit comments

Comments
 (0)