-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added top and bottom to mui list page
- Loading branch information
Tarik Huber
committed
May 9, 2023
1 parent
4d8dbab
commit aef7bff
Showing
5 changed files
with
220 additions
and
3 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
211 changes: 211 additions & 0 deletions
211
packages/material-ui-shell/src/components/MenuHeader/MenuHeader.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,211 @@ | ||
import React from 'react' | ||
import { useAuth } from 'base-shell/lib/providers/Auth' | ||
import { useMenu } from '../../providers/Menu' | ||
import { useTheme as useAppTheme } from '../../providers/Theme' | ||
import { | ||
Avatar, | ||
IconButton, | ||
List, | ||
ListItem, | ||
ListItemAvatar, | ||
ListItemSecondaryAction, | ||
ListItemText, | ||
Paper, | ||
} from '@mui/material' | ||
import { | ||
ChevronLeft, | ||
ChevronRight, | ||
ChromeReaderMode, | ||
Person as PersonIcon, | ||
ArrowDropDown as ArrowDropDownIcon, | ||
ArrowDropUp as ArrowDropUpIcon, | ||
Brightness4 as Brightness4Icon, | ||
BrightnessHigh as BrightnessHighIcon, | ||
} from '@mui/icons-material' | ||
import { useTheme } from '@mui/material/styles' | ||
|
||
const MenuHeader = () => { | ||
const { auth } = useAuth() | ||
const { toggleThisTheme, isDarkMode, isRTL } = useAppTheme() | ||
const menuContext = useMenu() | ||
const theme = useTheme() | ||
const authData = auth | ||
const { | ||
toggleThis, | ||
isDesktop, | ||
isMiniMode, | ||
isMenuOpen, | ||
isMiniSwitchVisibility, | ||
isAuthMenuOpen, | ||
} = menuContext || {} | ||
|
||
const isAuthenticated = auth.isAuthenticated | ||
const AvatarConstructor = ({ src, alt, avatar }) => { | ||
return ( | ||
<ListItemAvatar onClick={() => toggleThis('isAuthMenuOpen')}> | ||
<Avatar src={src} alt={alt}> | ||
{avatar} | ||
</Avatar> | ||
</ListItemAvatar> | ||
) | ||
} | ||
|
||
const styles = { | ||
icon: { | ||
color: theme.palette.grey.A100, | ||
cursor: 'pointer', | ||
}, | ||
toolbar: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'flex-end', | ||
padding: theme.spacing(1), | ||
// necessary for content to be below app bar | ||
...theme.mixins.toolbar, | ||
}, | ||
} | ||
|
||
return ( | ||
<Paper | ||
square={true} | ||
elevation={3} | ||
sx={{ | ||
backgroundColor: (t) => | ||
t.palette.mode === 'dark' | ||
? t.palette.background.default | ||
: t.palette.primary.dark, | ||
margin: 0, | ||
padding: 0, | ||
}} | ||
> | ||
{isMiniMode && isAuthenticated && ( | ||
<div style={{ ...styles.toolbar }}></div> | ||
)} | ||
<List sx={{ ...(!isAuthenticated ? styles.toolbar : {}) }}> | ||
{!isMiniMode && ( | ||
<ListItem | ||
sx={{ | ||
color: (t) => theme.palette.grey.A100, | ||
cursor: 'pointer', | ||
...theme.mixins.toolbar, | ||
}} | ||
> | ||
{isAuthenticated && | ||
(authData.photoURL | ||
? AvatarConstructor({ | ||
src: authData.photoURL, | ||
alt: 'user', | ||
}) | ||
: AvatarConstructor({ | ||
avatar: authData.displayName ? ( | ||
authData.displayName[0].toUpperCase() | ||
) : ( | ||
<PersonIcon /> | ||
), | ||
}))} | ||
<ListItemSecondaryAction> | ||
<IconButton | ||
onClick={() => { | ||
toggleThisTheme('isDarkMode') | ||
}} | ||
> | ||
{isDarkMode ? ( | ||
<BrightnessHighIcon sx={{ ...styles.icon }} /> | ||
) : ( | ||
<Brightness4Icon sx={{ ...styles.icon }} /> | ||
)} | ||
</IconButton> | ||
{isDesktop && ( | ||
<> | ||
{isMiniSwitchVisibility && ( | ||
<IconButton | ||
onClick={() => { | ||
toggleThis('isMiniMode', true) | ||
toggleThis('isMenuOpen', false) | ||
}} | ||
> | ||
<ChromeReaderMode sx={{ ...styles.icon }} /> | ||
</IconButton> | ||
)} | ||
<IconButton | ||
color="inherit" | ||
onClick={() => { | ||
toggleThis('isMenuOpen', false) | ||
}} | ||
> | ||
{isRTL ? ( | ||
<ChevronRight sx={{ ...styles.icon }} /> | ||
) : ( | ||
<ChevronLeft sx={{ ...styles.icon }} /> | ||
)} | ||
</IconButton>{' '} | ||
</> | ||
)} | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
)} | ||
|
||
{isAuthenticated && ( | ||
<ListItem | ||
onClick={() => { | ||
toggleThis('isAuthMenuOpen') | ||
}} | ||
> | ||
{!isMenuOpen && | ||
isMiniMode && | ||
isDesktop && | ||
(authData.photoURL | ||
? AvatarConstructor({ | ||
src: authData.photoURL, | ||
alt: 'user', | ||
}) | ||
: AvatarConstructor({ | ||
avatar: authData.displayName ? ( | ||
authData.displayName[0].toUpperCase() | ||
) : ( | ||
<PersonIcon /> | ||
), | ||
}))} | ||
{!isMiniMode && ( | ||
<ListItemText | ||
sx={{ | ||
color: (t) => theme.palette.grey.A100, | ||
cursor: 'pointer', | ||
marginLeft: | ||
!isMenuOpen && isDesktop && authData.photoURL | ||
? 7 | ||
: undefined, | ||
textOverflow: 'ellipsis', | ||
}} | ||
secondaryTypographyProps={{ | ||
color: (t) => theme.palette.grey.A100, | ||
width: 80, | ||
textOverflow: 'ellipsis', | ||
}} | ||
primary={authData.displayName} | ||
secondary={authData.email} | ||
/> | ||
)} | ||
{isMenuOpen && ( | ||
<ListItemSecondaryAction | ||
onClick={() => { | ||
toggleThis('isAuthMenuOpen') | ||
}} | ||
> | ||
<IconButton> | ||
{isAuthMenuOpen ? ( | ||
<ArrowDropUpIcon sx={{ ...styles.icon }} /> | ||
) : ( | ||
<ArrowDropDownIcon sx={{ ...styles.icon }} /> | ||
)} | ||
</IconButton> | ||
</ListItemSecondaryAction> | ||
)} | ||
</ListItem> | ||
)} | ||
</List> | ||
</Paper> | ||
) | ||
} | ||
|
||
export default MenuHeader |
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