add drag&drop to instruction menu

This commit is contained in:
Ole Morud
2022-08-22 13:56:21 +02:00
parent 587b7c6cc4
commit ef0291f382

View File

@@ -15,6 +15,19 @@ const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => (
} }
})) }))
function handleDragStart(
instruction: Instruction,
event: React.DragEvent<HTMLDivElement> | undefined
): void {
if (event === undefined) {
console.log("handleDragStart: event is undefined")
return
}
event.dataTransfer.dropEffect = "copy"
event.dataTransfer.setData("text/plain", instruction.symbol)
}
export default function InstructionMenu() { export default function InstructionMenu() {
let key = 0 let key = 0
@@ -32,11 +45,13 @@ export default function InstructionMenu() {
<Typography>{instruction.description}</Typography> <Typography>{instruction.description}</Typography>
</> </>
}> }>
<div draggable="true" onDragStart={(event) => handleDragStart(instruction, event)}>
<Card key={key++} sx={{ height: "3rem", width: "3rem" }}> <Card key={key++} sx={{ height: "3rem", width: "3rem" }}>
<CardContent> <CardContent>
<Typography sx={{ userSelect: "none" }}>{instruction.symbol}</Typography> <Typography sx={{ userSelect: "none" }}>{instruction.symbol}</Typography>
</CardContent> </CardContent>
</Card> </Card>
</div>
</HtmlTooltip> </HtmlTooltip>
</div> </div>
) )