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

[account] [docs] Add <Account /> in sidebarFooter #4255

Merged
merged 87 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
38ecc17
fix: Improve docs and make API clearer
bharatkashyap Oct 2, 2024
7fea561
Merge branch 'master' into enh/account-3
bharatkashyap Oct 2, 2024
01c7fa6
fix: lint
bharatkashyap Oct 2, 2024
49d756a
Merge branch 'enh/account-3' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap Oct 2, 2024
8098608
fix: Incorrect default
bharatkashyap Oct 2, 2024
6c1c073
fix: Add `userDetailsContainer` proposal
bharatkashyap Oct 3, 2024
f5edc05
Merge branch 'master' into enh/account-3
bharatkashyap Oct 3, 2024
43a0978
fix: No default `sx` in the slot
bharatkashyap Oct 3, 2024
7277cbf
fix: CI
bharatkashyap Oct 3, 2024
129b679
Merge branch 'enh/account-3' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap Oct 3, 2024
f909067
fix: Readability
bharatkashyap Oct 3, 2024
e337ac0
fix: typo
bharatkashyap Oct 3, 2024
2e321ba
fix: More clarification
bharatkashyap Oct 3, 2024
1086869
fix: CI
bharatkashyap Oct 3, 2024
7938e3f
fix: WIP `menuItems` -> `content`
bharatkashyap Oct 3, 2024
6807254
wip: Move demos over
bharatkashyap Oct 3, 2024
c2703a7
fix: Move demos to new API
bharatkashyap Oct 3, 2024
884ad56
wip: Better account switcher
bharatkashyap Oct 7, 2024
d76eebf
fix: CI
bharatkashyap Oct 7, 2024
840362c
Merge branch 'master' into enh/account-3
bharatkashyap Oct 7, 2024
c71f5ba
fix: Complete better account switcher
bharatkashyap Oct 7, 2024
6e34be8
fix: CI
bharatkashyap Oct 7, 2024
a80df48
fix: dedupe
bharatkashyap Oct 7, 2024
882b07b
Merge branch 'master' into enh/account-4
bharatkashyap Oct 7, 2024
0b2e4f8
Merge branch 'master' into enh/account-3
bharatkashyap Oct 7, 2024
77d8eb7
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-3
bharatkashyap Oct 8, 2024
cb9debf
fix: Redesign solution
bharatkashyap Oct 9, 2024
986298c
fix: CI
bharatkashyap Oct 9, 2024
eee948a
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-3
bharatkashyap Oct 9, 2024
b93270a
fix: CI
bharatkashyap Oct 9, 2024
cd6a2a0
fix: missed
bharatkashyap Oct 9, 2024
81e5304
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-3
bharatkashyap Oct 10, 2024
b94774f
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-3
bharatkashyap Oct 13, 2024
67b83fd
Merge branch 'enh/account-4' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap Oct 13, 2024
2dc6584
fix: Simplify docs
bharatkashyap Oct 13, 2024
cf1276f
fix: Add test
bharatkashyap Oct 13, 2024
cc743e5
fix: Rebase on `enh/account-3` and merge upstream
bharatkashyap Oct 13, 2024
28b71d5
Merge branch 'enh/account-3' into enh/account-4
bharatkashyap Oct 13, 2024
3c01cde
feat: Add `useSession`
bharatkashyap Oct 13, 2024
0aff5f9
fix: Move `Divider` out of `AccountDetails`
bharatkashyap Oct 13, 2024
0363c00
fix: Remove `Divider` from `AccountDetails`
bharatkashyap Oct 13, 2024
ce95f41
fix: Add `useSession` docs and examples
bharatkashyap Oct 13, 2024
83cd903
fix: CI
bharatkashyap Oct 13, 2024
96c760c
feat: Add `sidebar` variant to `Account`
bharatkashyap Oct 13, 2024
2ff572d
fix: Move `AccountDetails` into separate component and `slots`
bharatkashyap Oct 13, 2024
86fa603
Merge branch 'enh/account-3' into feat/account-sidebar-variant
bharatkashyap Oct 13, 2024
879f7a7
wip: AccountSidebarFooter
bharatkashyap Oct 13, 2024
868eb6e
fix: CI
bharatkashyap Oct 13, 2024
429b3dc
fix: Move to completely new component architecture
bharatkashyap Oct 17, 2024
ad12efc
Merge branch 'master' into enh/account-3
bharatkashyap Oct 17, 2024
5be7914
fix: CI
bharatkashyap Oct 17, 2024
637d637
fix: update test, CI
bharatkashyap Oct 17, 2024
a941719
Merge branch 'enh/account-3' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap Oct 17, 2024
bdc8e4f
fix: Pedro review
bharatkashyap Oct 17, 2024
a6b4ba9
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-3
bharatkashyap Oct 17, 2024
1c8523d
fix: Pedro review
bharatkashyap Oct 17, 2024
7334340
fix: missed
bharatkashyap Oct 17, 2024
73590d7
Merge branch 'enh/account-3' into enh/account-4
bharatkashyap Oct 18, 2024
07d48a8
fix: Accommodate new props
bharatkashyap Oct 18, 2024
4e7fdc8
fix: CI
bharatkashyap Oct 18, 2024
fcd1025
Merge branch 'enh/account-4' into feat/account-sidebar-variant
bharatkashyap Oct 18, 2024
86a84d9
wip: Add dashboard footer sidebar demo
bharatkashyap Oct 18, 2024
2a1d6d5
fix: CI
bharatkashyap Oct 18, 2024
d21ac77
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 18, 2024
6107c53
Merge branch 'master' of github.com:mui/mui-toolpad into feat/account…
bharatkashyap Oct 18, 2024
58f14d6
fix: CI
bharatkashyap Oct 18, 2024
3eead4a
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 21, 2024
4b5f4de
fix: Incorrect merge
bharatkashyap Oct 21, 2024
6f1499c
fix: CI
bharatkashyap Oct 21, 2024
ef3f403
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 22, 2024
d8fa6be
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 29, 2024
8603a43
fix: Fine tune demo
bharatkashyap Oct 29, 2024
fd826b3
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 30, 2024
7b86697
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Oct 30, 2024
299eb7f
Merge branch 'master' of github.com:mui/mui-toolpad into feat/account…
bharatkashyap Oct 30, 2024
81f6346
fix: CI
bharatkashyap Oct 31, 2024
2aa87b7
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Nov 1, 2024
64acd1d
fix: Pedro review
bharatkashyap Nov 1, 2024
5b21e45
Merge branch 'feat/account-sidebar-variant' of github.com:bharatkashy…
bharatkashyap Nov 1, 2024
01194bc
fix: Pedro review 2
bharatkashyap Nov 2, 2024
45f0499
fix: CI
bharatkashyap Nov 2, 2024
cbe1024
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Nov 2, 2024
d64ffae
fix: CI
bharatkashyap Nov 2, 2024
c7949d3
Merge branch 'feat/account-sidebar-variant' of github.com:bharatkashy…
bharatkashyap Nov 2, 2024
f9a5297
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Nov 2, 2024
7dd2eb3
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Nov 3, 2024
1615ae1
Merge branch 'master' into feat/account-sidebar-variant
bharatkashyap Nov 5, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import * as React from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2024-10-31 at 19 00 07

The 3 dots icon doesn't seem vertically centered.

Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2024-10-31 at 19 00 17

Also the popover isn't pointing to / coming from the 3 dots icon, I guess it should?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, I've tweaked the demo to reflect this in both states:

SidebarFooterAccountMini

SidebarFooterAccount

Copy link

Choose a reason for hiding this comment

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

For the expanded variant, could there be an option to choose whether the popup appears on the right or the top side?

Copy link
Member Author

@bharatkashyap bharatkashyap Nov 1, 2024

Choose a reason for hiding this comment

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

You should be able to customize the popover's position (as well as the placement of the arrow) using the slotProps - the demo on the docs will showcase this using the transformOrigin and anchorOrigin props

import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Stack from '@mui/material/Stack';
import MenuList from '@mui/material/MenuList';
import MenuItem from '@mui/material/MenuItem';
import ListItemText from '@mui/material/ListItemText';
import ListItemIcon from '@mui/material/ListItemIcon';
import Avatar from '@mui/material/Avatar';
import Divider from '@mui/material/Divider';
import { createTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import {
Account,
AccountPreview,
AccountPopoverFooter,
SignOutButton,
} from '@toolpad/core/Account';

const NAVIGATION = [
{
kind: 'header',
title: 'Main items',
},
{
segment: 'dashboard',
title: 'Dashboard',
icon: <DashboardIcon />,
},
{
segment: 'orders',
title: 'Orders',
icon: <ShoppingCartIcon />,
},
];

const demoTheme = createTheme({
cssVariables: {
colorSchemeSelector: 'data-toolpad-color-scheme',
},
colorSchemes: { light: true, dark: true },
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 AccountSidebarPreview(props) {
const { handleClick, open } = props;
return (
<Stack direction="column">
<Divider />
<AccountPreview variant="expanded" handleClick={handleClick} open={open} />
</Stack>
);
}

AccountSidebarPreview.propTypes = {
/**
* The handler used when the preview is expanded
*/
handleClick: PropTypes.func,
/**
* The state of the Account popover
* @default false
*/
open: PropTypes.bool,
};

const accounts = [
{
id: 1,
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
projects: [
{
id: 3,
title: 'Project X',
},
],
},
{
id: 2,
name: 'Bharat MUI',
email: '[email protected]',
color: '#8B4513', // Brown color
projects: [{ id: 4, title: 'Project A' }],
},
];

function SidebarFooterAccountPopover() {
return (
<Stack direction="column">
<Typography variant="body2" mx={2} mt={1}>
Accounts
</Typography>
<MenuList>
{accounts.map((account) => (
<MenuItem
key={account.id}
component="button"
sx={{
justifyContent: 'flex-start',
width: '100%',
columnGap: 2,
}}
>
<ListItemIcon>
<Avatar
sx={{
width: 32,
height: 32,
fontSize: '0.95rem',
bgcolor: account.color,
}}
src={account.image ?? ''}
alt={account.name ?? ''}
>
{account.name[0]}
</Avatar>
</ListItemIcon>
<ListItemText
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
width: '100%',
}}
primary={account.name}
secondary={account.email}
primaryTypographyProps={{ variant: 'body2' }}
secondaryTypographyProps={{ variant: 'caption' }}
/>
</MenuItem>
))}
</MenuList>
<AccountPopoverFooter>
<SignOutButton />
</AccountPopoverFooter>
</Stack>
);
}

function SidebarFooterAccount() {
Copy link
Member

Choose a reason for hiding this comment

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

This needs some logic to handle the mini-drawer variant, not to overflow.
The mini prop should always be available in this slot, it's just a boolean.

Copy link
Member Author

Choose a reason for hiding this comment

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

Missed that! I've modified the demo to be able to handle the mini state

return (
<Account
slots={{
preview: AccountSidebarPreview,
popoverContent: SidebarFooterAccountPopover,
Copy link
Member

Choose a reason for hiding this comment

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

In these docs demos, opening and closing the popover automatically scrolls unless they have the disableAutoFocus prop, maybe we could have that somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great find! I've added disableAutoFocus as true by default on the Account popover, but overridable by users through the slotProps

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I'm not 100% sure if we'd need it in a normal app though, maybe it's just a problem in the demo iframes.

}}
/>
);
}

const demoSession = {
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
};

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

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;

const [session, setSession] = React.useState(demoSession);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession(demoSession);
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AppProvider
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
authentication={authentication}
session={session}
>
<DashboardLayout
slots={{ toolbarAccount: () => null, sidebarFooter: SidebarFooterAccount }}
>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
);
}

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

export default DashboardLayoutAccountSidebar;
Loading
Loading