1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

add resizing capabilities to the side bar

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-10-01 11:18:56 -04:00
parent 14d3d88278
commit 995f11099d
2 changed files with 39 additions and 13 deletions

View File

@ -1,6 +1,4 @@
.MainLayout { .MainLayout {
--sidebar-max-size: 200px;
display: grid; display: grid;
grid-template-areas: grid-template-areas:
"aside header" "aside header"
@ -8,7 +6,7 @@
"aside main" "aside main"
"aside footer"; "aside footer";
grid-template-rows: [header] var(--main-layout-header) [tabs] min-content [main] 1fr [footer] auto; grid-template-rows: [header] var(--main-layout-header) [tabs] min-content [main] 1fr [footer] auto;
grid-template-columns: [sidebar] minmax(var(--main-layout-header), min-content) [main] 1fr; grid-template-columns: [sidebar] auto [main] 1fr;
height: 100%; height: 100%;
@ -33,19 +31,15 @@
background: $sidebarBackground; background: $sidebarBackground;
white-space: nowrap; white-space: nowrap;
transition: width 150ms cubic-bezier(0.4, 0, 0.2, 1); transition: width 150ms cubic-bezier(0.4, 0, 0.2, 1);
width: var(--sidebar-width);
&.pinned {
width: var(--sidebar-max-size);
}
&:not(.pinned) { &:not(.pinned) {
position: absolute;
width: var(--main-layout-header); width: var(--main-layout-header);
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
&.accessible:hover { &.accessible:hover {
width: var(--sidebar-max-size); width: max-content;
transition-delay: 750ms; transition-delay: 750ms;
box-shadow: 3px 3px 16px rgba(0, 0, 0, 0.35); box-shadow: 3px 3px 16px rgba(0, 0, 0, 0.35);
z-index: $zIndex-sidebar-hover; z-index: $zIndex-sidebar-hover;

View File

@ -3,11 +3,12 @@ import "./main-layout.scss";
import React from "react"; import React from "react";
import { observable, reaction } from "mobx"; import { observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { createStorage, cssNames } from "../../utils"; import { autobind, createStorage, cssNames } from "../../utils";
import { Sidebar } from "./sidebar"; import { Sidebar } from "./sidebar";
import { ErrorBoundary } from "../error-boundary"; import { ErrorBoundary } from "../error-boundary";
import { Dock } from "../dock"; import { Dock } from "../dock";
import { getHostedCluster } from "../../../common/cluster-store"; import { getHostedCluster } from "../../../common/cluster-store";
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
interface Props { interface Props {
className?: any; className?: any;
@ -18,22 +19,42 @@ interface Props {
@observer @observer
export class MainLayout extends React.Component<Props> { export class MainLayout extends React.Component<Props> {
public storage = createStorage("main_layout", { pinnedSidebar: true }); public storage = createStorage("main_layout", {
pinnedSidebar: true,
sidebarWidth: 200,
});
@observable isPinned = this.storage.get().pinnedSidebar; @observable isPinned = this.storage.get().pinnedSidebar;
@observable isAccessible = true; @observable isAccessible = true;
@observable sidebarWidth = this.storage.get().sidebarWidth
@disposeOnUnmount syncPinnedStateWithStorage = reaction( @disposeOnUnmount syncPinnedStateWithStorage = reaction(
() => this.isPinned, () => this.isPinned,
(isPinned) => this.storage.merge({ pinnedSidebar: isPinned }) (isPinned) => this.storage.merge({ pinnedSidebar: isPinned })
); );
@disposeOnUnmount syncWidthStateWithStorage = reaction(
() => this.sidebarWidth,
(sidebarWidth) => this.storage.merge({ sidebarWidth })
);
toggleSidebar = () => { toggleSidebar = () => {
this.isPinned = !this.isPinned; this.isPinned = !this.isPinned;
this.isAccessible = false; this.isAccessible = false;
setTimeout(() => (this.isAccessible = true), 250); setTimeout(() => (this.isAccessible = true), 250);
}; };
getSidebarSize = () => {
return {
"--sidebar-width": `${this.sidebarWidth}px`,
}
}
@autobind()
adjustWidth(newWidth: number): void {
this.sidebarWidth = newWidth
}
render() { render() {
const { className, headerClass, footer, footerClass, children } = this.props; const { className, headerClass, footer, footerClass, children } = this.props;
const cluster = getHostedCluster(); const cluster = getHostedCluster();
@ -41,20 +62,31 @@ export class MainLayout extends React.Component<Props> {
return null; // fix: skip render when removing active (visible) cluster return null; // fix: skip render when removing active (visible) cluster
} }
return ( return (
<div className={cssNames("MainLayout", className)}> <div className={cssNames("MainLayout", className)} style={this.getSidebarSize() as any}>
<header className={cssNames("flex gaps align-center", headerClass)}> <header className={cssNames("flex gaps align-center", headerClass)}>
<span className="cluster">{cluster.preferences.clusterName || cluster.contextName}</span> <span className="cluster">{cluster.preferences.clusterName || cluster.contextName}</span>
</header> </header>
<aside className={cssNames("flex column", { pinned: this.isPinned, accessible: this.isAccessible })}> <aside className={cssNames("flex column", { pinned: this.isPinned, accessible: this.isAccessible })}>
<Sidebar className="box grow" isPinned={this.isPinned} toggle={this.toggleSidebar} /> <Sidebar className="box grow" isPinned={this.isPinned} toggle={this.toggleSidebar} />
<ResizingAnchor
direction={ResizeDirection.HORIZONTAL}
placement={ResizeSide.TRAILING}
growthDirection={ResizeGrowthDirection.LEFT_TO_RIGHT}
getCurrentExtent={() => this.sidebarWidth}
onDrag={this.adjustWidth}
onDoubleClick={this.toggleSidebar}
disabled={!this.isPinned}
minExtent={100}
maxExtent={750}
/>
</aside> </aside>
<main> <main>
<ErrorBoundary>{children}</ErrorBoundary> <ErrorBoundary>{children}</ErrorBoundary>
</main> </main>
<footer className={footerClass}>{footer === undefined ? <Dock /> : footer}</footer> <footer className={footerClass}>{footer ?? <Dock />}</footer>
</div> </div>
); );
} }