Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MobileNav.jsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import AccountCircleIcon from '@mui/icons-material/AccountCircle';
  2. import CloseIcon from '@mui/icons-material/Close';
  3. import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
  4. import { Box, Button, Divider, Drawer, IconButton } from '@mui/material';
  5. import Image from 'next/image';
  6. import Link from 'next/link';
  7. import { CART_PAGE, PROFILE_PAGE } from '../../../constants/pages';
  8. import { NavItemMobile } from './NavItem';
  9. import { items } from './navItems';
  10. const MobileNav = ({ toggleDrawer, session, signOutHandler, open }) => {
  11. return (
  12. <Drawer
  13. PaperProps={{
  14. sx: { width: '40%' },
  15. }}
  16. anchor="left"
  17. open={open}
  18. onClose={toggleDrawer(false)}
  19. onOpen={toggleDrawer(true)}
  20. >
  21. <Box
  22. sx={{
  23. p: 2,
  24. height: 1,
  25. backgroundColor: '#fff',
  26. }}
  27. >
  28. <Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 2 }}>
  29. <IconButton disableRipple>
  30. <CloseIcon color="primary" onClick={toggleDrawer(false)} />
  31. </IconButton>
  32. {session?.user?._id && (
  33. <IconButton disableRipple onClick={signOutHandler}>
  34. <Image
  35. src="/images/logout.svg"
  36. alt="profile"
  37. width={18}
  38. height={20}
  39. />
  40. </IconButton>
  41. )}
  42. </Box>
  43. <Divider sx={{ mb: session?.user?._id ? 0 : 2 }} />
  44. {session?.user?._id && (
  45. <>
  46. <Box display="flex" flexDirection="column" sx={{ ml: 1 }}>
  47. <NavItemMobile
  48. icon={<AccountCircleIcon />}
  49. toggleDrawer={toggleDrawer}
  50. name="Profile"
  51. url={PROFILE_PAGE}
  52. />
  53. </Box>
  54. <Divider sx={{ mb: 2 }} />
  55. </>
  56. )}
  57. <Box sx={{ mb: 2, ml: 1 }} display="flex" flexDirection="column">
  58. {items.map((item) => (
  59. <NavItemMobile
  60. key={item.id}
  61. icon={item.icon}
  62. toggleDrawer={toggleDrawer}
  63. name={item.name}
  64. url={item.url}
  65. />
  66. ))}
  67. <Divider sx={{}} />
  68. <NavItemMobile
  69. icon={<ShoppingCartIcon />}
  70. toggleDrawer={toggleDrawer}
  71. name="Cart"
  72. url={CART_PAGE}
  73. />
  74. </Box>
  75. <Box
  76. sx={{
  77. display: 'flex',
  78. justifyContent: 'center',
  79. position: 'absolute',
  80. bottom: '0',
  81. left: '50%',
  82. transform: 'translate(-50%, 0)',
  83. }}
  84. >
  85. {!session?.user?._id && (
  86. <>
  87. <Link href="/auth/register">
  88. <Button
  89. onClick={toggleDrawer(false)}
  90. variant="contained"
  91. sx={{ m: 1, width: 0.5 }}
  92. >
  93. Register
  94. </Button>
  95. </Link>
  96. <Link href="/auth">
  97. <Button
  98. onClick={toggleDrawer(false)}
  99. variant="outlined"
  100. sx={{ m: 1, width: 0.5 }}
  101. >
  102. Login
  103. </Button>
  104. </Link>
  105. </>
  106. )}
  107. </Box>
  108. </Box>
  109. </Drawer>
  110. );
  111. };
  112. export default MobileNav;