From b17d817696ac360d4fb234be2911620cc8147877 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Thu, 29 Apr 2021 13:13:25 +0300 Subject: [PATCH] Initial drag-n-drop implementation Signed-off-by: Alex Andreev --- .../components/hotbar/hotbar-menu.tsx | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index b53161039e..a7af60a6e8 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -1,7 +1,7 @@ import "./hotbar-menu.scss"; import "./hotbar.commands"; -import React, { ReactNode, useState } from "react"; +import React, { HTMLAttributes, ReactNode, useState } from "react"; import { observer } from "mobx-react"; import { HotbarIcon } from "./hotbar-icon"; import { cssNames, IClassName } from "../../utils"; @@ -36,24 +36,45 @@ export class HotbarMenu extends React.Component { return item ? catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid) : null; } - renderGrid() { - if (!this.hotbar.items.length) return; + onDragEnd() { + console.log("drag end") + } + renderGrid() { return this.hotbar.items.map((item, index) => { const entity = this.getEntity(item); return ( - - {entity && ( - + {(provided, snapshot) => ( + entity.onRun(catalogEntityRunContext)} - /> + ref={provided.innerRef} + style={{ backgroundColor: snapshot.isDraggingOver ? 'blue' : 'grey' }} + {...provided.droppableProps} + > + {entity && ( + + {(provided, snapshot) => ( +
+ entity.onRun(catalogEntityRunContext)} + /> +
+ )} +
+ )} +
)} -
+ ); }); } @@ -74,7 +95,9 @@ export class HotbarMenu extends React.Component { return (
- {this.renderGrid()} + + {this.renderGrid()} + {this.hotbar.items.length != defaultHotbarCells && this.renderAddCellButton()}
@@ -83,9 +106,10 @@ export class HotbarMenu extends React.Component { } } -interface HotbarCellProps { +interface HotbarCellProps extends HTMLAttributes { children?: ReactNode; index: number; + ref?: any; } function HotbarCell(props: HotbarCellProps) {