File size: 6,561 Bytes
4114d85 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
import PropTypes from 'prop-types'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
// material-ui
import { useTheme } from '@mui/material/styles'
import { Box, Card, Divider, Grid, Typography } from '@mui/material'
import MuiBreadcrumbs from '@mui/material/Breadcrumbs'
// project imports
import config from 'config'
import { gridSpacing } from 'store/constant'
// assets
import { IconTallymark1 } from '@tabler/icons'
import AccountTreeTwoToneIcon from '@mui/icons-material/AccountTreeTwoTone'
import HomeIcon from '@mui/icons-material/Home'
import HomeTwoToneIcon from '@mui/icons-material/HomeTwoTone'
const linkSX = {
display: 'flex',
color: 'grey.900',
textDecoration: 'none',
alignContent: 'center',
alignItems: 'center'
}
// ==============================|| BREADCRUMBS ||============================== //
const Breadcrumbs = ({ card, divider, icon, icons, maxItems, navigation, rightAlign, separator, title, titleBottom, ...others }) => {
const theme = useTheme()
const iconStyle = {
marginRight: theme.spacing(0.75),
marginTop: `-${theme.spacing(0.25)}`,
width: '1rem',
height: '1rem',
color: theme.palette.secondary.main
}
const [main, setMain] = useState()
const [item, setItem] = useState()
// set active item state
const getCollapse = (menu) => {
if (menu.children) {
menu.children.filter((collapse) => {
if (collapse.type && collapse.type === 'collapse') {
getCollapse(collapse)
} else if (collapse.type && collapse.type === 'item') {
if (document.location.pathname === config.basename + collapse.url) {
setMain(menu)
setItem(collapse)
}
}
return false
})
}
}
useEffect(() => {
navigation?.items?.map((menu) => {
if (menu.type && menu.type === 'group') {
getCollapse(menu)
}
return false
})
})
// item separator
const SeparatorIcon = separator
const separatorIcon = separator ? <SeparatorIcon stroke={1.5} size='1rem' /> : <IconTallymark1 stroke={1.5} size='1rem' />
let mainContent
let itemContent
let breadcrumbContent = <Typography />
let itemTitle = ''
let CollapseIcon
let ItemIcon
// collapse item
if (main && main.type === 'collapse') {
CollapseIcon = main.icon ? main.icon : AccountTreeTwoToneIcon
mainContent = (
<Typography component={Link} to='#' variant='subtitle1' sx={linkSX}>
{icons && <CollapseIcon style={iconStyle} />}
{main.title}
</Typography>
)
}
// items
if (item && item.type === 'item') {
itemTitle = item.title
ItemIcon = item.icon ? item.icon : AccountTreeTwoToneIcon
itemContent = (
<Typography
variant='subtitle1'
sx={{
display: 'flex',
textDecoration: 'none',
alignContent: 'center',
alignItems: 'center',
color: 'grey.500'
}}
>
{icons && <ItemIcon style={iconStyle} />}
{itemTitle}
</Typography>
)
// main
if (item.breadcrumbs !== false) {
breadcrumbContent = (
<Card
sx={{
border: 'none'
}}
{...others}
>
<Box sx={{ p: 2, pl: card === false ? 0 : 2 }}>
<Grid
container
direction={rightAlign ? 'row' : 'column'}
justifyContent={rightAlign ? 'space-between' : 'flex-start'}
alignItems={rightAlign ? 'center' : 'flex-start'}
spacing={1}
>
{title && !titleBottom && (
<Grid item>
<Typography variant='h3' sx={{ fontWeight: 500 }}>
{item.title}
</Typography>
</Grid>
)}
<Grid item>
<MuiBreadcrumbs
sx={{ '& .MuiBreadcrumbs-separator': { width: 16, ml: 1.25, mr: 1.25 } }}
aria-label='breadcrumb'
maxItems={maxItems || 8}
separator={separatorIcon}
>
<Typography component={Link} to='/' color='inherit' variant='subtitle1' sx={linkSX}>
{icons && <HomeTwoToneIcon sx={iconStyle} />}
{icon && <HomeIcon sx={{ ...iconStyle, mr: 0 }} />}
{!icon && 'Dashboard'}
</Typography>
{mainContent}
{itemContent}
</MuiBreadcrumbs>
</Grid>
{title && titleBottom && (
<Grid item>
<Typography variant='h3' sx={{ fontWeight: 500 }}>
{item.title}
</Typography>
</Grid>
)}
</Grid>
</Box>
{card === false && divider !== false && <Divider sx={{ borderColor: theme.palette.primary.main, mb: gridSpacing }} />}
</Card>
)
}
}
return breadcrumbContent
}
Breadcrumbs.propTypes = {
card: PropTypes.bool,
divider: PropTypes.bool,
icon: PropTypes.bool,
icons: PropTypes.bool,
maxItems: PropTypes.number,
navigation: PropTypes.object,
rightAlign: PropTypes.bool,
separator: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
title: PropTypes.bool,
titleBottom: PropTypes.bool
}
export default Breadcrumbs
|