From a001b651b93e6689892758ed0226ffdf73b075ee Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Thu, 29 Apr 2021 11:56:29 +0300 Subject: [PATCH] Moving HotbarSelector to separate component Signed-off-by: Alex Andreev --- .../components/hotbar/hotbar-menu.scss | 37 ------------------- .../components/hotbar/hotbar-menu.tsx | 33 ++--------------- .../components/hotbar/hotbar-selector.scss | 36 ++++++++++++++++++ .../components/hotbar/hotbar-selector.tsx | 34 +++++++++++++++++ 4 files changed, 73 insertions(+), 67 deletions(-) create mode 100644 src/renderer/components/hotbar/hotbar-selector.scss create mode 100644 src/renderer/components/hotbar/hotbar-selector.tsx diff --git a/src/renderer/components/hotbar/hotbar-menu.scss b/src/renderer/components/hotbar/hotbar-menu.scss index af41e1b95b..ba4f17dfba 100644 --- a/src/renderer/components/hotbar/hotbar-menu.scss +++ b/src/renderer/components/hotbar/hotbar-menu.scss @@ -105,43 +105,6 @@ } } - .HotbarSelector { - height: 26px; - background-color: var(--layoutBackground); - position: relative; - - &:before { - content: " "; - position: absolute; - width: 100%; - height: 20px; - background: linear-gradient(0deg, var(--clusterMenuBackground), transparent); - top: -20px; - } - - .Badge { - cursor: pointer; - background: var(--secondaryBackground); - width: 100%; - color: var(--settingsColor); - padding-top: 3px; - } - - .Icon { - --size: 16px; - padding: 0 4px; - - &:hover { - box-shadow: none; - background-color: transparent; - } - - &.previous { - transform: rotateY(180deg); - } - } - } - .AddCellButton { width: 40px; height: 40px; diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index 29c44fc81e..b53161039e 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -9,10 +9,8 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { defaultHotbarCells, HotbarItem, HotbarStore } from "../../../common/hotbar-store"; import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity"; import { Icon } from "../icon"; -import { Badge } from "../badge"; -import { CommandOverlay } from "../command-palette"; -import { HotbarSwitchCommand } from "./hotbar-switch-command"; -import { Tooltip, TooltipPosition } from "../tooltip"; +import { DragDropContext, Draggable, DraggableProvided, Droppable, DroppableProvided, DropResult } from "react-beautiful-dnd"; +import { HotbarSelector } from "./hotbar-selector"; interface Props { className?: IClassName; @@ -38,18 +36,6 @@ export class HotbarMenu extends React.Component { return item ? catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid) : null; } - previous() { - HotbarStore.getInstance().switchToPrevious(); - } - - next() { - HotbarStore.getInstance().switchToNext(); - } - - openSelector() { - CommandOverlay.open(); - } - renderGrid() { if (!this.hotbar.items.length) return; @@ -84,7 +70,6 @@ export class HotbarMenu extends React.Component { const { className } = this.props; const hotbarStore = HotbarStore.getInstance(); const hotbar = hotbarStore.getActive(); - const activeIndexDisplay = hotbarStore.activeHotbarIndex + 1; return (
@@ -92,19 +77,7 @@ export class HotbarMenu extends React.Component { {this.renderGrid()} {this.hotbar.items.length != defaultHotbarCells && this.renderAddCellButton()}
-
- this.previous()} /> -
- this.openSelector()} /> - - {hotbar.name} - -
- this.next()} /> -
+ ); } diff --git a/src/renderer/components/hotbar/hotbar-selector.scss b/src/renderer/components/hotbar/hotbar-selector.scss new file mode 100644 index 0000000000..5467442eaa --- /dev/null +++ b/src/renderer/components/hotbar/hotbar-selector.scss @@ -0,0 +1,36 @@ +.HotbarSelector { + height: 26px; + background-color: var(--layoutBackground); + position: relative; + + &:before { + content: " "; + position: absolute; + width: 100%; + height: 20px; + background: linear-gradient(0deg, var(--clusterMenuBackground), transparent); + top: -20px; + } + + .Badge { + cursor: pointer; + background: var(--secondaryBackground); + width: 100%; + color: var(--settingsColor); + padding-top: 3px; + } + + .Icon { + --size: 16px; + padding: 0 4px; + + &:hover { + box-shadow: none; + background-color: transparent; + } + + &.previous { + transform: rotateY(180deg); + } + } +} \ No newline at end of file diff --git a/src/renderer/components/hotbar/hotbar-selector.tsx b/src/renderer/components/hotbar/hotbar-selector.tsx new file mode 100644 index 0000000000..6e4211e719 --- /dev/null +++ b/src/renderer/components/hotbar/hotbar-selector.tsx @@ -0,0 +1,34 @@ +import "./hotbar-selector.scss"; +import { Icon } from "../icon"; +import { Badge } from "../badge"; +import { Tooltip } from "@material-ui/core"; +import { Hotbar, HotbarStore } from "../../../common/hotbar-store"; +import { CommandOverlay } from "../command-palette"; +import { HotbarSwitchCommand } from "./hotbar-switch-command"; + +interface Props { + hotbar: Hotbar; +} + +const store = HotbarStore.getInstance(); + +export function HotbarSelector({ hotbar }: Props) { + const activeIndexDisplay = store.activeHotbarIndex + 1; + + return ( +
+ store.switchToPrevious()} /> +
+ + CommandOverlay.open()} + /> + +
+ store.switchToNext()} /> +
+ ); +}