azri пре 1 недеља
родитељ
комит
d54fc86ac0

+ 1
- 1
src/App.js Прегледај датотеку

@@ -11,7 +11,7 @@ import Footer from './components/Footer/Footer';
11 11
 import Header from './components/Header';
12 12
 import Loader from './components/Loader';
13 13
 import theme from './theme/theme';
14
-import { ThemeProvider } from '@mui/material';
14
+import { ThemeProvider, Box } from '@mui/material';
15 15
 import { fetchCart, createCart } from './redux/slices/cartSlice';
16 16
 import { useSelector, useDispatch } from 'react-redux';
17 17
 import Collection from './pages/Collection';

+ 13
- 9
src/components/Navbar/Navbar.jsx Прегледај датотеку

@@ -13,6 +13,7 @@ import { styled } from '@mui/material/styles';
13 13
 import { MenuItem, Select, FormControl, Badge, Typography } from '@mui/material';
14 14
 import MobileNav from "./components/MobileNav";
15 15
 import MenuIcon from "@mui/icons-material/Menu";
16
+import SearchProduct from "../SearchProduct"
16 17
 import CategoryIcon from '@mui/icons-material/Category';
17 18
 import HomeIcon from '@mui/icons-material/Home';
18 19
 import BrushIcon from '@mui/icons-material/Brush';
@@ -108,6 +109,7 @@ const Navbar = () => {
108 109
 
109 110
   const swiperRef = useRef(null); // Create a ref for the Swiper instance
110 111
   const [showHeader, setShowHeader] = useState(true);
112
+  const [showSearch, setShowSearch] = useState(false);
111 113
   const [isAtTop, setIsAtTop] = useState(false);
112 114
   const [isProductPage, setIsProductPage] = useState(false);
113 115
   const [lastScrollPos, setLastScrollPos] = useState(0);
@@ -261,7 +263,7 @@ const Navbar = () => {
261 263
     <>
262 264
       <AppBar position="fixed"
263 265
         sx={{
264
-          zIndex:998,
266
+          zIndex: 998,
265 267
           backgroundColor: (isAtTop) ? "rgba(0, 0, 0, 0)" : "rgba(255, 255, 255, 0.3)",
266 268
           backdropFilter: (isAtTop) ? "none" : "blur(10px)",
267 269
           boxShadow: 0,
@@ -294,7 +296,7 @@ const Navbar = () => {
294 296
           py: 0.5
295 297
         }} disableGutters>
296 298
 
297
-          <Box sx={{ display: "flex", alignItems: "center", width:"100%", position:"relative", justifyContent:"space-between" }}>
299
+          <Box sx={{ display: "flex", alignItems: "center", width: "100%", position: "relative", justifyContent: "space-between" }}>
298 300
             {/* SIDEBAR BUTTON */}
299 301
             <Box sx={{
300 302
               display: {
@@ -323,12 +325,12 @@ const Navbar = () => {
323 325
             {/* Left Section: Logo */}
324 326
             <Box
325 327
               sx={{
326
-                mr:{
327
-                  xs:0,
328
-                  sm:0,
329
-                  md:10,
330
-                  lg:10,
331
-                  xl:10
328
+                mr: {
329
+                  xs: 0,
330
+                  sm: 0,
331
+                  md: 10,
332
+                  lg: 10,
333
+                  xl: 10
332 334
                 },
333 335
                 display: {
334 336
                   xs: (isProductPage) ? "flex" : "none",
@@ -420,7 +422,7 @@ const Navbar = () => {
420 422
                 </LanguageSelect>
421 423
               </FormControl> */}
422 424
 
423
-              <IconButton>
425
+              <IconButton onClick={()=>{setShowSearch(true)}}>
424 426
                 <SearchIcon className="navItem" style={{
425 427
                   transition: "all 0.3s ease-in-out",
426 428
                   color: (isAtTop) ? "white" : "black",
@@ -486,8 +488,10 @@ const Navbar = () => {
486 488
         </Box>
487 489
 
488 490
       </AppBar>
491
+      {showSearch && <SearchProduct onClose={()=>{setShowSearch(false)}}/>}
489 492
 
490 493
       <MobileNav open={open} menu={navItem} onClose={() => { setOpen(false) }} />
494
+      
491 495
     </>
492 496
   );
493 497
 };

+ 127
- 0
src/components/SearchProduct/SearchProduct.jsx Прегледај датотеку

@@ -0,0 +1,127 @@
1
+import { useState, useEffect } from 'react';
2
+import Grid from '@mui/material/Grid2';
3
+import { Box, Button, TextField, InputAdornment, Typography, Card, CardContent, CardMedia } from '@mui/material';
4
+import { useSelector } from 'react-redux';
5
+
6
+const SearchProduct = ({onClose}) => {
7
+
8
+    const products = useSelector((state) => state.products.products.data)
9
+    const [searchedProducts, setSearchedProducts] = useState([]);
10
+    const [searchQuery, setSearchQuery] = useState('');
11
+
12
+    const filterProduct = function () {
13
+
14
+        let filteredProducts = products.filter((product) => {
15
+
16
+            let title = product?.title?.toLowerCase();
17
+            let search = searchQuery.toLowerCase();
18
+            return title?.includes(search)
19
+        })
20
+
21
+        // MAX show result 
22
+        filteredProducts = filteredProducts?.slice(0, 6);
23
+
24
+        setSearchedProducts(filteredProducts)
25
+
26
+    }
27
+
28
+    return (
29
+        <Box
30
+            className="animate__animated animate__fadeIn"
31
+            sx={{
32
+                position: 'fixed',
33
+                width: '100%',
34
+                height: '100%',
35
+                backgroundColor: 'rgba(255,255,255,0.8)',
36
+                top: 0,
37
+                left: 0,
38
+                py: 2,
39
+                zIndex: 999,
40
+                backdropFilter: 'blur(10px)',
41
+                display: 'flex',
42
+                flexDirection: 'column',
43
+                alignItems: 'center',
44
+            }}
45
+        >
46
+            {/* Search Box */}
47
+            <Box
48
+                sx={{
49
+                    backgroundColor: 'rgba(0,0,0,0)',
50
+                    borderRadius: 2,
51
+                    padding: 2,
52
+                    width: '90%',
53
+                    marginBottom: 4,
54
+                }}
55
+            >
56
+                <Grid container spacing={2}>
57
+                    <Grid size={12}>
58
+                        <TextField
59
+                            fullWidth
60
+                            placeholder="Search for a product..."
61
+                            variant="outlined"
62
+                            value={searchQuery}
63
+                            onChange={(e) => {
64
+                                setSearchQuery(e.target.value)
65
+                                if ((!searchQuery || searchQuery.trim() === "")) {
66
+                                    setSearchedProducts([])
67
+                                } else {
68
+                                    filterProduct()
69
+                                }
70
+                            }}
71
+                            InputProps={{
72
+                                endAdornment: (
73
+                                    <InputAdornment position="end">
74
+                                        <Button
75
+                                            variant="contained"
76
+                                            color="primary"
77
+                                            sx={{ height: '100%' }}
78
+                                            onClick={onClose}
79
+                                        >
80
+                                            Cancel
81
+                                        </Button>
82
+                                    </InputAdornment>
83
+                                ),
84
+                            }}
85
+                        />
86
+                    </Grid>
87
+                </Grid>
88
+            </Box>
89
+
90
+            {/* Product List */}
91
+            <Grid
92
+                container
93
+                columns={12}
94
+            >
95
+                {searchedProducts.length > 0 ? (
96
+                    searchedProducts.map((product) => (
97
+                        <Grid className="animate__animated animate__fadeIn" item size={{ xs: 12, sm: 12, md: 6 }} sx={{p:1}}>
98
+                            <Card
99
+                                key={product.id}
100
+                                sx={{ display: 'flex', alignItems: 'center', p: 2, cursor:"pointer" }}
101
+                                onClick={() => {
102
+                                    window.location.href = `/product/${product?.handle}`
103
+                                }}
104
+                            >
105
+                                <CardMedia
106
+                                    component="img"
107
+                                    sx={{ width: 100, height: 100, borderRadius: 1, marginRight: 2 }}
108
+                                    image={product?.images[0]?.url}
109
+                                    alt={product?.title}
110
+                                />
111
+                                <CardContent sx={{ flex: '1 0 auto' }}>
112
+                                    <Typography variant="h5">{product?.title}</Typography>
113
+                                </CardContent>
114
+                            </Card>
115
+                        </Grid>
116
+                    ))
117
+                ) : (
118
+                    <Typography variant="body1" color="text.secondary">
119
+                        No products found. Please search
120
+                    </Typography>
121
+                )}
122
+            </Grid>
123
+        </Box>
124
+    );
125
+};
126
+
127
+export default SearchProduct;

+ 1
- 0
src/components/SearchProduct/index.js Прегледај датотеку

@@ -0,0 +1 @@
1
+export { default } from "./SearchProduct"

Loading…
Откажи
Сачувај