-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathMenuBack.js
39 lines (36 loc) · 1.09 KB
/
MenuBack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useContext } from 'react'
import PropTypes from 'prop-types'
import { ListItem, ListItemIcon, ListItemText } from '@mui/material'
import { ChevronLeft } from '@mui/icons-material'
import MenuContext from './MenuContext'
export default function MenuBack({ goBack, item, backButtonProps }) {
const { classes, renderBack } = useContext(MenuContext)
return (
<ListItem divider button onClick={goBack} {...backButtonProps}>
<ListItemIcon classes={{ root: classes.header }}>
<ChevronLeft className={classes.icon} />
</ListItemIcon>
<ListItemText
classes={{ root: classes.headerText }}
primary={
<div className={classes.headerText}>
{typeof renderBack === 'function' ? renderBack(item) : item.text}
</div>
}
/>
</ListItem>
)
}
MenuBack.propTypes = {
/**
* Goes back to the previous item in the menu hierarchy
*/
goBack: PropTypes.func,
/**
* The menu item being rendered
*/
item: PropTypes.shape({
text: PropTypes.string,
}).isRequired,
backButtonProps: PropTypes.object,
}