Skip to content

Commit

Permalink
Merge pull request #7776 from marmelab/menu-storybook
Browse files Browse the repository at this point in the history
Add a storybook case for `Menu`
  • Loading branch information
fzaninotto committed Jun 3, 2022
2 parents 72265d4 + cce9edc commit e9a17f6
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions packages/ra-ui-materialui/src/layout/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';

import { Resource, testDataProvider } from 'ra-core';
import { defaultTheme, Admin } from 'react-admin';
import { AppBar, Typography, Box } from '@mui/material';
import { createTheme } from '@mui/material/styles';
import { ToggleThemeButton } from '../button';
import { Layout, Menu, SidebarToggleButton, Title } from '.';

export default { title: 'ra-ui-materialui/layout/Menu' };

const resources = ['Posts', 'Comments', 'Tags', 'Users', 'Orders', 'Reviews'];

const DemoAppBar = props => {
const darkTheme = createTheme({
palette: { mode: 'dark' },
});
return (
<AppBar
{...props}
elevation={1}
sx={{ flexDirection: 'row', flexWrap: 'nowrap' }}
>
<Box sx={{ flex: '1 1 100%' }}>
<SidebarToggleButton />
</Box>
<Box sx={{ flex: '0 0 auto' }}>
<ToggleThemeButton
lightTheme={defaultTheme}
darkTheme={darkTheme}
/>
</Box>
</AppBar>
);
};

const DemoList = ({ name }) => (
<>
<Title title={name} />
<Typography variant="h4">{name}</Typography>
</>
);

export const Default = () => {
const DefaultLayout = props => (
<Layout {...props} menu={MenuDefault} appBar={DemoAppBar} />
);
const MenuDefault = () => {
return <Menu hasDashboard={true} dense={false} />;
};

return (
<Admin dataProvider={testDataProvider()} layout={DefaultLayout}>
{resources.map((resource, index) => {
return (
<Resource
name={resource}
key={`resource_${index}`}
list={<DemoList name={resource} />}
/>
);
})}
</Admin>
);
};

export const Dense = () => {
const LayoutDense = props => (
<Layout {...props} menu={MenuDense} appBar={DemoAppBar} />
);
const MenuDense = props => {
return <Menu {...props} hasDashboard={true} dense={true} />;
};

return (
<Admin dataProvider={testDataProvider()} layout={LayoutDense}>
{resources.map((resource, index) => {
return (
<Resource
name={resource}
key={`resource_${index}`}
list={<DemoList name={resource} />}
/>
);
})}
</Admin>
);
};

0 comments on commit e9a17f6

Please sign in to comment.