Layout Configurable Layout
src / Demo.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import React, { ReactElement, useState } from "react";
import {
DEFAULT_DESKTOP_LAYOUT,
DEFAULT_LANDSCAPE_TABLET_LAYOUT,
DEFAULT_PHONE_LAYOUT,
DEFAULT_TABLET_LAYOUT,
Layout,
LayoutNavigationTree,
SupportedPhoneLayout,
SupportedTabletLayout,
SupportedWideLayout,
useLayoutNavigation,
} from "@react-md/layout";
import {
HomeSVGIcon,
SecuritySVGIcon,
SettingsSVGIcon,
ShareSVGIcon,
SnoozeSVGIcon,
StarSVGIcon,
StorageSVGIcon,
} from "@react-md/material-icons";
import { ConfigurationForm } from "./ConfigurationForm";
import { CurrentChildren } from "./CurrentChildren";
const navItems: LayoutNavigationTree = {
"/": {
itemId: "/",
parentId: null,
children: "Home",
leftAddon: <HomeSVGIcon />,
},
"/route-1": {
itemId: "/route-1",
parentId: null,
children: "Route 1",
leftAddon: <StarSVGIcon />,
},
"/divider-1": {
itemId: "/divider-1",
parentId: null,
divider: true,
isCustom: true,
},
"/route-2": {
itemId: "/route-2",
parentId: null,
children: "Route 2",
leftAddon: <ShareSVGIcon />,
},
"/route-2-1": {
itemId: "/route-2-1",
parentId: "/route-2",
children: "Route 2-1",
leftAddon: <SettingsSVGIcon />,
},
"/route-2-2": {
itemId: "/route-2-2",
parentId: "/route-2",
children: "Route 2-2",
leftAddon: <StorageSVGIcon />,
},
"/route-2-3": {
itemId: "/route-2-3",
parentId: "/route-2",
children: "Route 2-3",
leftAddon: <SecuritySVGIcon />,
},
"/route-3": {
itemId: "/route-3",
parentId: null,
children: "Route 3",
leftAddon: <SnoozeSVGIcon />,
},
"/route-4": {
itemId: "/route-4",
parentId: null,
children: "Route 4",
},
};
export default function Demo(): ReactElement {
const [phoneLayout, setPhoneLayout] =
useState<SupportedPhoneLayout>(DEFAULT_PHONE_LAYOUT);
const [tabletLayout, setTabletLayout] = useState<SupportedTabletLayout>(
DEFAULT_TABLET_LAYOUT
);
const [landscapeTabletLayout, setLandscapeTabletLayout] =
useState<SupportedTabletLayout>(DEFAULT_LANDSCAPE_TABLET_LAYOUT);
const [desktopLayout, setDesktopLayout] = useState<SupportedWideLayout>(
DEFAULT_DESKTOP_LAYOUT
);
const [largeDesktopLayout, setLargeDesktopLayout] =
useState<SupportedWideLayout>(DEFAULT_DESKTOP_LAYOUT);
const [selectedId, setSelectedId] = useState("/");
return (
<Layout
id="configurable-layout"
title="Configurable Layout Title"
navHeaderTitle="Another Title"
phoneLayout={phoneLayout}
tabletLayout={tabletLayout}
landscapeTabletLayout={landscapeTabletLayout}
desktopLayout={desktopLayout}
treeProps={{
...useLayoutNavigation(navItems, selectedId),
onItemSelect: setSelectedId,
}}
mainProps={{ component: "div" }}
>
<CurrentChildren route={selectedId} />
<ConfigurationForm
phoneLayout={phoneLayout}
setPhoneLayout={setPhoneLayout}
tabletLayout={tabletLayout}
setTabletLayout={setTabletLayout}
landscapeTabletLayout={landscapeTabletLayout}
setLandscapeTabletLayout={setLandscapeTabletLayout}
desktopLayout={desktopLayout}
setDesktopLayout={setDesktopLayout}
largeDesktopLayout={largeDesktopLayout}
setLargeDesktopLayout={setLargeDesktopLayout}
/>
</Layout>
);
}