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 custom user details example #4227

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 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
2ff572d
fix: Move `AccountDetails` into separate component and `slots`
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
a372cc5
Merge branch 'master' into enh/account-4
bharatkashyap Oct 18, 2024
c9d1fdb
Merge branch 'master' of github.com:mui/mui-toolpad into enh/account-4
bharatkashyap Oct 18, 2024
93853d2
fix: CI
bharatkashyap Oct 18, 2024
4315c01
Merge branch 'master' into enh/account-4
bharatkashyap Oct 21, 2024
7bf95b8
fix: Fix incorrect merge
bharatkashyap Oct 21, 2024
f2ef0b7
fix: CI
bharatkashyap Oct 21, 2024
c161742
fix: Add a test for `useSession`
bharatkashyap Oct 21, 2024
21c050d
Merge branch 'master' into enh/account-4
bharatkashyap Oct 22, 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
56 changes: 56 additions & 0 deletions docs/data/toolpad/core/components/UserOrg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from 'react';
import { Box, Stack, Typography, Avatar, Link, Divider } from '@mui/material';
import {
AccountPreview,
AccountPopoverFooter,
SignOutButton,
} from '@toolpad/core/Account';

import { useSession } from '@toolpad/core/useSession';

export function UserOrg() {
const session = useSession();
if (!session?.user) {
return <Typography>No user session available</Typography>;
}

const { logo: orgLogo, name: orgName, url: orgUrl } = session.org;

return (
<Stack>
<AccountPreview variant="expanded" />
{session.org && (
<Stack mb={1}>
<Typography textAlign="center" fontSize="0.625rem" gutterBottom>
This account is managed by
</Typography>
<Box display="flex" justifyContent="center" alignItems="center" gap={2}>
<Avatar
variant="square"
src={orgLogo}
alt={orgName}
sx={{ width: 27, height: 24 }}
/>
<Stack>
<Typography variant="caption" fontWeight="bolder">
{orgName}
</Typography>
<Link
variant="caption"
href={orgUrl}
target="_blank"
rel="noopener noreferrer"
>
{orgUrl}
</Link>
</Stack>
</Box>
</Stack>
)}
<Divider />
<AccountPopoverFooter>
<SignOutButton />
</AccountPopoverFooter>
</Stack>
);
}
64 changes: 64 additions & 0 deletions docs/data/toolpad/core/components/UserOrg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from 'react';
import { Box, Stack, Typography, Avatar, Link, Divider } from '@mui/material';
import {
AccountPreview,
AccountPopoverFooter,
SignOutButton,
} from '@toolpad/core/Account';
import { Session } from '@toolpad/core/AppProvider';
import { useSession } from '@toolpad/core/useSession';

export interface CustomSession extends Session {
org: {
name: string;
url: string;
logo: string;
};
}

export function UserOrg() {
const session = useSession<CustomSession>();
if (!session?.user) {
return <Typography>No user session available</Typography>;
}

const { logo: orgLogo, name: orgName, url: orgUrl } = session.org;

return (
<Stack>
<AccountPreview variant="expanded" />
{session.org && (
<Stack mb={1}>
<Typography textAlign="center" fontSize="0.625rem" gutterBottom>
This account is managed by
</Typography>
<Box display="flex" justifyContent="center" alignItems="center" gap={2}>
<Avatar
variant="square"
src={orgLogo}
alt={orgName}
sx={{ width: 27, height: 24 }}
/>
<Stack>
<Typography variant="caption" fontWeight="bolder">
{orgName}
</Typography>
<Link
variant="caption"
href={orgUrl}
target="_blank"
rel="noopener noreferrer"
>
{orgUrl}
</Link>
</Stack>
</Box>
</Stack>
)}
<Divider />
<AccountPopoverFooter>
<SignOutButton />
</AccountPopoverFooter>
</Stack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as React from 'react';
import { Account } from '@toolpad/core/Account';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { UserOrg } from '../UserOrg';

const demoSession = {
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
org: {
name: 'MUI Inc.',
url: 'https://mui.com',
logo: 'https://mui.com/static/logo.svg',
},
};

export default function AccountCustomUserDetails() {
const [customSession, setCustomSession] = React.useState(demoSession);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setCustomSession(demoSession);
},
signOut: () => {
setCustomSession(null);
},
};
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { Account } from '@toolpad/core/Account';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { UserOrg, CustomSession } from '../UserOrg';

const demoSession: CustomSession = {
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
org: {
name: 'MUI Inc.',
url: 'https://mui.com',
logo: 'https://mui.com/static/logo.svg',
},
};

export default function AccountCustomUserDetails() {
const [customSession, setCustomSession] = React.useState<CustomSession | null>(
demoSession,
);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setCustomSession(demoSession);
},
signOut: () => {
setCustomSession(null);
},
};
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Account
slots={{
popoverContent: UserOrg,
}}
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Account
localeText={{
signInLabel: 'Login',
signOutLabel: 'Logout',
}}
/>
126 changes: 126 additions & 0 deletions docs/data/toolpad/core/components/account/AccountSlotsWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import * as React from 'react';
import {
Avatar,
Button,
Divider,
Typography,
Stack,
IconButton,
} from '@mui/material';
import WalletIcon from '@mui/icons-material/AccountBalance';
import SendIcon from '@mui/icons-material/Send';
import ShoppingCart from '@mui/icons-material/ShoppingCart';
import CopyIcon from '@mui/icons-material/ContentCopy';

import {
Account,
AccountPreview,
AccountPopoverFooter,
SignOutButton,
} from '@toolpad/core/Account';

import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';

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

const mockData = {
address: '0xb794f5ea0ba39494ce839613fffba74279579268',
balance: '1,234.56 ETH',
usdBalance: '$2,345,678.90 USD',
};

function CryptoWalletInfo() {
return (
<Stack direction="column">
<AccountPreview variant="expanded" />
<Divider />
<Stack spacing={2} sx={{ width: 320, p: 2 }}>
<Stack direction="row" spacing={2} alignItems="center">
<Avatar sx={{ bgcolor: 'primary.main' }}>
<WalletIcon />
</Avatar>
<Stack sx={{ flexGrow: 1, minWidth: 0 }}>
<Typography
variant="subtitle1"
fontWeight="bold"
sx={{
display: 'flex',
alignItems: 'center',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
{mockData.address}
</span>
<IconButton size="small" sx={{ ml: 1 }}>
<CopyIcon fontSize="small" />
</IconButton>
</Typography>
<Typography variant="body2" color="text.secondary">
Main Account
</Typography>
</Stack>
</Stack>
<Divider />
<Stack>
<Typography variant="h6" fontWeight="bold">
{mockData.balance}
</Typography>
<Typography variant="body2" color="text.secondary">
{mockData.usdBalance}
</Typography>
</Stack>
</Stack>
<Divider />
<AccountPopoverFooter sx={{ gap: 2, px: 2, justifyContent: 'center' }}>
<Button
variant="contained"
disableElevation
size="small"
color="primary"
startIcon={<SendIcon />}
>
Send
</Button>
<Button variant="outlined" disableElevation startIcon={<ShoppingCart />}>
Buy
</Button>
<SignOutButton color="info" sx={{ textTransform: 'uppercase' }} />
</AccountPopoverFooter>
</Stack>
);
}

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

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account
slots={{
popoverContent: CryptoWalletInfo,
}}
/>
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
Loading
Loading