-
-
Notifications
You must be signed in to change notification settings - Fork 263
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] Export AccountUserDetails
component
#4227
Open
bharatkashyap
wants to merge
14
commits into
mui:master
Choose a base branch
from
bharatkashyap:enh/account-4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
38ecc17
fix: Improve docs and make API clearer
bharatkashyap 7fea561
Merge branch 'master' into enh/account-3
bharatkashyap 01c7fa6
fix: lint
bharatkashyap 49d756a
Merge branch 'enh/account-3' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap 8098608
fix: Incorrect default
bharatkashyap 6c1c073
fix: Add `userDetailsContainer` proposal
bharatkashyap f5edc05
Merge branch 'master' into enh/account-3
bharatkashyap 43a0978
fix: No default `sx` in the slot
bharatkashyap 7277cbf
fix: CI
bharatkashyap 129b679
Merge branch 'enh/account-3' of github.com:bharatkashyap/mui-toolpad …
bharatkashyap f909067
fix: Readability
bharatkashyap e337ac0
fix: typo
bharatkashyap 2e321ba
fix: More clarification
bharatkashyap 882b07b
Merge branch 'master' into enh/account-4
bharatkashyap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 23 additions & 9 deletions
32
docs/data/toolpad/core/components/account/AccountCustom.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
<Account | ||
localeText={{ | ||
signInLabel: 'Login', | ||
signOutLabel: 'Logout', | ||
}} | ||
slotProps={{ | ||
signInButton: { | ||
userDetailsContainer: { | ||
sx: { | ||
p: 2, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
gap: 2, | ||
'& .MuiStack-root': { | ||
color: theme.palette.grey[700], | ||
}, | ||
'& .MuiAvatar-root': { | ||
border: `2px solid ${theme.palette.primary.contrastText}`, | ||
boxShadow: theme.shadows[3], | ||
}, | ||
}, | ||
}, | ||
signOutButton: { | ||
color: 'info', | ||
variant: 'outlined', | ||
sx: { | ||
margin: 'auto', | ||
color: 'primaryDark', | ||
textTransform: 'capitalize', | ||
fontFamily: 'Inter', | ||
fontSize: '1em', | ||
height: 'fit-content', | ||
maxHeight: 'max-content', | ||
}, | ||
}, | ||
signOutButton: { color: 'primary', variant: 'outlined' }, | ||
iconButton: { | ||
sx: { | ||
width: 'fit-content', | ||
margin: 'auto', | ||
}, | ||
}, | ||
}} | ||
/> |
113 changes: 113 additions & 0 deletions
113
docs/data/toolpad/core/components/account/AccountCustomUserDetails.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Box, Stack, Typography, Avatar, Link } from '@mui/material'; | ||
import { Account, AuthenticationContext, SessionContext } from '@toolpad/core'; | ||
|
||
const demoSession = { | ||
user: { | ||
name: 'Bharat Kashyap', | ||
email: 'bharat@mui.com', | ||
image: 'https://avatars.githubusercontent.com/u/19550456', | ||
}, | ||
org: { | ||
name: 'MUI Inc.', | ||
url: 'https://mui.com', | ||
logo: 'https://mui.com/static/logo.svg', | ||
}, | ||
}; | ||
|
||
function UserDetailsContainer({ session }) { | ||
if (!session?.user) { | ||
return <Typography>No user session available</Typography>; | ||
} | ||
const { name, email, image } = session.user; | ||
const { logo: orgLogo, name: orgName, url: orgUrl } = session.org; | ||
|
||
return ( | ||
<Box sx={{ p: 2 }}> | ||
<Stack> | ||
<Stack flexDirection="row" gap={2} justifyContent="flex-start" mb={2}> | ||
<Avatar src={image ?? ''} alt={name ?? ''} /> | ||
<Stack> | ||
<Typography fontWeight="bolder">{name}</Typography> | ||
<Typography variant="caption" color="text.secondary"> | ||
{email} | ||
</Typography> | ||
</Stack> | ||
</Stack> | ||
{session.org && ( | ||
<Stack> | ||
<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> | ||
)} | ||
</Stack> | ||
</Box> | ||
); | ||
} | ||
|
||
UserDetailsContainer.propTypes = { | ||
session: PropTypes.shape({ | ||
org: PropTypes.shape({ | ||
logo: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
}).isRequired, | ||
user: PropTypes.shape({ | ||
email: PropTypes.string, | ||
id: PropTypes.string, | ||
image: PropTypes.string, | ||
name: PropTypes.string, | ||
}), | ||
}).isRequired, | ||
}; | ||
|
||
export default function AccountCustomUserDetails() { | ||
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}> | ||
{/* preview-start */} | ||
<Account | ||
slots={{ | ||
userDetailsContainer: UserDetailsContainer, | ||
}} | ||
/> | ||
{/* preview-end */} | ||
</SessionContext.Provider> | ||
</AuthenticationContext.Provider> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about calling it just
userDetails
?