Skip to content

Commit 716ccdd

Browse files
author
Teddy Sterne
committedJun 15, 2020
Added basic preview image for draggable elements
1 parent 59bc14a commit 716ccdd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎src/pages/game/components/BaseCard.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const BaseCard = React.forwardRef<
2121
const { children, card, transition = "none", showPower, ...rest } = props;
2222
const { onLongPress, ...imgProps } = rest;
2323
const [preview, setPreview] = useState(false);
24-
const [{ isDragging }, drag] = useDrag({
24+
const [{ isDragging }, drag, dragPreview] = useDrag({
2525
item: { type: "power", value: card },
2626
canDrag: card.canAttach && showPower,
2727
collect: (monitor) => ({ isDragging: monitor.isDragging() }),
@@ -31,7 +31,10 @@ export const BaseCard = React.forwardRef<
3131

3232
return (
3333
<Card
34-
innerRef={drag}
34+
innerRef={(inst) => {
35+
drag(inst);
36+
dragPreview(inst);
37+
}}
3538
style={{ position: "relative", flexDirection: "column" }}>
3639
<SwitchTransition mode="out-in">
3740
<CSSTransition

‎src/pages/game/components/Fate.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface Props {
1313
}
1414
export const Fate: FC<Props> = (props) => {
1515
const { num: value, source, styles, onClick, highlight } = props;
16-
const [{ isDragging }, drag] = useDrag({
16+
const [{ isDragging }, drag, dragPreview] = useDrag({
1717
item: { type: "fate", value, source },
1818
canDrag: !!source,
1919
collect: (monitor) => ({ isDragging: monitor.isDragging() }),
@@ -32,7 +32,10 @@ export const Fate: FC<Props> = (props) => {
3232
exit: 350,
3333
}}>
3434
<Tile
35-
ref={drag}
35+
ref={(inst) => {
36+
drag(inst);
37+
dragPreview(inst);
38+
}}
3639
{...longPressProps}
3740
onContextMenu={(e) => {
3841
handler();

0 commit comments

Comments
 (0)
Please sign in to comment.