Skip to content

Commit

Permalink
Added top and bottom to mui list page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Huber committed May 9, 2023
1 parent 4d8dbab commit aef7bff
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const ListPageDemo = () => {
list={list}
fields={fields}
Row={Row}
top={<div>TOP</div>}
listProps={{ itemSize: 91 }}
getPageProps={(list) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-shell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/material-ui-shell/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "material-ui-shell",
"version": "3.4.9",
"version": "3.4.10",
"description": "material-ui-shell React component",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
211 changes: 211 additions & 0 deletions packages/material-ui-shell/src/components/MenuHeader/MenuHeader.js
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
5 changes: 5 additions & 0 deletions packages/material-ui-shell/src/containers/Page/ListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export default function (props) {
getPageProps = () => {},
listProps,
Row,

name,
trailing = null,
leading = null,
disableSearch = false,
disableFilter = false,
top = null,
bottom = null,
} = props
const { openFilter, getList, getFilter, setSearch } = useFilter()
const { queries = [], search = {} } = getFilter(name)
Expand Down Expand Up @@ -52,7 +55,9 @@ export default function (props) {
}
{...getPageProps(list)}
>
{top}
<VirtualList list={list} name={name} listProps={listProps} Row={Row} />
{bottom}

{fields.length > 0 && <FilterDrawer fields={fields} name={name} />}
</Page>
Expand Down

0 comments on commit aef7bff

Please sign in to comment.