From 996c597932222f0d2b56c748c318356c3e7ec7a4 Mon Sep 17 00:00:00 2001 From: Mikkel Laursen Date: Sun, 9 May 2021 18:56:13 -0600 Subject: [PATCH] fix(layout): non-fixed AppBar mini layouts Closes #1101 --- packages/layout/src/LayoutChildren.tsx | 87 +++++----- packages/layout/src/LayoutMain.tsx | 27 +++- packages/layout/src/LayoutNavigation.tsx | 27 +++- packages/layout/src/LayoutTree.tsx | 39 +++-- packages/layout/src/MiniLayoutWrapper.tsx | 149 ++++++++++++++++++ .../__tests__/__snapshots__/Layout.tsx.snap | 2 +- packages/layout/src/_mixins.scss | 22 ++- 7 files changed, 301 insertions(+), 52 deletions(-) create mode 100644 packages/layout/src/MiniLayoutWrapper.tsx diff --git a/packages/layout/src/LayoutChildren.tsx b/packages/layout/src/LayoutChildren.tsx index 0a5278a4a7..70d34c8a10 100644 --- a/packages/layout/src/LayoutChildren.tsx +++ b/packages/layout/src/LayoutChildren.tsx @@ -1,4 +1,10 @@ -import React, { ReactElement, ReactNode, useEffect, useState } from "react"; +import React, { + HTMLAttributes, + ReactElement, + ReactNode, + useEffect, + useState, +} from "react"; import { SkipToMainContent, SkipToMainContentProps } from "@react-md/link"; import { BaseTreeItem, TreeData } from "@react-md/tree"; import { PropsWithRef } from "@react-md/utils"; @@ -8,6 +14,7 @@ import { LayoutAppBar } from "./LayoutAppBar"; import { LayoutMain, LayoutMainProps } from "./LayoutMain"; import { LayoutNavigation } from "./LayoutNavigation"; import { useLayoutConfig } from "./LayoutProvider"; +import { MiniLayoutWrapper } from "./MiniLayoutWrapper"; import { LayoutNavigationItem } from "./types"; import { isMiniLayout } from "./utils"; @@ -60,6 +67,23 @@ export interface LayoutChildrenProps< */ miniNavItems?: TreeData; + /** + * This prop allows you to provide additional props to the `
` surrounding + * the `LayoutMain` and mini `LayoutNavigation` components. + * + * Note: This additional `
` will only be rendered if: + * - the current layout is one of the `mini` types + * - the layout is not using a fixed app bar + * - the `miniNav` prop has not been defined + * - `treeProps` have been provided + * + * @remarks \@since 2.8.3 + */ + miniWrapperProps?: PropsWithRef< + HTMLAttributes, + HTMLDivElement + >; + /** * The children to display within the layout. This is pretty much required * since you'll have an empty app otherwise, but it's left as optional just @@ -88,8 +112,9 @@ export function LayoutChildren({ navToggleProps, navAfterAppBar = false, nav: propNav, - miniNav: propMiniNav, + miniNav, miniNavItems, + miniWrapperProps, navHeader, navHeaderProps, navHeaderTitle, @@ -152,48 +177,38 @@ export function LayoutChildren({ ); } - let miniNav = propMiniNav; - if (mini && treeProps && typeof miniNav === "undefined") { - let miniTreeProps = treeProps; - if (miniNavItems) { - miniTreeProps = { - ...miniTreeProps, - navItems: miniNavItems, - }; - } - - miniNav = ( -