Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

107 строки
2.9 KiB

  1. import PropTypes from 'prop-types';
  2. import { useEffect, useState } from 'react';
  3. import { Link, useLocation } from 'react-router-dom';
  4. // material-ui
  5. import MuiBreadcrumbs from '@mui/material/Breadcrumbs';
  6. import { Grid, Typography } from '@mui/material';
  7. // project imports
  8. import MainCard from '../MainCard';
  9. // ==============================|| BREADCRUMBS ||============================== //
  10. const Breadcrumbs = ({ navigation, title, ...others }) => {
  11. const location = useLocation();
  12. const [main, setMain] = useState();
  13. const [item, setItem] = useState();
  14. // set active item state
  15. const getCollapse = (menu) => {
  16. if (menu.children) {
  17. menu.children.filter((collapse) => {
  18. if (collapse.type && collapse.type === 'collapse') {
  19. getCollapse(collapse);
  20. } else if (collapse.type && collapse.type === 'item') {
  21. if (location.pathname === collapse.url) {
  22. setMain(menu);
  23. setItem(collapse);
  24. }
  25. }
  26. return false;
  27. });
  28. }
  29. };
  30. useEffect(() => {
  31. navigation?.items?.map((menu) => {
  32. if (menu.type && menu.type === 'group') {
  33. getCollapse(menu);
  34. }
  35. return false;
  36. });
  37. });
  38. // only used for component demo breadcrumbs
  39. if (location.pathname === '/breadcrumbs') {
  40. location.pathname = '/dashboard/analytics';
  41. }
  42. let mainContent;
  43. let itemContent;
  44. let breadcrumbContent = <Typography />;
  45. let itemTitle = '';
  46. // collapse item
  47. if (main && main.type === 'collapse') {
  48. mainContent = (
  49. <Typography component={Link} to={document.location.pathname} variant="h6" sx={{ textDecoration: 'none' }} color="textSecondary">
  50. {main.title}
  51. </Typography>
  52. );
  53. }
  54. // items
  55. if (item && item.type === 'item') {
  56. itemTitle = item.title;
  57. itemContent = (
  58. <Typography variant="subtitle1" color="textPrimary">
  59. {itemTitle}
  60. </Typography>
  61. );
  62. // main
  63. if (item.breadcrumbs !== false) {
  64. breadcrumbContent = (
  65. <MainCard border={false} sx={{ mb: 3, bgcolor: 'transparent' }} {...others} content={false}>
  66. <Grid container direction="column" justifyContent="flex-start" alignItems="flex-start" spacing={1}>
  67. <Grid item>
  68. <MuiBreadcrumbs aria-label="breadcrumb">
  69. <Typography component={Link} to="/" color="textSecondary" variant="h6" sx={{ textDecoration: 'none' }}>
  70. Home
  71. </Typography>
  72. {mainContent}
  73. {itemContent}
  74. </MuiBreadcrumbs>
  75. </Grid>
  76. {title && (
  77. <Grid item sx={{ mt: 2 }}>
  78. <Typography variant="h5">{item.title}</Typography>
  79. </Grid>
  80. )}
  81. </Grid>
  82. </MainCard>
  83. );
  84. }
  85. }
  86. return breadcrumbContent;
  87. };
  88. Breadcrumbs.propTypes = {
  89. navigation: PropTypes.object,
  90. title: PropTypes.bool
  91. };
  92. export default Breadcrumbs;