Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <Menu> storybook is missing #7776

Merged
merged 6 commits into from
Jun 3, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 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,83 @@
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'];

export const MenuDefault = () => (
<Admin dataProvider={testDataProvider()} layout={StorybookLayoutDefault}>
{resources.map((resource, index) => {
return (
<Resource
name={resource}
key={`ressource_${index}`}
antoinefricker marked this conversation as resolved.
Show resolved Hide resolved
list={<StorybookList name={resource} />}
/>
);
})}
</Admin>
);
const StorybookLayoutDefault = props => (
antoinefricker marked this conversation as resolved.
Show resolved Hide resolved
<Layout {...props} menu={StorybookMenuDefault} appBar={StorybookAppBar} />
);
const StorybookMenuDefault = () => {
return <Menu hasDashboard={true} dense={false} />;
};

export const MenuDense = () => (
<Admin dataProvider={testDataProvider()} layout={StorybookLayoutDense}>
{resources.map((resource, index) => {
return (
<Resource
name={resource}
key={`ressource_${index}`}
list={<StorybookList name={resource} />}
/>
);
})}
</Admin>
);
const StorybookLayoutDense = props => (
<Layout {...props} menu={StorybookMenuDense} appBar={StorybookAppBar} />
);
const StorybookMenuDense = () => {
return <Menu hasDashboard={true} dense={true} />;
};

const StorybookAppBar = props => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you customize the AppBar in this Story

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to provide dark/default theme testing ability. Should I remove it?

const darkTheme = createTheme({
palette: { mode: 'dark' },
});
return (
<AppBar
{...props}
elevation={1}
sx={{ flexDirection: 'row', flexWrap: 'nowrap' }}
>
<SidebarToggleButton />
<Box sx={{ flex: '1 1 100%' }}>
<Typography variant="h6" id="react-admin-title" />
</Box>
<Box sx={{ flex: '0 0 auto' }}>
<ToggleThemeButton
lightTheme={defaultTheme}
darkTheme={darkTheme}
/>
</Box>
</AppBar>
);
};

const StorybookList = ({ name }) => (
antoinefricker marked this conversation as resolved.
Show resolved Hide resolved
<>
<Title title={name} />
<Typography variant="h4">{name}</Typography>
</>
);