1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/layout/main-layout.tsx
Janne Savolainen 589472c2b5
Shorten license header to reduce amount of clutter in top of the files (#4709)
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-01-18 10:18:10 +02:00

84 lines
2.4 KiB
TypeScript
Executable File

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import styles from "./main-layout.module.scss";
import React from "react";
import { observer } from "mobx-react";
import { cssNames, StorageHelper } from "../../utils";
import { ErrorBoundary } from "../error-boundary";
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
import { withInjectables } from "@ogre-tools/injectable-react";
import sidebarStorageInjectable, {
defaultSidebarWidth,
SidebarStorageState,
} from "./sidebar-storage/sidebar-storage.injectable";
interface Props {
sidebar: React.ReactNode;
className?: string;
footer?: React.ReactNode;
}
/**
* Main layout is commonly used as a wrapper for "global pages"
*
* @link https://api-docs.k8slens.dev/master/extensions/capabilities/common-capabilities/#global-pages
*/
interface Dependencies {
sidebarStorage: StorageHelper<SidebarStorageState>
}
@observer
class NonInjectedMainLayout extends React.Component<Props & Dependencies> {
onSidebarResize = (width: number) => {
this.props.sidebarStorage.merge({ width });
};
render() {
const { className, footer, children, sidebar } = this.props;
const { width: sidebarWidth } = this.props.sidebarStorage.get();
const style = { "--sidebar-width": `${sidebarWidth}px` } as React.CSSProperties;
return (
<div className={cssNames(styles.mainLayout, className)} style={style}>
<div className={styles.sidebar}>
{sidebar}
<ResizingAnchor
direction={ResizeDirection.HORIZONTAL}
placement={ResizeSide.TRAILING}
growthDirection={ResizeGrowthDirection.LEFT_TO_RIGHT}
getCurrentExtent={() => sidebarWidth}
onDrag={this.onSidebarResize}
onDoubleClick={() => this.onSidebarResize(defaultSidebarWidth)}
minExtent={120}
maxExtent={400}
/>
</div>
<div className={styles.contents}>
<ErrorBoundary>{children}</ErrorBoundary>
</div>
<div className={styles.footer}>{footer}</div>
</div>
);
}
}
export const MainLayout = withInjectables<Dependencies, Props>(
NonInjectedMainLayout,
{
getProps: (di, props) => ({
sidebarStorage: di.inject(sidebarStorageInjectable),
...props,
}),
},
);