Skip to content

Commit 69132b6

Browse files
committed
Add variables for calculation of custom dragging bounds.
1 parent aa88e2c commit 69132b6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/components/cards/cards.jsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,35 @@ const Cards = props => {
264264

265265
if (activeDeckId === null) return;
266266

267+
// Tutorial cards need to calculate their own dragging bounds
268+
// to allow for dragging the cards off the left, right and bottom
269+
// edges of the workspace, used in the custom overlay 'card-container-overlay'
270+
const cardHorizontalOffset = 400; // 80% of approx. card width
271+
const cardVerticalOffset = 256; // 80% of approx. card height
272+
const menuBarHeight = 48; // TODO: get pre-calculated from elsewhere?
273+
267274
if (x === 0 && y === 0) {
268275
// initialize positions
269276
x = isRtl ? -292 : 292;
270-
// The tallest cards are about 385px high, and the default position is pinned
277+
x += cardHorizontalOffset;
278+
// The tallest cards are about 320px high, and the default position is pinned
271279
// to near the bottom of the blocks palette to allow room to work above.
272-
const tallCardHeight = 385;
280+
const tallCardHeight = 320;
273281
const bottomMargin = 60; // To avoid overlapping the backpack region
274-
y = window.innerHeight - tallCardHeight - bottomMargin;
282+
y = window.innerHeight - tallCardHeight - bottomMargin - menuBarHeight;
275283
}
276284

277285
const steps = content[activeDeckId].steps;
278286

279287
return (
288+
// Use a custom overlay to act as the bounding parent for the draggable
280289
<div
281290
className={styles.cardContainerOverlay}
282291
style={{
283-
width: `${window.innerWidth + (2 * 300)}px`,
284-
height: `${window.innerHeight + (2 * 300)}px`
292+
width: `${window.innerWidth + (2 * cardHorizontalOffset)}px`,
293+
height: `${window.innerHeight - menuBarHeight + cardVerticalOffset}px`,
294+
top: `${menuBarHeight}px`,
295+
left: `${-cardHorizontalOffset}px`
285296
}}
286297
>
287298
<Draggable

0 commit comments

Comments
 (0)