From 21bdc6ba8f94ee766878fd4bcecfd938fa2f2749 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 6 Oct 2020 13:33:23 -0400 Subject: [PATCH] add resizing capabilities to the side bar (#1009) * add resizing capabilities to the side bar Signed-off-by: Sebastian Malton --- .../components/layout/main-layout.scss | 6 +-- .../components/layout/main-layout.tsx | 40 +++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/renderer/components/layout/main-layout.scss b/src/renderer/components/layout/main-layout.scss index 3a02d36717..d423b0388f 100755 --- a/src/renderer/components/layout/main-layout.scss +++ b/src/renderer/components/layout/main-layout.scss @@ -1,6 +1,4 @@ .MainLayout { - --sidebar-max-size: 200px; - display: grid; grid-template-areas: "aside header" @@ -35,7 +33,7 @@ transition: width 150ms cubic-bezier(0.4, 0, 0.2, 1); &.pinned { - width: var(--sidebar-max-size); + width: var(--sidebar-width); } &:not(.pinned) { @@ -45,7 +43,7 @@ overflow: hidden; &.accessible:hover { - width: var(--sidebar-max-size); + width: var(--sidebar-width); transition-delay: 750ms; box-shadow: 3px 3px 16px rgba(0, 0, 0, 0.35); z-index: $zIndex-sidebar-hover; diff --git a/src/renderer/components/layout/main-layout.tsx b/src/renderer/components/layout/main-layout.tsx index 97f5727a2d..43c0c01670 100755 --- a/src/renderer/components/layout/main-layout.tsx +++ b/src/renderer/components/layout/main-layout.tsx @@ -3,11 +3,12 @@ import "./main-layout.scss"; import React from "react"; import { observable, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; -import { createStorage, cssNames } from "../../utils"; +import { autobind, createStorage, cssNames } from "../../utils"; import { Sidebar } from "./sidebar"; import { ErrorBoundary } from "../error-boundary"; import { Dock } from "../dock"; import { getHostedCluster } from "../../../common/cluster-store"; +import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor"; interface Props { className?: any; @@ -18,22 +19,42 @@ interface Props { @observer export class MainLayout extends React.Component { - public storage = createStorage("main_layout", { pinnedSidebar: true }); + public storage = createStorage("main_layout", { + pinnedSidebar: true, + sidebarWidth: 200, + }); @observable isPinned = this.storage.get().pinnedSidebar; @observable isAccessible = true; + @observable sidebarWidth = this.storage.get().sidebarWidth @disposeOnUnmount syncPinnedStateWithStorage = reaction( () => this.isPinned, (isPinned) => this.storage.merge({ pinnedSidebar: isPinned }) ); + @disposeOnUnmount syncWidthStateWithStorage = reaction( + () => this.sidebarWidth, + (sidebarWidth) => this.storage.merge({ sidebarWidth }) + ); + toggleSidebar = () => { this.isPinned = !this.isPinned; this.isAccessible = false; setTimeout(() => (this.isAccessible = true), 250); }; + getSidebarSize = () => { + return { + "--sidebar-width": `${this.sidebarWidth}px`, + } + } + + @autobind() + adjustWidth(newWidth: number): void { + this.sidebarWidth = newWidth + } + render() { const { className, headerClass, footer, footerClass, children } = this.props; const cluster = getHostedCluster(); @@ -41,20 +62,31 @@ export class MainLayout extends React.Component { return null; // fix: skip render when removing active (visible) cluster } return ( -
+
{cluster.preferences.clusterName || cluster.contextName}
{children}
-
{footer === undefined ? : footer}
+
); }