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

[core] Fix some DashboardLayout bugs and make some docs examples more consis… #3905

Merged
merged 12 commits into from
Aug 9, 2024
Next Next commit
Fix some DashboardLayout bugs and make some docs examples more consis…
…tent
  • Loading branch information
apedroferreira committed Aug 7, 2024
commit cd5ce4bee001f0851ff6356ddcc195a5cde549f0
88 changes: 84 additions & 4 deletions docs/data/toolpad/core/components/account/AccountWithDashboard.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import { AppProvider, DashboardLayout } from '@toolpad/core';
import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';

const NAVIGATION = [
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's adding all this boilerplate here too but this way it matches the other examples...

{
segment: 'dashboard',
title: 'Dashboard',
icon: <DashboardIcon />,
},
];

const demoTheme = extendTheme({
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 600,
lg: 1200,
xl: 1536,
},
},
});

function DemoPageContent({ pathname }) {
return (
<Box
sx={{
py: 4,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
}}
>
<Typography>Dashboard content for {pathname}</Typography>
</Box>
);
}

DemoPageContent.propTypes = {
pathname: PropTypes.string.isRequired,
};

function AccountWithDashboard(props) {
const { window } = props;

export default function AccountWithDashboard() {
const [session, setSession] = React.useState({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});

const authentication = React.useMemo(() => {
return {
signIn: () => {
Expand All @@ -27,11 +75,43 @@ export default function AccountWithDashboard() {
};
}, []);

const [pathname, setPathname] = React.useState('/dashboard');

const router = React.useMemo(() => {
return {
pathname,
searchParams: new URLSearchParams(),
navigate: (path) => setPathname(String(path)),
};
}, [pathname]);

// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

return (
<AppProvider session={session} authentication={authentication}>
// preview-start
<AppProvider
session={session}
authentication={authentication}
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
>
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
// preview-end
);
}

AccountWithDashboard.propTypes = {
/**
* Injected by the documentation to work in an iframe.
* Remove this when copying and pasting into your project.
*/
window: PropTypes.func,
};

export default AccountWithDashboard;
82 changes: 78 additions & 4 deletions docs/data/toolpad/core/components/account/AccountWithDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { Session, AppProvider, DashboardLayout } from '@toolpad/core';
import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Session, Router, Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
segment: 'dashboard',
title: 'Dashboard',
icon: <DashboardIcon />,
},
];

const demoTheme = extendTheme({
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 600,
lg: 1200,
xl: 1536,
},
},
});

function DemoPageContent({ pathname }: { pathname: string }) {
return (
<Box
sx={{
py: 4,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
}}
>
<Typography>Dashboard content for {pathname}</Typography>
</Box>
);
}

interface DemoProps {
/**
* Injected by the documentation to work in an iframe.
* Remove this when copying and pasting into your project.
*/
window?: () => Window;
}

export default function AccountWithDashboard(props: DemoProps) {
const { window } = props;

export default function AccountWithDashboard() {
const [session, setSession] = React.useState<Session | null>({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});

const authentication = React.useMemo(() => {
return {
signIn: () => {
Expand All @@ -27,11 +79,33 @@ export default function AccountWithDashboard() {
};
}, []);

const [pathname, setPathname] = React.useState('/dashboard');

const router = React.useMemo<Router>(() => {
return {
pathname,
searchParams: new URLSearchParams(),
navigate: (path) => setPathname(String(path)),
};
}, [pathname]);

// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

return (
<AppProvider session={session} authentication={authentication}>
// preview-start
<AppProvider
session={session}
authentication={authentication}
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
>
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
// preview-end
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
</DashboardLayout>
<AppProvider
session={session}
authentication={authentication}
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
>
<DashboardLayout>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import BarChartIcon from '@mui/icons-material/BarChart';
import DescriptionIcon from '@mui/icons-material/Description';
import LayersIcon from '@mui/icons-material/Layers';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation } from '@toolpad/core';
import type { Router, Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation } from '@toolpad/core';
import type { Navigation, Router } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import CallIcon from '@mui/icons-material/Call';
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
import CallMadeIcon from '@mui/icons-material/CallMade';
import CallReceivedIcon from '@mui/icons-material/CallReceived';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation } from '@toolpad/core';
import type { Navigation, Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DescriptionIcon from '@mui/icons-material/Description';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DescriptionIcon from '@mui/icons-material/Description';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DescriptionIcon from '@mui/icons-material/Description';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DescriptionIcon from '@mui/icons-material/Description';
import FolderIcon from '@mui/icons-material/Folder';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ The `DashboardLayout` comes integrated with the [`<Account />`](/toolpad/core/re
The use of an `iframe` may cause some spacing issues in the following demo.
:::

{{"demo": "../account/AccountWithDashboard.js", "iframe": true, "height": 320 }}
{{"demo": "../account/AccountWithDashboard.js", "height": 400, "iframe": true}}
3 changes: 2 additions & 1 deletion docs/data/toolpad/core/introduction/TutorialDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import { AppProvider, Navigation } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import { useDemoRouter } from '@toolpad/core/internals';
import type { Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/data/toolpad/core/introduction/TutorialPages.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Typography } from '@mui/material';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import TimelineIcon from '@mui/icons-material/Timeline';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { useDemoRouter } from '@toolpad/core/internals';
import { PageContainer } from '@toolpad/core/PageContainer';
import { Typography } from '@mui/material';

const NAVIGATION = [
{
Expand Down
5 changes: 3 additions & 2 deletions docs/data/toolpad/core/introduction/TutorialPages.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { Typography } from '@mui/material';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import TimelineIcon from '@mui/icons-material/Timeline';
import { AppProvider, Navigation } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { useDemoRouter } from '@toolpad/core/internals';
import { PageContainer } from '@toolpad/core/PageContainer';
import { Typography } from '@mui/material';
import type { Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
5 changes: 3 additions & 2 deletions docs/src/components/landing/ToolpadDashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import BarChartIcon from '@mui/icons-material/BarChart';
import DescriptionIcon from '@mui/icons-material/Description';
import LayersIcon from '@mui/icons-material/Layers';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer, type Navigation } from '@toolpad/core';
import { PageContainer } from '@toolpad/core/PageContainer';
import type { Navigation, Router } from '@toolpad/core';
import DemoSandbox from 'docs/src/modules/components/DemoSandbox';
import Grid from '@mui/material/Grid2';
import { styled } from '@mui/material';
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/landing/ToolpadPageContainerDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const PlaceHolder = styled('div')<{ height: number }>(({ theme, height }) => ({
borderRadius: theme.shape.borderRadius,
}));

function PageContainerDemp() {
function PageContainerDemo() {
const router = useDemoRouter('/orders');
const theme = useTheme();
const demoTheme = React.useMemo(
Expand Down Expand Up @@ -84,7 +84,7 @@ export default function ToolpadPageContainerDemo() {
onResetDemoClick={NOOP}
productId="toolpad-core"
>
<PageContainerDemp />
<PageContainerDemo />
</DemoSandbox>
</Paper>
</Frame.Demo>
Expand Down
Loading
Loading