You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Navbar.jsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import AppBar from '@mui/material/AppBar';
  2. import Box from '@mui/material/Box';
  3. import Typography from '@mui/material/Typography';
  4. import Image from 'next/image';
  5. import Link from 'next/link';
  6. import { useRouter } from 'next/router';
  7. import {
  8. BASE_PAGE,
  9. CART_PAGE,
  10. PRODUCTS_PAGE,
  11. PROFILE_PAGE,
  12. } from '../../../constants/pages';
  13. import { useStore } from '../../../store/cart-context';
  14. const Navbar = () => {
  15. const router = useRouter();
  16. const { totalQuantity } = useStore();
  17. return (
  18. <AppBar
  19. position="absolute"
  20. sx={{
  21. zIndex: 100,
  22. top: 20,
  23. width: '100%',
  24. backgroundColor: 'transparent',
  25. boxShadow: 'none',
  26. height: 40,
  27. }}
  28. >
  29. <Box sx={{ display: 'flex', width: '100%' }}>
  30. <Box
  31. sx={{
  32. flexGrow: 1,
  33. maxWidth: '50%',
  34. height: 30,
  35. display: { xs: 'none', md: 'flex' },
  36. px: 10,
  37. }}
  38. >
  39. <Link key="home" href={BASE_PAGE}>
  40. <Typography
  41. textAlign="center"
  42. sx={{
  43. mx: 'auto',
  44. fontSize: 20,
  45. fontWeight: 500,
  46. color: router.pathname === '/' ? 'white' : 'black',
  47. textDecoration: 'none',
  48. cursor: 'pointer',
  49. }}
  50. >
  51. Home
  52. </Typography>
  53. </Link>
  54. <Link key="menu" href={BASE_PAGE}>
  55. <Typography
  56. textAlign="center"
  57. sx={{
  58. mx: 'auto',
  59. fontSize: 20,
  60. fontWeight: 500,
  61. color: router.pathname === '/' ? 'white' : 'black',
  62. textDecoration: 'none',
  63. cursor: 'pointer',
  64. }}
  65. >
  66. Menu
  67. </Typography>
  68. </Link>
  69. <Link key="about" href={BASE_PAGE}>
  70. <Typography
  71. textAlign="center"
  72. sx={{
  73. mx: 'auto',
  74. fontSize: 20,
  75. fontWeight: 500,
  76. color: router.pathname === '/' ? 'white' : 'black',
  77. textDecoration: 'none',
  78. cursor: 'pointer',
  79. }}
  80. >
  81. About
  82. </Typography>
  83. </Link>
  84. <Link key="store" href={PRODUCTS_PAGE}>
  85. <Typography
  86. textAlign="center"
  87. sx={{
  88. mx: 'auto',
  89. fontSize: 20,
  90. fontWeight: 500,
  91. color: router.pathname === '/' ? 'white' : 'black',
  92. textDecoration: 'none',
  93. cursor: 'pointer',
  94. }}
  95. >
  96. Store
  97. </Typography>
  98. </Link>
  99. <Link key="contact" href={BASE_PAGE}>
  100. <Typography
  101. textAlign="center"
  102. sx={{
  103. mx: 'auto',
  104. fontSize: 20,
  105. fontWeight: 500,
  106. color: router.pathname === '/' ? 'white' : 'black',
  107. textDecoration: 'none',
  108. cursor: 'pointer',
  109. }}
  110. >
  111. Contact
  112. </Typography>
  113. </Link>
  114. </Box>
  115. <Box
  116. sx={{
  117. flexGrow: 1,
  118. maxWidth: '50%',
  119. height: 30,
  120. display: { xs: 'none', md: 'flex' },
  121. justifyContent: 'right',
  122. pt: 0.5,
  123. mr: 4,
  124. }}
  125. >
  126. <Box
  127. sx={{
  128. mx: 2,
  129. cursor: 'pointer',
  130. }}
  131. >
  132. <Link key="home" href={PROFILE_PAGE}>
  133. <Image
  134. src="/images/profile.svg"
  135. alt="profile"
  136. width={24}
  137. height={24}
  138. />
  139. </Link>
  140. </Box>
  141. <Box
  142. sx={{
  143. mr: 6,
  144. ml: 2,
  145. cursor: 'pointer',
  146. }}
  147. >
  148. <Link key="home" href={CART_PAGE}>
  149. <Box>
  150. <Box
  151. sx={{
  152. color: 'white',
  153. zIndex: 3,
  154. width: 20,
  155. height: 20,
  156. borderRadius: 20,
  157. textAlign: 'center',
  158. px: 0.5,
  159. ml: 2.2,
  160. mt: -1,
  161. fontSize: 16,
  162. position: 'absolute',
  163. backgroundColor: 'primary.main',
  164. }}
  165. >
  166. {totalQuantity}
  167. </Box>
  168. <Image
  169. src="/images/cart.svg"
  170. alt="cart"
  171. width={24}
  172. height={24}
  173. />
  174. </Box>
  175. </Link>
  176. ,
  177. </Box>
  178. </Box>
  179. </Box>
  180. </AppBar>
  181. );
  182. };
  183. export default Navbar;