Skip to content

Commit 9c0fcf7

Browse files
committed
wip: introduce Layout appBarAlwaysOn prop
1 parent c933ab5 commit 9c0fcf7

3 files changed

Lines changed: 118 additions & 5 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import {
2+
Box,
3+
ListItemIcon,
4+
ListItemText,
5+
MenuItem,
6+
MenuList,
7+
Skeleton,
8+
ThemeProvider,
9+
createTheme,
10+
} from '@mui/material';
11+
import DashboardIcon from '@mui/icons-material/Dashboard';
12+
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
13+
import PeopleIcon from '@mui/icons-material/People';
14+
import {
15+
AuthContext,
16+
PreferencesEditorContextProvider,
17+
StoreContextProvider,
18+
memoryStore,
19+
} from 'ra-core';
20+
import * as React from 'react';
21+
import { QueryClient, QueryClientProvider } from 'react-query';
22+
import { MemoryRouter } from 'react-router';
23+
24+
import { defaultTheme } from '../defaultTheme';
25+
import { AppBar } from './AppBar';
26+
import { Layout } from './Layout';
27+
import { Title } from './Title';
28+
29+
export default {
30+
title: 'ra-ui-materialui/layout/Layout',
31+
};
32+
33+
const Content = () => (
34+
<Box>
35+
<Skeleton
36+
variant="text"
37+
width="auto"
38+
sx={{ fontSize: '2rem', mx: 2 }}
39+
animation={false}
40+
/>
41+
<Skeleton
42+
variant="rectangular"
43+
width="auto"
44+
height={1500}
45+
sx={{ mx: 2 }}
46+
animation={false}
47+
/>
48+
</Box>
49+
);
50+
51+
const Wrapper = ({
52+
children = <Content />,
53+
theme = createTheme(defaultTheme),
54+
layout: LayoutProp = Layout,
55+
}) => (
56+
<MemoryRouter>
57+
<QueryClientProvider client={new QueryClient()}>
58+
<ThemeProvider theme={theme}>
59+
<StoreContextProvider value={memoryStore()}>
60+
<PreferencesEditorContextProvider>
61+
<AuthContext.Provider value={undefined as any}>
62+
<LayoutProp>
63+
{children}
64+
<Title title="React Admin" />
65+
</LayoutProp>
66+
</AuthContext.Provider>
67+
</PreferencesEditorContextProvider>
68+
</StoreContextProvider>
69+
</ThemeProvider>
70+
</QueryClientProvider>
71+
</MemoryRouter>
72+
);
73+
74+
const Menu = () => (
75+
<MenuList>
76+
<MenuItem>
77+
<ListItemIcon>
78+
<DashboardIcon />
79+
</ListItemIcon>
80+
<ListItemText>Dashboard</ListItemText>
81+
</MenuItem>
82+
<MenuItem>
83+
<ListItemIcon>
84+
<ShoppingCartIcon />
85+
</ListItemIcon>
86+
<ListItemText>Orders</ListItemText>
87+
</MenuItem>
88+
<MenuItem>
89+
<ListItemIcon>
90+
<PeopleIcon />
91+
</ListItemIcon>
92+
<ListItemText>Customers</ListItemText>
93+
</MenuItem>
94+
</MenuList>
95+
);
96+
const BasicLayout = props => <Layout menu={Menu} {...props} />;
97+
98+
export const Basic = () => <Wrapper layout={BasicLayout} />;
99+
100+
const AlwaysOnAppBar = () => <AppBar alwaysOn />;
101+
const AlwaysOnLayout = props => (
102+
<BasicLayout appBar={AlwaysOnAppBar} {...props} />
103+
);
104+
105+
export const AlwaysOn = () => <Wrapper layout={AlwaysOnLayout} />;
106+
107+
const AlwaysOnLayout2 = props => <BasicLayout appBarAlwaysOn {...props} />;
108+
109+
export const AlwaysOn2 = () => <Wrapper layout={AlwaysOnLayout2} />;

packages/ra-ui-materialui/src/layout/Layout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Inspector } from '../preferences';
2121
export const Layout = (props: LayoutProps) => {
2222
const {
2323
appBar: AppBar = DefaultAppBar,
24+
appBarAlwaysOn,
2425
children,
2526
className,
2627
dashboard,
@@ -42,9 +43,9 @@ export const Layout = (props: LayoutProps) => {
4243
<StyledLayout className={clsx('layout', className)} {...rest}>
4344
<SkipNavigationButton />
4445
<div className={LayoutClasses.appFrame}>
45-
<AppBar open={open} title={title} />
46+
<AppBar open={open} title={title} alwaysOn={appBarAlwaysOn} />
4647
<main className={LayoutClasses.contentWithSidebar}>
47-
<Sidebar>
48+
<Sidebar appBarAlwaysOn={appBarAlwaysOn}>
4849
<Menu hasDashboard={!!dashboard} />
4950
</Sidebar>
5051
<div id="main-content" className={LayoutClasses.content}>
@@ -74,6 +75,7 @@ export interface LayoutProps
7475
extends CoreLayoutProps,
7576
Omit<HtmlHTMLAttributes<HTMLDivElement>, 'title'> {
7677
appBar?: ComponentType<AppBarProps>;
78+
appBarAlwaysOn?: boolean;
7779
className?: string;
7880
error?: ComponentType<ErrorProps>;
7981
menu?: ComponentType<MenuProps>;

packages/ra-ui-materialui/src/layout/Sidebar.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useLocale } from 'ra-core';
1515
import { useSidebarState } from './useSidebarState';
1616

1717
export const Sidebar = (props: SidebarProps) => {
18-
const { children, closedSize, size, ...rest } = props;
18+
const { appBarAlwaysOn, children, closedSize, size, ...rest } = props;
1919
const isXSmall = useMediaQuery<Theme>(theme =>
2020
theme.breakpoints.down('sm')
2121
);
@@ -41,7 +41,9 @@ export const Sidebar = (props: SidebarProps) => {
4141
open={open}
4242
onClose={toggleSidebar}
4343
classes={SidebarClasses}
44-
className={trigger ? SidebarClasses.appBarCollapsed : ''}
44+
className={
45+
trigger && !appBarAlwaysOn ? SidebarClasses.appBarCollapsed : ''
46+
}
4547
{...rest}
4648
>
4749
<div className={SidebarClasses.fixed}>{children}</div>
@@ -54,9 +56,9 @@ Sidebar.propTypes = {
5456
};
5557

5658
export interface SidebarProps extends DrawerProps {
59+
appBarAlwaysOn?: boolean;
5760
children: ReactElement;
5861
closedSize?: number;
59-
6062
size?: number;
6163
}
6264

0 commit comments

Comments
 (0)