Reac front end for psicometric app

listItems.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import * as React from 'react';
  2. import { Nav } from 'react-bootstrap';
  3. import {
  4. Fingerprint, History, MiscellaneousServices ,
  5. ExpandLess, ExpandMore
  6. } from '@mui/icons-material/'
  7. import { useNavigate, useResolvedPath, useMatch } from 'react-router-dom'
  8. import { Collapse,ListItem, List ,ListItemIcon,ListItemText,ListSubheader } from '@mui/material/'
  9. import {
  10. MainItems, ExtraItems, PruebaItems
  11. } from '../../Utils/MenuItems'
  12. function NavItem (props) {
  13. let navigate = useNavigate()
  14. let resolved = useResolvedPath(props.route);
  15. let match = useMatch({ path: resolved.pathname, end: true });
  16. let { title, route, icon, open, AppBarVisible, setOpen } = props
  17. if(route.startsWith('prueba') && match && open && !AppBarVisible ){
  18. setOpen(false);
  19. }
  20. return(
  21. <ListItem
  22. sx={{ color : '#25344f'}}
  23. selected={ match && typeof(match) === "object" }
  24. onClick={() => navigate(route) }
  25. button >
  26. <ListItemIcon>
  27. {icon && icon}
  28. </ListItemIcon>
  29. <ListItemText
  30. sx={{
  31. fontSize: 12,
  32. ' .css-10hburv-MuiTypography-root' : {
  33. fontSize : '.875rem'
  34. },
  35. }}
  36. primary={title}
  37. />
  38. </ListItem>
  39. )
  40. }
  41. export const MainListItems = (props) => {
  42. const [open, setOpen] = React.useState(false);
  43. const showPruebas = () => {
  44. if(!props.AppBarVisible){
  45. props.setAppBarVisible(true);
  46. }
  47. setOpen(!open);
  48. };
  49. return(
  50. <List>
  51. <ListSubheader inset>MENÚ</ListSubheader>
  52. {
  53. MainItems.map( ({ icon, title, route}) => (
  54. <NavItem icon={icon} title={title} route={route} />
  55. ))
  56. }
  57. <ListItem selected={open} onClick={showPruebas}>
  58. <ListItemIcon>
  59. <Fingerprint />
  60. </ListItemIcon>
  61. <ListItemText
  62. sx={{
  63. fontSize: 12,
  64. ' .css-10hburv-MuiTypography-root' : {
  65. fontSize : '.875rem'
  66. },
  67. }}
  68. primary="Pruebas"
  69. />
  70. {open ? <ExpandLess /> : <ExpandMore />}
  71. </ListItem>
  72. <Collapse in={open} timeout="auto" unmountOnExit>
  73. <List component="div" disablePadding>
  74. {
  75. PruebaItems.map( ({ route, title}) =>
  76. ( <NavItem setOpen={setOpen} { ...props} open={open} route={route} title={title} />)
  77. )
  78. }
  79. </List>
  80. </Collapse>
  81. <NavItem icon={<MiscellaneousServices/>} title="Configuraciones" route="configuraciones" />
  82. <NavItem icon={<History/>} title="Historial" route="historial" />
  83. </List>
  84. )
  85. };
  86. export const SecondaryListItems = (
  87. <Nav>
  88. <ListSubheader inset>EXTRAS</ListSubheader>
  89. {
  90. ExtraItems.map( ({ icon, route, title}) =>
  91. ( <NavItem icon={icon} title={title} route={route} />)
  92. )
  93. }
  94. </Nav>
  95. );