* refactor: 🔧 del unnecessary children type Change-Id: I3dea5e07f5401bdbdd168eb959fe361c57784167 * feat: 💄 eslint Change-Id: Ie173adeca9e3112d8cdfc1f85964332105dcb424 * feat: 🔧 add css type Change-Id: I8850c4d09b152f4d9c4d98e6eebca58bd9eecd37 * fix: 💄 ci lint Change-Id: I69ff89c7a30e2bdcd26475ec83f3f5ec143121b6
103 lines
2.6 KiB
TypeScript
103 lines
2.6 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { Helmet } from "react-helmet";
|
|
import styled from "styled-components";
|
|
import breakpoint from "styled-components-breakpoint";
|
|
import Flex from "~/components/Flex";
|
|
import { LoadingIndicatorBar } from "~/components/LoadingIndicator";
|
|
import SkipNavContent from "~/components/SkipNavContent";
|
|
import SkipNavLink from "~/components/SkipNavLink";
|
|
import useKeyDown from "~/hooks/useKeyDown";
|
|
import { MenuProvider } from "~/hooks/useMenuContext";
|
|
import useStores from "~/hooks/useStores";
|
|
import { isModKey } from "~/utils/keyboard";
|
|
|
|
type Props = {
|
|
title?: string;
|
|
sidebar?: React.ReactNode;
|
|
rightRail?: React.ReactNode;
|
|
};
|
|
|
|
const Layout: React.FC<Props> = ({ title, children, sidebar, rightRail }) => {
|
|
const { ui } = useStores();
|
|
const sidebarCollapsed = !sidebar || ui.isEditing || ui.sidebarCollapsed;
|
|
|
|
useKeyDown(".", (event) => {
|
|
if (isModKey(event)) {
|
|
ui.toggleCollapsedSidebar();
|
|
}
|
|
});
|
|
|
|
return (
|
|
<Container column auto>
|
|
<Helmet>
|
|
<title>{title ? title : "Outline"}</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
</Helmet>
|
|
|
|
<SkipNavLink />
|
|
|
|
{ui.progressBarVisible && <LoadingIndicatorBar />}
|
|
|
|
<Container auto>
|
|
<MenuProvider>{sidebar}</MenuProvider>
|
|
|
|
<SkipNavContent />
|
|
<Content
|
|
auto
|
|
justify="center"
|
|
$isResizing={ui.sidebarIsResizing}
|
|
$sidebarCollapsed={sidebarCollapsed}
|
|
$hasSidebar={!!sidebar}
|
|
style={
|
|
sidebarCollapsed
|
|
? undefined
|
|
: {
|
|
marginLeft: `${ui.sidebarWidth}px`,
|
|
}
|
|
}
|
|
>
|
|
{children}
|
|
</Content>
|
|
|
|
{rightRail}
|
|
</Container>
|
|
</Container>
|
|
);
|
|
};
|
|
|
|
const Container = styled(Flex)`
|
|
background: ${(props) => props.theme.background};
|
|
transition: ${(props) => props.theme.backgroundTransition};
|
|
position: relative;
|
|
width: 100%;
|
|
min-height: 100%;
|
|
`;
|
|
|
|
const Content = styled(Flex)<{
|
|
$isResizing?: boolean;
|
|
$sidebarCollapsed?: boolean;
|
|
$hasSidebar?: boolean;
|
|
}>`
|
|
margin: 0;
|
|
transition: ${(props) =>
|
|
props.$isResizing ? "none" : `margin-left 100ms ease-out`};
|
|
|
|
@media print {
|
|
margin: 0 !important;
|
|
}
|
|
|
|
${breakpoint("mobile", "tablet")`
|
|
margin-left: 0 !important;
|
|
`}
|
|
|
|
${breakpoint("tablet")`
|
|
${(props: any) =>
|
|
props.$hasSidebar &&
|
|
props.$sidebarCollapsed &&
|
|
`margin-left: ${props.theme.sidebarCollapsedWidth}px;`}
|
|
`};
|
|
`;
|
|
|
|
export default observer(Layout);
|